Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't discover/connect new peers using webrtc-star on v0.39.5 #1442

Closed
ratik21 opened this issue Oct 17, 2022 · 13 comments
Closed

Can't discover/connect new peers using webrtc-star on v0.39.5 #1442

ratik21 opened this issue Oct 17, 2022 · 13 comments
Labels
kind/support A question or request for support need/triage Needs initial labeling and prioritization

Comments

@ratik21
Copy link
Contributor

ratik21 commented Oct 17, 2022

Peer discovery and connections are not happening with the latest libp2p version (after esm upgrade).

I have created a failing test for both versions (before & after esm), with screenshots - https://github.com/ratik21/p2p-webrtc-star-test. Please check it out. Thanks.

Related discussion thread :: https://discuss.libp2p.io/t/cant-discover-peers-with-webrtc-star-on-js-libp2p-0-37-0/1438

cc: @MarcoPolo

@ratik21 ratik21 added the need/triage Needs initial labeling and prioritization label Oct 17, 2022
@achingbrain
Copy link
Member

You need to configure the peer discovery component of the WebRTCStar transport for it to work:

For libp2p@0.37.0-0.39.0 and @libp2p/webrtc-star@4.x.x:

import { WebRTCStar } from '@libp2p/webrtc-star'
import { createLibp2p } from 'libp2p'
//... other stuff

const webRTC = new WebRTCStar({ ... })

const node = await createLibp2p( {
  transports: [
    webRTC
  ],
  peerDiscovery: [
     webRTC.discovery
  ],
  //... other stuff
})

For libp2p@0.40.0 and @libp2p/webrtc-star@5.x.x:

import { webRTCStar } from '@libp2p/webrtc-star'
import { createLibp2p } from 'libp2p'
//... other stuff

const webRTC = webRTCStar({ ... })

const node = await createLibp2p( {
  transports: [
    webRTC.transport
  ],
  peerDiscovery: [
     webRTC.discovery
  ],
  //... other stuff
})

The README for v5 is hopefully a bit clearer.

@ratik21
Copy link
Contributor Author

ratik21 commented Oct 19, 2022

@achingbrain thanks for responding.

With the changes you have suggested the discovery is working (for libp2p@0.37.0-0.39.0 and @libp2p/webrtc-star@4.x.x). But the connection is still not happening (sc attached).

image

I was wondering if this is the case now (for after-esm versions)? Because connection is being established for same nodes at before-esm version (one at local & one behind NAT -- reference).

@ratik21
Copy link
Contributor Author

ratik21 commented Oct 19, 2022

@achingbrain one more thing (side note), i start getting this influx of discovery logs and it never stops, after discovery (for any transport/peer discovery mechanism)

image

This is the event handler code (taken from node1.js from my repo)

  node.addEventListener('peer:discovery', (event) => {
    const peerInfo = event.detail;
    console.log('Discovered:', peerInfo.id.toString());
  });

@achingbrain
Copy link
Member

Discovered nodes are no longer dialled automatically - please see the upgrade guide - https://github.com/libp2p/js-libp2p/blob/master/doc/migrations/v0.37-v0.40.md#autodial

@ratik21
Copy link
Contributor Author

ratik21 commented Oct 19, 2022

@achingbrain i tested on libp2p@0.37.0-0.39.0 :)

Also, in the node configuration i have set

    ..
    addressManager: {
      autoDial: true
    },
    connectionManager: {
      autoDial: true,
      dialTimeout: 60000
    },
    ..
    // more stuff

@ratik21
Copy link
Contributor Author

ratik21 commented Oct 19, 2022

Furthur more, if i try to manually dial after discovery, i get this error

[AggregateError: All promises were rejected] {
  [errors]: [
    AbortError: The operation was aborted
        at file:///Users/ratikjindal/Zero/libp2p-webrtc-star-issue/after-esm/node_modules/@libp2p/webrtc-star/dist/src/index.js:117:26
        at <anonymous> {
      type: 'aborted',
      code: 'ABORT_ERR'
    }
  ]
}

Update to source code:

  node.addEventListener('peer:discovery', async (event) => {
    const peerInfo = event.detail;
    console.log('Discovered:', peerInfo.id.toString());

    console.log("dialing..");
    try {
      const ma = new Multiaddr(`/dns4/vast-escarpment-62759.herokuapp.com/tcp/443/wss/p2p-webrtc-star/p2p/${peerInfo.id.toString()}`);
      await node.dial(ma);
    } catch (error) {
      console.log(error);
    }
  });

@ratik21
Copy link
Contributor Author

ratik21 commented Oct 25, 2022

@achingbrain I have upgraded the js-libp2p version on this test, but I am still getting the same issue as above.

As an alternative, could you please suggest what protocol to use for connection b/w two peers where one is behind a NAT? Before the esm upgrade webrtc-star servers were working fine. Anyway, can we use circuit relay (v1/v2) now?, i.e <..>/p2p-circuit/p2p/<..>?

Also there is a small bug in the migration guide for v0.40.0, I have created a PR for it.

@ratik21
Copy link
Contributor Author

ratik21 commented Oct 28, 2022

@achingbrain -- any update on this?

@mpetrunic mpetrunic added the kind/support A question or request for support label Nov 8, 2022
@p-shahi
Copy link
Member

p-shahi commented Nov 8, 2022

@ratik21 We likely won't pursue this issue since we are actively working to support WebRTC transport https://github.com/little-bear-labs/js-libp2p-webrtc/ and deprecate WebRTC-star (and direct) as a result.

@ratik21
Copy link
Contributor Author

ratik21 commented Nov 10, 2022

@p-shahi Ok, thanks for responding. few questions :-

  • Does js-libp2p-webrtc work for server <-> browser, server <-> server as well? Or is it only browser <-> browser?

  • Assuming browser to browser only, will this transport be able to discover & connect to "new" peers (not known peers but peers who join the network), behind NAT's ? It seems there aren't many ways for NAT traversal in js-libp2p yet :/

@p-shahi
Copy link
Member

p-shahi commented Nov 10, 2022

@ratik21 That implementation (tracked here #1478 now) is for browser to server
How it behaves is specified here: https://github.com/libp2p/specs/tree/master/webrtc

The browser to browser aspect is just beginning to get underway. See #1462. It's not specified yet but necessary parts like supporting Circuit Relay v2 are being added.

AutoNat support is also being added, hopefully before the end of this year per our roadmap: https://github.com/libp2p/js-libp2p/blob/master/ROADMAP.md#end-of-q4-december

@ratik21
Copy link
Contributor Author

ratik21 commented Nov 11, 2022

@p-shahi thanks! I will try js-libp2p-webrtc for server to server, and browser to browser for new discovery and connections

@p-shahi
Copy link
Member

p-shahi commented Nov 15, 2022

@ratik21 I'll close this issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support A question or request for support need/triage Needs initial labeling and prioritization
Projects
None yet
Development

No branches or pull requests

4 participants