Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Configure own signaling server and bootstrap node #1092

Closed
AquiGorka opened this issue Nov 20, 2017 · 7 comments
Closed

Configure own signaling server and bootstrap node #1092

AquiGorka opened this issue Nov 20, 2017 · 7 comments
Labels
kind/support A question or request for support

Comments

@AquiGorka
Copy link
Member

AquiGorka commented Nov 20, 2017

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.

@AquiGorka AquiGorka changed the title Configure own signalling server and bootstrap node Configure own signaling server and bootstrap node Nov 20, 2017
@daviddias
Copy link
Member

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
Copy link
Member Author

AquiGorka commented Nov 20, 2017

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
Copy link
Member Author

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

@daviddias
Copy link
Member

Awesome! you bet :)

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

@daviddias daviddias added the kind/support A question or request for support label Nov 21, 2017
@AquiGorka
Copy link
Member Author

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

@Steverman
Copy link

Steverman commented Nov 23, 2017

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

alarm@alarmpi ~ % DEBUG=* star-signal --port=9999 
  signalling-server signaling server has started on: http://0.0.0.0:9999 +0ms
  socket.io:server initializing namespace / +0ms
  socket.io-parser encoding packet {"type":0,"nsp":"/"} +0ms
  socket.io-parser encoded {"type":0,"nsp":"/"} as 0 +2ms
  socket.io:server creating engine.io instance with opts {"path":"/socket.io","initialPacket":["0"]} +7ms
  socket.io:server attaching client serving req handler +73ms
Listening on: http://0.0.0.0:9999
  • Port forward my Raspberry Pi's LAN IP with internal port 9999 to external port 9999, which now make it accessable at example.com:9999
  • The expected multiaddr would then be (correct me if I am wrong):
    /dns4/example.com/tcp/9999/ws/p2p-webrtc-star/
  • Add it to your ipfs config:
const ipfs = new IPFS({
  repo: `stream-handler/${Math.random()}`,
  EXPERIMENTAL: {
    pubsub: true
  },
  config: {
    Addresses: {
      Swarm: [
        '/dns4/example.com/tcp/9999/ws/p2p-webrtc-star'
      ]
    }
  }
});

Result

Using the browser I then get this error in my console

webpack:///../node_modules/libp2p-webrtc-star/src/utils.js?:18 Uncaught Error: invalid multiaddr/dns4/example.com/tcp/9999/ws/p2p-webrtc-star/ipfs/QmRrYPJBkCQqhJ5CPq8qb8qyxd7GkRQqwPfi6mmgPFTZ9s
    at cleanUrlSIO (webpack:///../node_modules/libp2p-webrtc-star/src/utils.js?:18)
    at EventEmitter.listener.listen (webpack:///../node_modules/libp2p-webrtc-star/src/index.js?:134)
    at eval (webpack:///../node_modules/libp2p-swarm/src/transport.js?:86)
    at eval (webpack:///../node_modules/async/internal/parallel.js?:31)
    at eachOfArrayLike (webpack:///../node_modules/async/eachOf.js?:65)
    at exports.default (webpack:///../node_modules/async/eachOf.js?:9)
    at _parallel (webpack:///../node_modules/async/internal/parallel.js?:30)
    at parallelLimit (webpack:///../node_modules/async/parallel.js?:88)
    at Object.listen (webpack:///../node_modules/libp2p-swarm/src/transport.js?:103)
    at each (webpack:///../node_modules/libp2p-swarm/src/index.js?:77)

Temporary fix for /dns4

Assuming that the ports are accessable from the outside, use these following multiaddrs to make it work:

Port other than 80

If port 9999 is the desired port:
/dns4/example.com:9999/ws/p2p-webrtc-star

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 👍

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
Copy link
Member

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

We are now targetting this issue in both libp2p/js-libp2p-webrtc-star#129 and libp2p/js-libp2p-websocket-star#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 :)

MicrowaveDev pushed a commit to galtproject/js-ipfs that referenced this issue May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/support A question or request for support
Projects
None yet
Development

No branches or pull requests

3 participants