libp2p / js-libp2p-webrtc-star

libp2p WebRTC transport that includes a discovery mechanism provided by the signalling-star
https://libp2p.io
Other
320 stars 97 forks source link

Connecting nodejs and browser using webrtc-star problem #419

Closed fsvieira closed 2 years ago

fsvieira commented 2 years ago

Hi,

I am trying to connect browser nodes and nodejs nodes using webrtc-start, I am able to connect browser-to-browser, nodejs-to-nodejs, but when a browser node connects with a nodejs node and vice-versa, it immediately disconnects

I took the code from here GitHub - HighCWu/js-libp2p-webrtc-star-example, I also tried to run webrtc-signalling-server on my own computer, but it didn’t solve the problem.

How can I solve this ? Thanks.

mpetrunic commented 2 years ago

Triage notes: @fsvieira Could you provide us with logs when this happens? Please also set DEBUG=libp2p:*

fsvieira commented 2 years ago

Hi, this is the log from my nodejs node

`

libp2p-in-node@1.0.0 start /media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node DEBUG=libp2p:* node index.js

Starting libp2p... libp2p:connection-manager options: {"maxConnections":null,"minConnections":25,"maxData":null,"maxSentData":null,"maxReceivedData":null,"maxEventLoopDelay":null,"pollInterval":2000,"autoDialInterval":10000,"movingAverageInterval":60000,"defaultPeerValue":1,"autoDial":true} +0ms libp2p:transports adding WebSockets +0ms libp2p:transports adding WebRTCStar +0ms libp2p:transports adding Circuit +1ms libp2p:peer-store:proto-book added provided protocols for QmPFADEtgi1v8FuSqYLhGSMnoCzERfTA3JcbBVEFdmgsq7 +0ms libp2p:peer-store:proto-book added provided protocols for QmPFADEtgi1v8FuSqYLhGSMnoCzERfTA3JcbBVEFdmgsq7 +1ms libp2p:peer-store:proto-book added provided protocols for QmPFADEtgi1v8FuSqYLhGSMnoCzERfTA3JcbBVEFdmgsq7 +0ms libp2p:transports creating listener for WebRTCStar on /ip4/127.0.0.1/tcp/13579/wss/p2p-webrtc-star +8ms libp2p:webrtc-star:listener Dialing to Signalling Server on: http://127.0.0.1:13579 +0ms libp2p:peer-store:address-book stored provided peer record for QmPFADEtgi1v8FuSqYLhGSMnoCzERfTA3JcbBVEFdmgsq7 +0ms libp2p:connection-manager started +48ms libp2p started! libp2p id is QmPFADEtgi1v8FuSqYLhGSMnoCzERfTA3JcbBVEFdmgsq7 libp2p:webrtc-star Peer Discovered: /ip4/127.0.0.1/tcp/13579/wss/p2p-webrtc-star/p2p/QmUh9pHprV2z4zTjNfnzt4Y62tsqsDv3uqUZjNrfWF5Gci +0ms libp2p:peer-store:address-book added provided multiaddrs for QmUh9pHprV2z4zTjNfnzt4Y62tsqsDv3uqUZjNrfWF5Gci +3s Found peer QmUh9pHprV2z4zTjNfnzt4Y62tsqsDv3uqUZjNrfWF5Gci libp2p:dialer 1 tokens request, returning 1, 99 remaining +0ms libp2p:webrtc-star dialing 127.0.0.1:13579 +21ms libp2p:connection-manager checking limit of maxEventLoopDelay. current value: 1.2256309999997939 of Infinity +4s libp2p:webrtc-star:listener new inbound connection undefined +5s libp2p:upgrader Starting the inbound connection upgrade +0ms libp2p:upgrader handling inbound crypto protocol selection [ '/noise' ] +1ms libp2p:upgrader encrypting inbound connection... +12ms libp2p:noise Stage 0 - Responder waiting to receive first message... +0ms libp2p:noise Stage 0 - Responder received first message. +6ms libp2p:noise Stage 1 - Responder sending out first message with signed payload and static key. +1ms libp2p:noise Stage 1 - Responder sent the second handshake message with signed payload. +12ms libp2p:noise Stage 2 - Responder waiting for third handshake message... +1ms libp2p:noise Stage 2 - Responder received the message, finished handshake. +17ms libp2p:upgrader inbound handling muxers [ '/mplex/6.7.0' ] +57ms libp2p:upgrader Successfully upgraded inbound connection +2ms libp2p:upgrader inbound: starting new stream on [ '/ipfs/id/1.0.0' ] +1ms libp2p:mplex new initiator stream 0 0 +0ms Connected to QmUh9pHprV2z4zTjNfnzt4Y62tsqsDv3uqUZjNrfWF5Gci libp2p:peer-store:key-book stored provided public key for QmUh9pHprV2z4zTjNfnzt4Y62tsqsDv3uqUZjNrfWF5Gci +0ms libp2p:connection-manager checking limit of maxConnections. current value: 1 of Infinity +1s libp2p:webrtc-star:listener inbound connection undefined upgraded +75ms libp2p:identify:err ReferenceError: AbortController is not defined libp2p:identify:err at module.exports (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/stream.js:25:27) libp2p:identify:err at Mplex._newStream (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:130:20) libp2p:identify:err at Mplex.newStream (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:86:17) libp2p:identify:err at Connection.newStream [as _newStream] (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p/src/upgrader.js:260:35) libp2p:identify:err at Connection.newStream (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-interfaces/src/connection/connection.js:175:45) libp2p:identify:err at IdentifyService.identify (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p/src/identify/index.js:168:41) libp2p:identify:err at ConnectionManager. (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p/src/identify/index.js:84:12) libp2p:identify:err at ConnectionManager.emit (events.js:412:35) libp2p:identify:err at ConnectionManager.onConnect (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p/src/connection-manager/index.js:218:10) libp2p:identify:err at Upgrader.onConnection (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p/src/index.js:226:60) +0ms libp2p:mplex incoming message { id: 0, type: 'NEW_STREAM', data: <Buffer 30> } +7ms libp2p:mplex new receiver stream 0 0 +1ms libp2p:mplex error in sink ReferenceError: AbortController is not defined at module.exports (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/stream.js:25:27) at Mplex._newStream (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:130:20) at Mplex._newReceiverStream (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:100:17) at Mplex._handleIncoming (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:207:27) at /media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:156:22 at processTicksAndRejections (internal/process/task_queues.js:95:5) at async Mplex.sink (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:149:9) +0ms libp2p:webrtc-star:socket:error ReferenceError: AbortController is not defined libp2p:webrtc-star:socket:error at module.exports (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/stream.js:25:27) libp2p:webrtc-star:socket:error at Mplex._newStream (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:130:20) libp2p:webrtc-star:socket:error at Mplex._newReceiverStream (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:100:17) libp2p:webrtc-star:socket:error at Mplex._handleIncoming (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:207:27) libp2p:webrtc-star:socket:error at /media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:156:22 libp2p:webrtc-star:socket:error at processTicksAndRejections (internal/process/task_queues.js:95:5) libp2p:webrtc-star:socket:error at async Mplex.sink (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:149:9) +0ms Disconnected from QmUh9pHprV2z4zTjNfnzt4Y62tsqsDv3uqUZjNrfWF5Gci libp2p:connection-manager checking limit of maxEventLoopDelay. current value: 0.49321600000007493 of Infinity +704ms libp2p:connection-manager checking limit of maxEventLoopDelay. current value: 1.3804620000000796 of Infinity +2s libp2p:webrtc-star connection opened 127.0.0.1:13579 +5s libp2p:webrtc-star new outbound connection /ip4/127.0.0.1/tcp/13579/wss/p2p-webrtc-star/p2p/QmUh9pHprV2z4zTjNfnzt4Y62tsqsDv3uqUZjNrfWF5Gci +3ms libp2p:upgrader Starting the outbound connection upgrade +3s libp2p:upgrader selecting outbound crypto protocol [ '/noise' ] +1ms libp2p:upgrader encrypting outbound connection to {"id":"QmUh9pHprV2z4zTjNfnzt4Y62tsqsDv3uqUZjNrfWF5Gci"} +5ms libp2p:noise Stage 0 - Initiator starting to send first message. +3s libp2p:noise Stage 0 - Initiator finished sending first message. +3ms libp2p:noise Stage 1 - Initiator waiting to receive first message from responder... +0ms libp2p:noise Stage 1 - Initiator received the message. +21ms libp2p:noise Initiator going to check remote's signature... +1ms libp2p:noise All good with the signature! +5ms libp2p:noise Stage 2 - Initiator sending third handshake message. +0ms libp2p:noise Stage 2 - Initiator sent message with signed payload. +6ms libp2p:upgrader outbound selecting muxer [ '/mplex/6.7.0' ] +42ms libp2p:upgrader /mplex/6.7.0 selected as muxer protocol +15ms libp2p:upgrader Successfully upgraded outbound connection +0ms libp2p:upgrader outbound: starting new stream on [ '/ipfs/id/1.0.0' ] +0ms libp2p:mplex new initiator stream 0 0 +3s Connected to QmUh9pHprV2z4zTjNfnzt4Y62tsqsDv3uqUZjNrfWF5Gci libp2p:connection-manager checking limit of maxConnections. current value: 1 of Infinity +291ms libp2p:webrtc-star outbound connection /ip4/127.0.0.1/tcp/13579/wss/p2p-webrtc-star/p2p/QmUh9pHprV2z4zTjNfnzt4Y62tsqsDv3uqUZjNrfWF5Gci upgraded +65ms libp2p:identify:err ReferenceError: AbortController is not defined libp2p:identify:err at module.exports (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/stream.js:25:27) libp2p:identify:err at Mplex._newStream (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:130:20) libp2p:identify:err at Mplex.newStream (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:86:17) libp2p:identify:err at Connection.newStream [as _newStream] (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p/src/upgrader.js:260:35) libp2p:identify:err at Connection.newStream (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-interfaces/src/connection/connection.js:175:45) libp2p:identify:err at IdentifyService.identify (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p/src/identify/index.js:168:41) libp2p:identify:err at ConnectionManager. (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p/src/identify/index.js:84:12) libp2p:identify:err at ConnectionManager.emit (events.js:412:35) libp2p:identify:err at ConnectionManager.onConnect (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p/src/connection-manager/index.js:218:10) libp2p:identify:err at Upgrader.onConnection (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p/src/index.js:226:60) +3s libp2p:dialer token 0 released +5s libp2p:dialer dial succeeded to QmUh9pHprV2z4zTjNfnzt4Y62tsqsDv3uqUZjNrfWF5Gci +0ms libp2p:mplex incoming message { id: 0, type: 'NEW_STREAM', data: <Buffer 30> } +2ms libp2p:mplex new receiver stream 0 0 +0ms libp2p:mplex error in sink ReferenceError: AbortController is not defined at module.exports (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/stream.js:25:27) at Mplex._newStream (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:130:20) at Mplex._newReceiverStream (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:100:17) at Mplex._handleIncoming (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:207:27) at /media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:156:22 at processTicksAndRejections (internal/process/task_queues.js:95:5) at async Mplex.sink (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:149:9) +0ms libp2p:webrtc-star:socket:error ReferenceError: AbortController is not defined libp2p:webrtc-star:socket:error at module.exports (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/stream.js:25:27) libp2p:webrtc-star:socket:error at Mplex._newStream (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:130:20) libp2p:webrtc-star:socket:error at Mplex._newReceiverStream (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:100:17) libp2p:webrtc-star:socket:error at Mplex._handleIncoming (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:207:27) libp2p:webrtc-star:socket:error at /media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:156:22 libp2p:webrtc-star:socket:error at processTicksAndRejections (internal/process/task_queues.js:95:5) libp2p:webrtc-star:socket:error at async Mplex.sink (/media/fsvieira/Data/fsvieira/sandbox/libp2p-repo/js-libp2p-webrtc-star-example/node/node_modules/libp2p-mplex/src/mplex.js:149:9) +3s Disconnected from QmUh9pHprV2z4zTjNfnzt4Y62tsqsDv3uqUZjNrfWF5Gci `

On the browser I just have my messages, like this: libp2p started! libp2p id is QmUh9pHprV2z4zTjNfnzt4Y62tsqsDv3uqUZjNrfWF5Gci Found peer QmPFADEtgi1v8FuSqYLhGSMnoCzERfTA3JcbBVEFdmgsq7 Connected to QmPFADEtgi1v8FuSqYLhGSMnoCzERfTA3JcbBVEFdmgsq7 Disconnected from QmPFADEtgi1v8FuSqYLhGSMnoCzERfTA3JcbBVEFdmgsq7 Connected to QmPFADEtgi1v8FuSqYLhGSMnoCzERfTA3JcbBVEFdmgsq7 Disconnected from QmPFADEtgi1v8FuSqYLhGSMnoCzERfTA3JcbBVEFdmgsq7 Thanks.

mpetrunic commented 2 years ago

Interesting, AbortController is not defined. @fsvieira which nodejs version are you running?

fsvieira commented 2 years ago

Oh, you are right it was my node version, I was using v14.18.1, I tested it now with v16.14.0, and it works great. I completed forget that I add this version as default. Thank you so much for the help.