ipfs-shipyard / ipfs-pubsub-room

IPFS Pubsub room
MIT License
288 stars 41 forks source link

HTTPS clients can't discover each other, but can discover and be discovered by HTTP-only clients #30

Open ccashwell opened 6 years ago

ccashwell commented 6 years ago

This demo code doesn't seem to work once pushed behind an HTTPS endpoint. Specifically, HTTPS clients are communicating with the signaling server, but they're never made aware of one another. HTTP-only clients don't have this issue, and the interesting part is that an HTTP-only client can also discover and be discovered by HTTPS clients. There's just the disconnect between HTTPS clients and other HTTPS clients.

I thought maybe it was the signaling server, so I deployed my own libp2p-websocket-star rendezvous server to no avail. Am I missing something?

ccashwell commented 6 years ago

After communicating with the libp2p team a bit more, I'm unsure where in the IPFS/libp2p stack this is occurring. The following is a simplified version of the code I'm using to test ipfs-pubsub-room:

import IPFS from 'ipfs'
import Room from 'ipfs-pubsub-room'

(() => {
  this.ipfs = new IPFS({
      EXPERIMENTAL: { pubsub: true },
      repo: `ipfs/mythereum/${Math.random()}`,
      config: {
        Addresses: {
          Swarm: [
            // note: I've also tried replacing these with a self-hosted rendezvous, same issue
            // whether it's my self-hosted server or any of the hosted ones I've discovered
            '/dnsaddr/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star',
            '/dnsaddr/ws-star-signal-1.servep2p.com/tcp/443/wss/p2p-websocket-star',
            '/dnsaddr/ws-star-signal-2.servep2p.com/tcp/443/wss/p2p-websocket-star',
            '/dnsaddr/ws-star-signal-3.servep2p.com/tcp/443/wss/p2p-websocket-star'
          ]
        }
      }
    })

    // IPFS node is ready, so we can start using ipfs-pubsub-room
    this.ipfs.on('ready', () => {
      this.ipfs.id((err, info) => {
        if (err) { throw err }
        console.log("Connected to IPFS as " + info.id)
      })

      this.gameLobby = Room(this.ipfs, 'game-lobby-079a4d')

      this.gameLobby.on('peer joined', (peer) => {
        let event = { event: "peer_joined", id: peer }
        console.log(JSON.stringify(event))
      })

      this.gameLobby.on('peer left', (peer) => {
        let event = { event: "peer_left", id: peer }
        console.log(JSON.stringify(event))
      })

      this.gameLobby.on('message', (message) => {
        let payload = JSON.parse(message.data.toString())
        console.log(payload)
      })
    })
})()

I've ruled out browser-specific issues by testing each affected machine with the IPFS benchmark tool which connects me (and every other browser I've tested) to other peers as expected.

harrshasri commented 6 years ago

I think you need to remove Math.Random() when deploying. When you are doing locally you need Math.Random() for uniqueness on the same client.

And one of my implementation is working on https on firebase.

eolszewski commented 6 years ago

@harrshasri can you link to that implementation?

sriharrsha commented 6 years ago

@eolszewski Link