-
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
Replace peer addresses in identify #599
Conversation
A concern here is that we might be clobbering permanent addresses. |
It looks like we'll need a change in the peerstore interface to avoid clobbering them. |
An approach that doesn't require a change is to set the |
In terms of interface changes, we can perhaps add This would look like this: permaddrs := id.Host.Peerstore().GetAddrs(p, pstore.PermenentAddrTTL)
switch ids.Host.Network().Connectedness(p) {
case inet.Connected:
ids.Host.Peerstore().SetAddrs(p, lmaddrs, pstore.ConnectedAddrTTL)
default:
ids.Host.Peerstore().SetAddrs(p, lmaddrs, pstore.RecentlyConnectedAddrTTL)
}
if len(permaddrs) > 0 {
id.Host.Peerstore.AddAddrs(p, permaddrs, pstore.PermenentAddrTTL)
} thoughts @Stebalien @raulk ? |
Relates to libp2p/go-libp2p-identify#2 cc @hsanjuan. |
p2p/protocol/identify/id.go
Outdated
@@ -252,9 +252,9 @@ func (ids *IDService) consumeMessage(mes *pb.Identify, c inet.Conn) { | |||
ids.addrMu.Lock() | |||
switch ids.Host.Network().Connectedness(p) { | |||
case inet.Connected: | |||
ids.Host.Peerstore().AddAddrs(p, lmaddrs, pstore.ConnectedAddrTTL) | |||
ids.Host.Peerstore().SetAddrs(p, lmaddrs, pstore.ConnectedAddrTTL) |
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 function is really deceptive. It sets the TTLs for the given addrs but doesn't actually swap out the old addrs for a new set.
As far as I can tell, nobody actually uses this. We now use UpdateAddrs
to atomically change TTLs.
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 don't think UpdateAddrs
is sufficient here: it only updates the given addrs and requires us to know the old TTL. It only changes the TTLs, it doesn't remove addrs.
Specifically, if the most recent IdentifyPush
removed addrs from the set, ie maybe because autorelay has rewritten the addr set, then the old addrs not in the new set will stick around forever!
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.
My proposal is to modify SetAddrs
to discard the old addrs and act as a real setter (and be its first user), and introduce a new GetAddrs
method that allows us to retrieve the old addrs associated with some TTL. The latter will allow us to avoid clobbering permanent Addrs.
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.
Actually, there might be a way to do the dance with UpdateAddrs
and AddAddrs
.
First update addrs of ConnectedTTL
to TempTTL
and then AddAddrs
with connected ttl.
It doesn't have the same effect as removing addrs, but it's close as it will mark them eligible for garbage collection and reduce the exposure time for gossiping invalid addrs.
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 can go one step further and set the TTL to 0 to invalidate them, no interface change necessary.
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 and rebased/squased//force-pushed.
My interest here boils down to never deleting or changing the TTL on addresses added with PermanentAddrTTL, even if they don't work. |
e975f55
to
06391d4
Compare
The implementation in 06391d4 never touches permanent addr TTLs. It only replaces addresses with |
p2p/protocol/identify/id.go
Outdated
@@ -252,8 +252,10 @@ func (ids *IDService) consumeMessage(mes *pb.Identify, c inet.Conn) { | |||
ids.addrMu.Lock() | |||
switch ids.Host.Network().Connectedness(p) { | |||
case inet.Connected: | |||
ids.Host.Peerstore().UpdateAddrs(p, pstore.ConnectedAddrTTL, 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.
I wasn't actually suggesting that we use UpdateAddrs
(I was also thinking about fixing SetAddrs
) but I actually like this more.
Maybe we should downgrade these to TempAddrTTL
instead of 0? Honestly, I'm fine either way and TempAddrTTL
is long enough that that might cause problems. My only concern is that we'll have a short period where we'll have no good addresses.
We could also use a constant 10s timeout (for really temporary addresses).
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.
It's a valid concern I think, so I'll update to use a 10s ttl to cover the gap.
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 called it transientTTL
and it's 10s long; maybe we should have this constant in the peerstore.
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.
Well, that's what TempAddrTTL
was supposed to be...
Closes #579.