Comments (5)
So sometimes I can see the multiaddr but sometimes not. Why?
not sure about that.
Why was there a host with port 59919 created for 5000?
that's an ephemeral port, it is created by the kernel when you make an outbound connection.
from go-libp2p-examples.
@lzl124631x What OS?
from go-libp2p-examples.
Richards-MacBook-Pro:~ ricl$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.1
BuildVersion: 18B75
from go-libp2p-examples.
I've forgotten why I asked that, but it was relevant at the time.
from go-libp2p-examples.
Hey @lzl124631x. With reference to your first question:
Task:
- Set yourself as a provider to id "key".
- Find other peers with id "key".
Note: Locally known (cached) providers are stored in something called a providerSet
. A call to FindProviders
, FindProvidersAsync
or Provide
will be responsible for updating any new peer to the providerSet
. (there might be other functions which can update providerSet
)
The situation you are facing arises when your node, say X
tries to connect to some other node, say Y
which is already connected to the bootstrap node, B
(or any node common to X
and Y
).
- To begin with,
Y
wants to connect toB
. After successfully connecting,B
storesY
in its closest peers list and vice versa.Y
also calledY.dht.Provide("key")
to be a provider for "key". - Now when
X
connects toB
, they connect successfully. - When
X.dht.Provide()
is called:
3.1X
adds itself to theproviderSet
but with empty address i.e. []. (This is important)
3.2 It then callsX.dht.GetClosestPeers
which fetches second degree peers from theNearestPeers
i.e.B
for now.
3.3B
will returnY
along with its addresses. Now,X
will connect toY
. [I think this step was added to improve your connections automatically. A node will automatically connect to its second degree nodes if you have insufficient number of connections.]
3.4 At this point nodeX
andY
are connected to each other. AlthoughY
is not added in theproviderSet
ofX
and vice versa. - When
X.dht.FindProvider("key")
is called:
4.1X
will run a query to find ifNearestPeers
can be a provider for "key".
4.2NearestPeers
toX
at this time areB
andY
and both will return a list of peers they know can be a provider for "key".
4.3Y
will return itself as it can be a provider for "key" but it will return empty list of address for itself.B
also returnsY
asB
knows thatY
can be a provider but becauseB
knowsY's
addresses,B
returns a full list of addresses ofY
.
4.4 Now the problem is which query returns first. If the answer fromY
is returned first it will be an empty list of address and ifB
returns you will get a full list of addresses. Although you can overwrite the empty list butPeerSet.TryAdd
used here does not add the peer to the provider set if its already in the set even if the addresses are empty.
When FindProvider
returns an empty list, under above circumstances, you are already connected to that peer so host.Connect
will be successful. Hence, Connected to: {<peer.ID Qm*UB48gJ> []} chat.go:183
.
I think this can be reported as a bug. Ideally, a node should replace an empty list of addresses with addresses known from some other peer but findProvidersAsyncRoutine
uses a chan pstore.PeerInfo
for output and a result is immediately written to this chan. This means whichever query returns the result first will be written to the chan and subsequent results will be ignored.
from go-libp2p-examples.
Related Issues (20)
- pubsub\chat example - Can't see others clients messages HOT 1
- Relay Example error HOT 2
- pubsub chat example datarace
- how to init RendezvousString in chat-with-rendezvous? HOT 2
- How do I keep nodeID unchanged every time I start it HOT 4
- Does libP2P support authentication? HOT 1
- How can i make other peers persist when another peer disconnects HOT 2
- An Error in Echo client/server with libp2p
- Dependencies out of date
- Automated testing
- How can I help PRs get merged? HOT 2
- chat-with-rendezvous doesn't work: dht failed to query self during routing table refresh HOT 3
- Add Example on configuring and using AutoRelay
- Add example to show how to configure AutoNAT client and how it discovers reachability
- go-libp2p-autonat-svc deprecated
- libp2p-host example missing _peer import
- Should I openStream every time like multipro did
- Errors with simple libp2p HOT 1
- routed-echo example: invalid character '-' after top-level value
- Modifying http_proxy/proxy.go to make the remote proxy to act as an egress gateway to connect to a non-p2p real server. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-libp2p-examples.