Skip to content

Connection to found peers does not work #149

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

Open
ZababurinSergei opened this issue Sep 16, 2024 · 4 comments
Open

Connection to found peers does not work #149

ZababurinSergei opened this issue Sep 16, 2024 · 4 comments

Comments

@ZababurinSergei
Copy link

ZababurinSergei commented Sep 16, 2024

I have updated all libraries to the latest versions at the moment.

 "dependencies": {
    "@chainsafe/libp2p-gossipsub": "^14.1.0",
    "@chainsafe/libp2p-noise": "^16.0.0",
    "@chainsafe/libp2p-yamux": "^7.0.0",
    "@libp2p/autonat": "^2.0.1",
    "@libp2p/bootstrap": "^11.0.1",
    "@libp2p/circuit-relay-v2": "^2.0.1",
    "@libp2p/crypto": "^5.0.1",
    "@libp2p/dcutr": "^2.0.1",
    "@libp2p/identify": "^3.0.1",
    "@libp2p/interface-transport": "^4.0.3",
    "@libp2p/kad-dht": "^13.0.1",
    "@libp2p/logger": "^5.0.1",
    "@libp2p/peer-id": "^5.0.1",
    "@libp2p/peer-store": "^11.0.1",
    "@libp2p/ping": "^2.0.1",
    "@libp2p/pubsub-peer-discovery": "^11.0.0",
    "@libp2p/tcp": "^10.0.1",
    "@libp2p/webrtc": "^5.0.2",
    "@libp2p/websockets": "^9.0.1",
    "@libp2p/webtransport": "^5.0.2",
    "@multiformats/multiaddr": "^12.3.1",
    "blockstore-core": "^5.0.2",
    "datastore-core": "^10.0.2",
    "datastore-idb": "^3.0.1"
  }

Node configuration.

