-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Clean addresses with peer id before adding to addrbook #2007
Conversation
I'm cleaning the address before adding it to addressbook. The other option is to change the check in all transports. This seemed cleaner to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for picking this up! This is really helpful 🎉. There's a couple of things we should do before merging this:
- The changes mentioned in the review.
- We should update the implementations of
Host.Connect
so that they check that the multiaddrs with ap2p
component in theAddrs
field match theID
field. Filter out any mismatching multiaddrs (maybe log a warning). And return an error if no addresses are dialable because of mismatched peer ids. As well as removing thep2p
component of the multiaddr before passing it down the call stack.
p2pAddr := addr[0].Encapsulate(Multiaddr("/p2p/" + peerId.String())) | ||
ab.AddAddr(peerId, p2pAddr, time.Hour) | ||
AssertAddressesEqual(t, addr, ab.Addrs(peerId)) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a case that fails if the peer id in the multiaddr is != to the peer id passed in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The annoying thing is that AddAddr
doesn't return an error. So the best we can do here is to fail silently and log an error in the implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added another test case with filtering on invalid peerId
@@ -601,10 +601,12 @@ func (ab *dsAddrBook) deleteAddrs(p peer.ID, addrs []ma.Multiaddr) (err error) { | |||
func cleanAddrs(addrs []ma.Multiaddr) []ma.Multiaddr { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should now take a peer id as well, and filter out multiaddrs that have an id component but don't match (and log an error when this happens)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm logging a warning which was previously logged for nil addresses, should I make it an error?
@@ -238,19 +238,21 @@ func (mab *memoryAddrBook) addAddrsUnlocked(s *addrSegment, p peer.ID, addrs []m | |||
|
|||
exp := mab.clock.Now().Add(ttl) | |||
for _, addr := range addrs { | |||
if addr == nil { | |||
// Remove suffix of /p2p/peer-id from address | |||
taddr, _ := peer.SplitAddr(addr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as above about the peer id check. Also I think it's okay to shadow the addr variable
with the new multiaddr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be fixed
@@ -283,17 +285,18 @@ func (mab *memoryAddrBook) SetAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Du | |||
|
|||
exp := mab.clock.Now().Add(ttl) | |||
for _, addr := range addrs { | |||
if addr == nil { | |||
taddr, _ := peer.SplitAddr(addr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed now.
All Host.Connect implementations use PeerStore.AddAddrs which will filter out for invalid ID and log the warning, should I do it in the connect implementation as well?
|
Add error reporting from Host.Connect
@MarcoPolo Addressed review comments. Do the changes in Host.Connect look okay? |
Good point. If there are no available addresses we'll still get that error from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small nits. I pushed a change. Thanks a ton for fixing this :)
p2p/host/basic/basic_host.go
Outdated
@@ -709,6 +709,11 @@ func (h *BasicHost) Connect(ctx context.Context, pi peer.AddrInfo) error { | |||
} | |||
} | |||
|
|||
addrs := h.Peerstore().Addrs(pi.ID) | |||
if len(addrs) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought we already return a similar error here https://github.com/libp2p/go-libp2p/blob/master/p2p/net/swarm/swarm_dial.go#L340. So this change is not required. Sorry I added confusion here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's fair. Thanks for fixing this!
Will merge after CI passes. |
Thanking you folks for getting this issue resolved so quickly 🙇 |
Fixes: #2001