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

new found discovered peers not added to peers #481

Open
koh-osug opened this issue Jan 6, 2024 · 4 comments
Open

new found discovered peers not added to peers #481

koh-osug opened this issue Jan 6, 2024 · 4 comments

Comments

@koh-osug
Copy link

koh-osug commented Jan 6, 2024

I'm running two nodes on the same machine and can see:

libp2p:mdns peer found 12D3KooWFvEoC1NJz5Cgcji15WyNGRjo85ytgMi7PJCQnTeTHM2B +0ms
libp2p:mdns discovered peer in mDNS query response 12D3KooWFvEoC1NJz5Cgcji15WyNGRjo85ytgMi7PJCQnTeTHM2B +1ms

Now, I would strongly assume that private onPeerConnected must be called to add this peer. But this never happens. The integration seems to be not working. I'm using version ^11.0.1

The code:

import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { tcp } from '@libp2p/tcp'
import defaultsDeep from '@nodeutils/defaults-deep'
import { createLibp2p as create } from 'libp2p'
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { mdns } from '@libp2p/mdns'
import { pubsubPeerDiscovery } from '@libp2p/pubsub-peer-discovery'

async function createLibp2p (_options) {
    const defaults = {
        addresses: {
            listen: ['/ip4/0.0.0.0/tcp/0']
        },
        transports: [
            tcp(),
        ],
        streamMuxers: [
            yamux()
        ],
        connectionEncryption: [
            noise()
        ],
        peerDiscovery: [
            mdns({
                interval: 20e3
            }),
            pubsubPeerDiscovery()
        ],
        services: {
            pubsub: gossipsub({
                allowPublishToZeroPeers: true
            })
        }
    }

    return create(defaultsDeep(_options, defaults))
}

async function run () {

    const node = await createLibp2p({
    })
    console.log('node ready, listening on:')
    node.getMultiaddrs().forEach((ma) => {
        console.log(ma.toString())
    })
    node.addEventListener('peer:discovery', (evt) => console.log('Discovered:', evt.detail.id.toString()))

    node.addEventListener('peer:connect', (evt) => {
        const remotePeer = evt.detail
        console.log('connected to: ', remotePeer.toString())
    })

    node.services.pubsub.addEventListener('message', (message) => {
        console.log(`${message.detail.topic}:`, new TextDecoder().decode(message.detail.data))
    })

    node.services.pubsub.subscribe('rendezvous')

    setInterval((async () => {
        try {
            await node.services.pubsub.publish('rendezvous', new TextEncoder().encode('test'))
        }
        catch (e) {
            console.log("error publishing", e)
        }
    }), 10000)

    return node.start()
}

await run()
@koh-osug
Copy link
Author

koh-osug commented Jan 6, 2024

The solution is to add to the config:

        connectionManager: {
        }

This is not covered by the examples or tutorials. Any reasons why? Should I create a PR to fix this?

@wemeetagain
Copy link
Member

Yes this seems like a bug. You should not need to explicitly add an empty connection manager configuration.

@wemeetagain
Copy link
Member

cc @achingbrain this seems like an issue in js-libp2p core

@wemeetagain
Copy link
Member

@achingbrain
I'm clearing out older issues now, I wonder if this is still an issue?

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

2 participants