ipfs / js-ipfs

IPFS implementation in JavaScript
https://js.ipfs.tech
Other
7.43k stars 1.25k forks source link

Configure own signaling server and bootstrap node #1092

Closed AquiGorka closed 6 years ago

AquiGorka commented 6 years ago

I'd been seeing some odd behavior (now reported here) so I wanted to setup a browser node that would only connect to my local jsipfs daemon and use my own signaling server.

My config looks like this:

const ipfsConfig = {
   repo: 'repo-name',
   EXPERIMENTAL: {
     pubsub: true,
   },
   config: {
     Addresses: {
       Swarm: [],
       SignalServer: '127.0.0.1:9090',
     },
     Bootstrap: [
       '/ip4/127.0.0.1/tcp/4003/ws/ipfs/_node_id_from_local_jsipfs_daemon_',
     ],
   },
}

jsipfs daemon (using experimental pub/sub):

jsipfs daemon --enable-pubsub-experiment

signaling server:

npm run star-signal -- -p=9090 -h=127.0.0.1
Listening on: http://127.0.0.1:9090

I see the browser node has one connected swarm peer:

node.swarm.peers().then(console.log)
// shows same id from local jsipfs daemon

I am using YJS for CRDT and I am not able to pubsub. The signaling server does not log any info - either the server does not log anything or it is not being used.

Help would be much appreciated.

daviddias commented 6 years ago

Hi @AquiGorka, thanks for opening this issue, now I see that it is not clear how to configure custom multiaddrs.

The fix for your issue is that you do not need that "SignalServer" on the config file, instead, you should add a multiaddr to your swarm array that looks like this:

/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star

So that IPFS knows where to find the Signalling Server.

The explanation why it is this way is that we use Multiaddr, a self-describable data type that offers information about an address, in the example I shared with you, we can see that 1) it is a p2p-webrtc-star multiaddr and 2) the SignalServer is available at an IPv4 addr, on a TCP port that expect interactions over WebSockets.

Let me know if you hit any other issue :)

AquiGorka commented 6 years ago

That kind'a worked!

Now I can see all the nodes connected to the swarm. But I am not able to pubsub between the two browser nodes - I can't find the reference but I think I read when 3 nodes are connected there can be pubsub among them if one is not a browser node. Am I right to assume so?

Could there be any reason why in setup like mine peers are not receiving updates via pubsub?

AquiGorka commented 6 years ago

Now it is working, thanks for the help @diasdavid !

daviddias commented 6 years ago

Awesome! you bet :)

Would you like to contribute to the js-ipfs FAQ with how to configure a signalling endpoint?

AquiGorka commented 6 years ago

I will gladly do so. Expect another PR from me.

Steverman commented 6 years ago

I would to add that there currently is a bug with multiaddr in libp2p-webrtc-star when using domains for your signal server that listens on ports other than 80. As we have discussed @diasdavid on IRC, it is most likely util.js in libp2p-webrtc-star. I should probably create another issue, but I am pretty new when it comes to actual github usage.

Setup

Port 80

No need to add tcp or port hackery /dns4/example.com/ws/p2p-webrtc-star

Using /ip4

omitting the v caught me off guard but it's a design choice :+1:

IP4 actually works last time I checked, but I am not 100% sure. I would have to test it again. E.g. if the desired port is 9999, then /ip4/1.2.3.4/tcp/9999/ws/p2p-webrtc-star Works.

Conclusion

/dns4 is not handled properly, and the culprit is most likely the cleanUrlSIO function. More specifically:

https://github.com/libp2p/js-libp2p-webrtc-star/blob/44f4417c359d533f8eefb56d168e2cef099fbf50/src/utils.js#L13-L19

As it expects either ws or wss, but got tcp instead. The solution is probably adding another else if on 'tcp' and handle it there.

I haven't gotten around to test it or looked over the code to fully understand it, but I would like to let this be my first PR on github. Just point me to the guidelines :).

As a sidenote: Chrome is a real PITA when it comes to wss and https with WebRTC as I am getting "mixed content" errors or key generation errors. I believe the provided signal server does not support wss, and I need it in order to use my own signalling server for my upcoming live demo. This also means I can't test this part.

daviddias commented 6 years ago

@Steverman thank you for the complete description of the problem, 5 🌟

We are now targetting this issue in both https://github.com/libp2p/js-libp2p-webrtc-star/issues/129 and https://github.com/libp2p/js-libp2p-websocket-star/issues/35 and as we talked about, the real issue is here https://github.com/libp2p/js-libp2p-websocket-star/blob/master/src/utils.js#L8-L35. Let's continue the convo on these two issues :)