-
Notifications
You must be signed in to change notification settings - Fork 93
Not getting peers nor pubsub messages #268
Comments
Hey Mark, Just looking at the code, I can see some issues. Just using your own signal server, you should be able to open multiple browsers in the same machine, or even in different machines and they will discover and connect to each other. |
Hi Vasco, Do note that the address i was using in the bootstrap was I fiddled with the addresses a bit to reflect what you just told me. It didn't change anything for me (no peers). Also, you mentioned that i should not use the p2p-webrtc-star with peer id. I merely got that from https://github.com/libp2p/js-libp2p-webrtc-star which mentions:
which made me think that i need to add it... I immediately believe you tell me otherwise as you're the developer of that project :) package.json {
"name": "testproject",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"build": "parcel build src/index.html",
"start": "parcel src/index.html"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-polyfill": "^6.26.0",
"libp2p": "^0.29.2",
"libp2p-bootstrap": "^0.12.1",
"libp2p-gossipsub": "^0.6.4",
"libp2p-mplex": "^0.10.1",
"libp2p-noise": "^2.0.1",
"libp2p-pubsub-peer-discovery": "^3.0.0",
"libp2p-tcp": "^0.15.1",
"libp2p-webrtc-star": "^0.20.1",
"libp2p-websockets": "^0.14.0",
"os-browserify": "^0.3.0",
"parcel-bundler": "^1.12.4",
"uint8arrays": "^1.1.0"
},
"devDependencies": {}
} index.js 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 = [
'/ip4/116.203.242.65/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: [
// '/ip4/0.0.0.0/tcp/0'
'/dns4/star.sc2.nl/tcp/443/wss/p2p-webrtc-star',
// '/dns4/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)
})() index.html <!DOCTYPE html>
<html lang="en">
<head>
<title>blaaaaaa</title>
<script src="index.js"></script>
</head>
<body>
<div id="root"></div>
</body>
</html> Put index.js and index.html in a folder called |
Indeed there is an issue with
The above is true, the peer will be listening on I will look deeper on your example and get back. |
I did notice that i got peers from star2 too. But even then, pubsub didn't work. My whole goal here is to have pubsub working, just to be clear about that :) |
Ok, I copied your project and just ran it:
I removed the bootstrap module for now. You will need to use a websocket transport there.
-- With this, for achieving your goal you just need to be able to connect with the bootstrap node. I believe the websocket address is not configured by default in go. You need to add that address in the IPFS config file (default in ~/.ipfs/config) with something like: "Swarm": [
"/ip4/0.0.0.0/tcp/4001",
"/ip4/0.0.0.0/tcp/4010/ws",
"/ip6/::/tcp/4001",
"/ip6/::/tcp/4010/ws",
"/ip4/0.0.0.0/udp/4001/quic",
"/ip6/::/udp/4001/quic"
] |
@markg85 out of topic, but I remembered that it would be super helpful if you could create docs for setting up the star server, since you got it running. Would you be interested and creating a PR targeting this (in progress PR) libp2p/js-libp2p#718 to add instructions for the star servers? |
I'm lost... If i understand you correctly you just removed the bootstrapping and that made it work for you? 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 GossipSub from 'libp2p-gossipsub'
const uint8ArrayFromString = require('uint8arrays/from-string')
const uint8ArrayToString = require('uint8arrays/to-string')
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: [
// '/ip4/0.0.0.0/tcp/0'
'/dns4/star.sc2.nl/tcp/443/wss/p2p-webrtc-star',
// '/dns4/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,
},
config: {
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)
})() Then i still get the same af before. Nothing. Also, i don't get why i need to change my IPFS node to talk with websockets. |
Hmm, i have more results now. Ehm... Also, am i correct in assuming that if i enable websocket on my IPFS node that i only need the bootstrap node and can get rid of the whole WebRTCStar? Including the signaling thingy on star.sc2.nl? |
Yes, that is the expected. So, on a general note I will explain you the flow for Webrtc-star transport+discovery module should be used to easily achieve connectivity between browser peers. If you simply want a connection between a go-ipfs node and a browser node, the browser node will need to discover the go-ipfs node address (this discovery can be manual, by adding its address to the bootstrap addresses, or even a manual dial). So, a browser node might use Webrtc or Websockets. Currently, go-ipfs webrtc is still being worked on AFAIK, so you should use websockets to achieve this connectivity.
Per the above paragraph, yes Bear in mind that we are currently working on other protocols to improve these flows libp2p/js-libp2p#703 |
Ok, right. I couldn't find any of this on the github pages btw. So i changed my node to allow You can try to use my node (ipfs.sc2.nl) it should have websockets enabled now. |
It is a mixture of concepts.
For a simple scenario you can do const node = await Libp2p.create({
modules: {
transport: [Websockets],
streamMuxer: [Mplex],
connEncryption: [NOISE],
pubsub: GossipSub,
},
config: {
peerDiscovery: {
autoDial: true,
[Bootstrap.tag]: {
enabled: true,
list: [
// Your go ipfs ws address (with peer ID)
]
}
},
pubsub: {
enabled: true,
emitSelf: false
}
}
}) Other solution would be to not use bootstrap at all and do: const node = Libp2p.create({...})
await node.start()
await node.dial(ipfsWebsocketMultiaddr)
What port did you use? |
Please try to improve that. The very fact that it works that way causes it to be very vague for anyone to want to use it. It raises the bar a lot more then it would need to be if there were concise clear examples of explaining individual concepts.
Well, i don't know which port i need to use :) I have: But that's what you said to be wrong for websockets. So i added the websockets part in the config as per your suggestion. |
It would be great if you could provide direct feedback on what types of examples you would expect and why are they valuable. There are a lot of use cases and at the moment there are a set of examples that enable the basic use cases, but the community input on their difficulties is important.
Yes, but you needed to specify a port: Like I suggested it would be 4010: "Swarm": [
"/ip4/0.0.0.0/tcp/4001",
"/ip4/0.0.0.0/tcp/4010/ws",
"/ip6/::/tcp/4001",
"/ip6/::/tcp/4010/ws",
"/ip4/0.0.0.0/udp/4001/quic",
"/ip6/::/udp/4001/quic"
] Than the address would be: Also, for questions and general support we kindly ask people to use https://discuss.libp2p.io as it will help the entire community, and you can get a broad support. Issues should be for bugs, feature requests, ..., as you can see, we are discussing this issue which is not relevant in |
Now i feel stupid as i completely missed the 4010 port part. Oops. It now slowly begins to work, but still not as i would expect it to. Now it does connect when using bootstrapping and if send a pubsub message from that machine (so from 116.203.242.65 itself) then it arrives in the browser log. As i would expect. But.. If i now use my local machine's IPFS (peer id: 12D3KooWHatJmgusU8E9WSnJiprkVALyLfUufbYsvcJxbzM8RqyD) to post a message on the same pubsub channel i get.... nothing. I'm also not getting any additional nodes besides the one i'm connected to with the bootstrapping. As for the examples. I will definitely help there with contributing this very example (use libp2p in the browser to connect to ipfs and use pubsub). As that, when working properly, is a very awesome tool to have! So funnily enough, we're a lot further now but still on the very same issue that i started with. |
Yes, you need the
Yes, that would eventually be expected. If peer A cannot reach peer B by any way, it will not be able to propagate pubsub messages around. So, this seems a connectivity issue as before. I recommend you describe what is your complete use case, and how you see the network topology and peers communication with each other. With that, I can help you with the best solution. Please create a post in the discuss forum for us to proceed. |
What i'm trying to achieve is basically a client-server model. How i envision this to work is as follows: The only thing both know is the channel on which to publish messages. You could apply the above principle to a whole slew of site concepts. Think of the following:
I could be wrong, but this seems to be a very valid and simple usecase for pubsub. One that works just fine if the browser is not involved. So where the client is an application that can connect via the IPFS api. Things just get exponentially more complicated as soon as a browser is involved. The problem here is the client that somehow magically needs to connect to the same network as the rest of IPFS. That apparently proves to be a lot more complicated then i had though. Add to that the HTTPS demand of browsers nowadays and you're in a whole mess of protocols. |
Hey @markg85 |
12 days later... sorry for that. I'll wait with posting till you confirmed this one :) Thank you a lot for all your help thus far! |
@markg85 yes, it is also fine if you post to discuss.ipfs.io! Thanks for understanding |
Bump - I think the autodialing isn't working.
...
|
Update... saw, after a google of Not the greatest way to manage it but
|
I might add - I'm trying to pass messages to myself through different instances locally. |
Hrm. It looks like pubsub on a local computer/instance, between two nodeJS processes, only process one of the pubsub streams (i havent tested other topics yet). |
Hello @jacobfriedman libp2p.on('peer:connect', (connection) => {
console.log('\n \n Connection established to:', connection.remotePeer.toB58String())
}) should be the follow (check the API.md): libp2p.connectionManager.on('peer:connect', (connection) => {
console.log('\n \n Connection established to:', connection.remotePeer.toB58String())
})
So, if you are trying to talk with a node that unfortunately did not update its connectionEncryption module to |
I'll make a new issue. It's not an RTC problem. I added the
connectionmanager in and will report on the pubsub issue I had
…On Wed., Nov. 18, 2020, 4:05 a.m. Vasco Santos, ***@***.***> wrote:
Hello @jacobfriedman <https://github.com/jacobfriedman>
Any reason for not creating a new issue?
I am not sure if I understood the issue, but I noticed in your code an API
issue so far:
libp2p.on('peer:connect', (connection) => {console.log('\n \n Connection established to:', connection.remotePeer.toB58String()) })
should be the follow (check the API.md
<https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#libp2pconnectionmanager>
):
libp2p.connectionManager.on('peer:connect', (connection) => {console.log('\n \n Connection established to:', connection.remotePeer.toB58String()) })
Update... saw, after a google of Error: protocol selection failed... SECIO
is required!? But it's deprecated! I added it and will post the update back
here .
So, if you are trying to talk with a node that unfortunately did not
update its connectionEncryption module to Noise, your peer will not be
able to talk with it as you will be using Noise and it only supports SECIO.
What is the node in question?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#268 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFKHXWOWAJMUOUGUAAHSMTSQOE7NANCNFSM4TFNY24A>
.
|
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.
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 onlystar2
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
The text was updated successfully, but these errors were encountered: