Skip to content
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

Merged
merged 2 commits into from
Apr 16, 2019
Merged

Conversation

vyzo
Copy link
Contributor

@vyzo vyzo commented Apr 15, 2019

Closes #579.

@vyzo vyzo requested a review from Stebalien April 15, 2019 11:17
@ghost ghost assigned vyzo Apr 15, 2019
@ghost ghost added the status/in-progress In progress label Apr 15, 2019
@vyzo
Copy link
Contributor Author

vyzo commented Apr 15, 2019

A concern here is that we might be clobbering permanent addresses.

@vyzo
Copy link
Contributor Author

vyzo commented Apr 15, 2019

It looks like we'll need a change in the peerstore interface to avoid clobbering them.

@vyzo
Copy link
Contributor Author

vyzo commented Apr 15, 2019

An approach that doesn't require a change is to set the ConnectedAddrTTL address to be TempAddrTTL with UpdateAddrs and then do AddAddrs for the new address with ConnectedAddrTTL.
A bit hacky, but it might just work.

@vyzo
Copy link
Contributor Author

vyzo commented Apr 15, 2019

In terms of interface changes, we can perhaps add GetAddrs(p, ttl) call to peerstore.
This way we can do GetAddrs(p, PermenentTTL) before the SetAddrs and then re-add the permenent addresses.

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 ?

@raulk
Copy link
Member

raulk commented Apr 15, 2019

Relates to libp2p/go-libp2p-identify#2 cc @hsanjuan.

@@ -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)
Copy link
Member

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.

Copy link
Contributor Author

@vyzo vyzo Apr 16, 2019

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!

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@hsanjuan
Copy link
Contributor

My interest here boils down to never deleting or changing the TTL on addresses added with PermanentAddrTTL, even if they don't work.

@vyzo vyzo force-pushed the feat/identify-replace-addrs branch from e975f55 to 06391d4 Compare April 16, 2019 08:49
@vyzo
Copy link
Contributor Author

vyzo commented Apr 16, 2019

The implementation in 06391d4 never touches permanent addr TTLs.

It only replaces addresses with ConnectedAddrTTL.

@vyzo vyzo requested a review from Stebalien April 16, 2019 08:51
@@ -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)
Copy link
Member

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).

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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...

@vyzo vyzo merged commit 213863a into master Apr 16, 2019
@ghost ghost removed the status/in-progress In progress label Apr 16, 2019
@vyzo vyzo deleted the feat/identify-replace-addrs branch April 16, 2019 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Identify should _replace_ addresses
4 participants