const libp2p = await createLibp2p({
  addresses: {
    listen: [
      '/webrtc-direct',
      '/webrtc'
    ]
  },
  transports: [
    webRTCDirect(),
    webSockets({
      filter: filters.all
    }),
    webRTC(),
    circuitRelayTransport({
      discoverRelays: 4
    })
  ],
  peerDiscovery: [
      pubsubPeerDiscovery({
        interval: 10000,
        topics: [PUBSUB_PEER_DISCOVERY],
        listenOnly: false
      }),
      bootstrap({
        list: ["/dns4/localhost/tcp/4839/ws/p2p/12D3KooWAJKSV1yF6XVZRzMnh6YFd5tbXbQQZxwHAMxZXfWyQpm6"]
      })
    ],
  connectionEncrypters: [noise()],
  streamMuxers: [yamux()],
  connectionManager: {
    minConnections: 20,
  },
  transportManager: {
    faultTolerance: FaultTolerance.NO_FATAL
  },
  services: {
    identify: identify(),
    identifyPush: identifyPush(),
    pubsub: gossipsub(),
    dcutr: dcutr(),
    ping: ping()
  }
}

relay

 const libp2p = await createLibp2p({
        peerStore: PersistentPeerStore,
        MemoryDatastore,
        privateKey: peerId,
        addresses: addresses,
        transports: [
            webTransport(),
            webSockets({ server }),
            tcp(),
        ],
        connectionEncrypters: [
            noise()
        ],
        streamMuxers: [yamux()],
        services: {
            identify: identify(),
            identifyPush: identifyPush(),
            pubsub: gossipsub(),
            relay: circuitRelayServer(),
            ping: ping()
        }
    })

    libp2p.services.pubsub.subscribe(PUBSUB_PEER_DISCOVERY)

Before the update, the search worked.

Peer search event is triggered now.
Request is made.
But connection is not made.

logs

libp2p:discovery:pubsub discovered peer 12D3KooWRhwKCP5WR943Gm4XrbypBAPYKiSQThX628PCajX9GnNZ on discovery +9s
index.js:344 ------------ MESSAGE ------------ {type: 'signed', from: Ed25519PeerId, data: Uint8Array(446), sequenceNumber: 16363233405102080667n, topic: 'discovery', …}
index.js:212 -------- filterMultiaddrForPeer -------- 12D3KooWRhwKCP5WR943Gm4XrbypBAPYKiSQThX628PCajX9GnNZ _Multiaddr {bytes: Uint8Array(100), #string: '/dns4/localhost/tcp/4839/p2p/12D3KooWAJKSV1yF6XVZR…3KooWRhwKCP5WR943Gm4XrbypBAPYKiSQThX628PCajX9GnNZ', #tuples: Array(6), #stringTuples: Array(6), #path: null, …}
index.js:212 -------- filterMultiaddrForPeer -------- 12D3KooWRhwKCP5WR943Gm4XrbypBAPYKiSQThX628PCajX9GnNZ _Multiaddr {bytes: Uint8Array(102), #string: '/dns4/localhost/tcp/4839/ws/p2p/12D3KooWAJKSV1yF6X…3KooWRhwKCP5WR943Gm4XrbypBAPYKiSQThX628PCajX9GnNZ', #tuples: Array(7), #stringTuples: Array(7), #path: null, …}
index.js:212 -------- filterMultiaddrForPeer -------- 12D3KooWRhwKCP5WR943Gm4XrbypBAPYKiSQThX628PCajX9GnNZ _Multiaddr {bytes: Uint8Array(98), #string: '/dns4/localhost/tcp/4839/p2p/12D3KooWAJKSV1yF6XVZR…3KooWRhwKCP5WR943Gm4XrbypBAPYKiSQThX628PCajX9GnNZ', #tuples: Array(5), #stringTuples: Array(5), #path: null, …}
index.js:212 -------- filterMultiaddrForPeer -------- 12D3KooWRhwKCP5WR943Gm4XrbypBAPYKiSQThX628PCajX9GnNZ _Multiaddr {bytes: Uint8Array(100), #string: '/dns4/localhost/tcp/4839/ws/p2p/12D3KooWAJKSV1yF6X…3KooWRhwKCP5WR943Gm4XrbypBAPYKiSQThX628PCajX9GnNZ', #tuples: Array(6), #stringTuples: Array(6), #path: null, …}
index.js:265 peer:discovery 12D3KooWRhwKCP5WR943Gm4XrbypBAPYKiSQThX628PCajX9GnNZ
common.ts:122 libp2p:connection:outbound:7k26001726515400390 incoming stream opened on /ipfs/ping/1.0.0 +7s
index.js:212 -------- filterMultiaddrForPeer -------- 12D3KooWAJKSV1yF6XVZRzMnh6YFd5tbXbQQZxwHAMxZXfWyQpm6 _Multiaddr {bytes: Uint8Array(14), #string: '/dns4/localhost/tcp/4839', #tuples: Array(2), #stringTuples: Array(2), #path: null, …}
index.js:212 -------- filterMultiaddrForPeer -------- 12D3KooWAJKSV1yF6XVZRzMnh6YFd5tbXbQQZxwHAMxZXfWyQpm6 _Multiaddr {bytes: Uint8Array(16), #string: '/dns4/localhost/tcp/4839/ws', #tuples: Array(3), #stringTuples: Array(3), #path: null, …}
common.ts:122 libp2p:ping incoming ping from 12D3KooWAJKSV1yF6XVZRzMnh6YFd5tbXbQQZxwHAMxZXfWyQpm6 +0ms
common.ts:122 libp2p:ping incoming ping from 12D3KooWAJKSV1yF6XVZRzMnh6YFd5tbXbQQZxwHAMxZXfWyQpm6 complete in 6ms +7ms
common.ts:122 libp2p:connection:outbound:7k26001726515400390 starting new stream for protocols /ipfs/ping/1.0.0 +1s
common.ts:122 libp2p:yamux:outbound:9 selected protocol /ipfs/ping/1.0.0 +0ms
index.js:212 -------- filterMultiaddrForPeer -------- 12D3KooWAJKSV1yF6XVZRzMnh6YFd5tbXbQQZxwHAMxZXfWyQpm6 _Multiaddr {bytes: Uint8Array(14), #string: '/dns4/localhost/tcp/4839', #tuples: Array(2), #stringTuples: Array(2), #path: null, …}
index.js:212 -------- filterMultiaddrForPeer -------- 12D3KooWAJKSV1yF6XVZRzMnh6YFd5tbXbQQZxwHAMxZXfWyQpm6 _Multiaddr {bytes: Uint8Array(16), #string: '/dns4/localhost/tcp/4839/ws', #tuples: Array(3), #stringTuples: Array(3), #path: null, …}
common.ts:122 libp2p:yamux frame for missing stream id=9 +8s
common.ts:122 libp2p:discovery:pubsub broadcasting our peer data on topic discovery +1s
common.ts:122 libp2p:gossipsub rpc.from 12D3KooWAJKSV1yF6XVZRzMnh6YFd5tbXbQQZxwHAMxZXfWyQpm6 subscriptions 0 messages 1 ihave 0 iwant 0 graft 0 prune 0 +10s
common.ts:122 libp2p:discovery:pubsub discovered peer 12D3KooWRhwKCP5WR943Gm4XrbypBAPYKiSQThX628PCajX9GnNZ on discovery +9s

And this log is repeated.

In the new version of the libp2p library, the autoDial module was removed. Apparently, this is why the module stopped working.

Do I have any errors in the configuration or do I need to change something in the library?

@ZababurinSergei
Copy link
Author

ZababurinSergei commented Sep 18, 2024

The connection is happening.
But in the logs I saw that an error occurs when creating a stream

image

image

@elielnfinic
Copy link

Is this issue fixed?

@NiKrause
Copy link

NiKrause commented Mar 11, 2025

I am also using pubsub-peer-discovery and since some times it doesn't work anymore. Out of my perspective the discovered peerId doesn't have any multiaddrs.
e.g. I am logging:

Peer 12D3xxxxxxYuAd discovered: 12D3KxxxxJTE
peer.multiaddrs {id: Ed25519PeerId, multiaddrs: Array(0)}

I am using two different browsers which connect to a local relay via wss.

@NiKrause
Copy link

NiKrause commented Mar 12, 2025

I changed the following two things in my libp2p config and then at least I could fix the issue with the empty multiaddrs!

addresses: { listen: ['/p2p-circuit', ],...}
and I also added identifyPush: identifyPush() to services section!

PubSubPeerDiscovery still does not connect to the discovered peers automatically, so I had to do that manually in such a way in my browser code (here Svelte Code).

They question is raised, if we should to add an "autodial" flag to the PubSubPeerDiscovery Module and dial from there.

$libp2p?.addEventListener('peer:discovery', async (evt) => {
      const peer = evt.detail
      console.log(`Peer ${$libp2p?.peerId.toString()} discovered: ${peer.id.toString()}`)
      console.log('peer.multiaddrs', peer)
      const connections = $libp2p?.getConnections(peer.id)
      if (!connections || connections.length === 0) {
        console.log(`Dialing new peer: ${peer.id.toString()}`)
        
        // Try each multiaddr until one succeeds
        let connected = false
        for (const addr of peer.multiaddrs) {
          try {
              console.log('dialing', addr.toString())
              await $libp2p?.dial(addr)
              console.log('Successfully dialed:', addr.toString())
              connected = true
            break // Exit the loop once successfully connected
          } catch (error) {
            console.warn(`Failed to dial ${addr.toString()}:`, error.message)
          }
        }
        if (!connected) {
          console.error(`Failed to connect to peer ${peer.id.toString()} on all addresses`)
        }
      } else {
        console.log(`Already connected to peer: ${peer.id.toString()}`)
      }
    })

That is my libp2p config

export const Libp2pOptions = {
    addresses: {
        listen: [
            '/p2p-circuit',
            "/webrtc",
            "/webtransport",
            "/wss", "/ws",
        ]
    },
    transports: [
        webTransport(),
        webSockets({filter: filters.all}),
        webRTC({
             rtcConfiguration: {
                 iceServers:[{
                     urls: [
                         'stun:stun.l.google.com:19302',
                         'stun:global.stun.twilio.com:3478'
                     ]
                 }]
             }
         }),
        webRTCDirect(),
        circuitRelayTransport({ discoverRelays: 1 })
    ],
    connectionEncrypters: [noise()],
    streamMuxers: [
        yamux(),
    ],
    connectionGater: {
        denyDialMultiaddr: () => {
            return false
        }
    },
    peerDiscovery: [
        bootstrap(bootstrapConfig),
        pubsubPeerDiscovery({
            interval: 10000,
            topics: pubSubPeerDiscoveryTopics, // defaults to ['_peer-discovery._p2p._pubsub']
            listenOnly: false,
        })
    ],
    services: {
        identify: identify(),
        identifyPush: identifyPush(),
        ping: ping(),
        autoNAT: autoNAT(),
        dcutr: dcutr(),
        pubsub: gossipsub({ allowPublishToZeroTopicPeers: true, canRelayMessage: true })
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants