Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.
This repository was archived by the owner on Apr 24, 2023. It is now read-only.

Not getting peers nor pubsub messages #268

Closed
@markg85

Description

@markg85

Hi,

I have setup a "webrtc-star" server here: https://star.sc2.nl/
Next i use the following code that is compiled to browser code using parcel. You can (nearly literally) copy/paste it in your own setup.

import 'babel-polyfill';
import Libp2p from 'libp2p'
// const TCP = require('libp2p-tcp')
import Websockets from 'libp2p-websockets'
import WebRTCStar from 'libp2p-webrtc-star'
import { NOISE } from 'libp2p-noise'
import Mplex from 'libp2p-mplex'
import Bootstrap from 'libp2p-bootstrap'
import GossipSub from 'libp2p-gossipsub'
const uint8ArrayFromString = require('uint8arrays/from-string')
const uint8ArrayToString = require('uint8arrays/to-string')

const bootstrapMultiaddrs = [
    '/dnsaddr/ipfs.sc2.nl/tcp/4001/p2p/12D3KooWLVFqkLQGa4rRFmqrVtTnm4CkKrySm8V1cCebxnDmx53N',
    // '/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
    // '/ip4/104.236.176.52/tcp/4001/p2p/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
    // '/ip4/104.236.179.241/tcp/4001/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
    // '/ip4/162.243.248.213/tcp/4001/p2p/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
    // '/ip4/128.199.219.111/tcp/4001/p2p/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
    // '/ip4/104.236.76.40/tcp/4001/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
    // '/ip4/178.62.158.247/tcp/4001/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
    // '/ip4/178.62.61.185/tcp/4001/p2p/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
    // '/ip4/104.236.151.122/tcp/4001/p2p/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx'
]

const createNode = async () => {
    const node = await Libp2p.create({
        addresses: {
            // Add the signaling server address, along with our PeerId to our multiaddrs list
            // libp2p will automatically attempt to dial to the signaling server so that it can
            // receive inbound connections from other peers
            listen: [
                '/dnsaddr/star.sc2.nl/tcp/443/wss/p2p-webrtc-star/p2p/12D3KooWLVFqkLQGa4rRFmqrVtTnm4CkKrySm8V1cCebxnDmx53N',
                // '/dnsaddr/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star',
                // '/dnsaddr/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star'
            ]
        },
        modules: {
            // transport: [TCP],
            transport: [Websockets, WebRTCStar],
            streamMuxer: [Mplex],
            connEncryption: [NOISE],
            pubsub: GossipSub,
            peerDiscovery: [Bootstrap]
        },
        config: {
            peerDiscovery: {
                autoDial: true, // Auto connect to discovered peers (limited by ConnectionManager minConnections)
                // The `tag` property will be searched when creating the instance of your Peer Discovery service.
                // The associated object, will be passed to the service when it is instantiated.
                [Bootstrap.tag]: {
                    enabled: true,
                    list: bootstrapMultiaddrs // provide array of multiaddrs
                }
            },
            pubsub: {
                enabled: true,
                emitSelf: false
            }
        }
    })

    await node.start()
    return node
}

(async () => {
    const topic = 'news'

    const node = await createNode();

    const listenAddrs = node.transportManager.getAddrs()
    console.log('libp2p is listening on the following addresses: ', listenAddrs)

    const advertiseAddrs = node.multiaddrs
    console.log('libp2p is advertising the following addresses: ', advertiseAddrs)


    node.on('peer:discovery', (peer) => {
        console.log('Discovered %s', peer.toB58String()) // Log discovered peer
    })

    node.connectionManager.on('peer:connect', (connection) => {
        console.log('Connected to %s', connection.remotePeer.toB58String()) // Log connected peer
    })

    node.pubsub.on(topic, (msg) => {
        console.log(`node received: ${uint8ArrayToString(msg.data)}`)
    })
    await node.pubsub.subscribe(topic)

    setInterval(() => {
        node.pubsub.publish(topic, uint8ArrayFromString('Bird bird bird, bird is the word!'))
    }, 1000)
})()

Note, please do tell me anything that's wrong with this code. I've merely scraped it together from multiple examples throughout readme pages, examples and issues posts.. It seems very difficult to get this working properly.

In the code above, i'm connecting (at least i think listen does that? shouldn't bootstrap connect? ... confusion all the way) to: /dnsaddr/star.sc2.nl/tcp/443/wss/p2p-webrtc-star/p2p/12D3KooWLVFqkLQGa4rRFmqrVtTnm4CkKrySm8V1cCebxnDmx53N

On the console i do get two outputs with that where it claims to be listening on that address and advertising.
But i'm not receiving any node connections, not after waiting for hours...

Next, if i try /dnsaddr/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star (star 2) as listen address i do get nodes quite quickly. But it's advised to not use that.
Also, if i post any message on the "news" pubsub room with an IPFS client, i'm not getting any message here.

Lastly, the /dnsaddr/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star (star1) is just there because this library gives me these two as defaults. Now note though that only star2 seems to be giving any peers.

I'm very likely just doing something wrong here. What, i have no clue about. At all.
So err, help please :)

Cheers,
Mark

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions