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

fix: keep observed addrs alive as long as their associated connections are alive #899

Merged
merged 2 commits into from
Apr 25, 2020

Conversation

Stebalien
Copy link
Member

Otherwise, if we're not creating new connections, we'll eventually forget them.

Up until now, this wasn't too much of an issue because our peers would still remember our addresses. However, we now tell our connected peers when our addresses change. That means we'll tell our peers to forget where we are, preventing anyone from finding us.

…s are alive

Otherwise, if we're not creating new connections, we'll eventually forget them.

Up until now, this wasn't _too_ much of an issue because our peers would still
remember our addresses. However, we now _tell_ our connected peers when our
addresses change. That means we'll tell our peers to forget where we are,
preventing anyone from finding us.

// ok! we have the observed version of one of our ListenAddresses!
log.Debugf("added own observed listen addr: %s --> %s", c.LocalMultiaddr(), maddr)
ids.observedAddrs.Add(maddr, c.LocalMultiaddr(), c.RemoteMultiaddr(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into the observed addr manager.

Comment on lines +269 to +298
if manet.IsIPLoopback(observed) {
return
}

// we should only use ObservedAddr when our connection's LocalAddr is one
// of our ListenAddrs. If we Dial out using an ephemeral addr, knowing that
// address's external mapping is not very useful because the port will not be
// the same as the listen addr.
ifaceaddrs, err := oas.host.Network().InterfaceListenAddresses()
if err != nil {
log.Infof("failed to get interface listen addrs", err)
return
}

local := conn.LocalMultiaddr()
if !addrInAddrs(local, ifaceaddrs) && !addrInAddrs(local, oas.host.Network().ListenAddresses()) {
// not in our list
return
}

// We should reject the connection if the observation doesn't match the
// transports of one of our advertised addresses.
if !HasConsistentTransport(observed, oas.host.Addrs()) {
log.Debugw(
"observed multiaddr doesn't match the transports of any announced addresses",
"from", conn.RemoteMultiaddr(),
"observed", observed,
)
return
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from identify.

p2p/protocol/identify/obsaddr.go Show resolved Hide resolved
p2p/protocol/identify/obsaddr.go Outdated Show resolved Hide resolved
p2p/protocol/identify/obsaddr.go Show resolved Hide resolved
p2p/protocol/identify/obsaddr.go Show resolved Hide resolved
p2p/protocol/identify/obsaddr.go Show resolved Hide resolved
Comment on lines +67 to +71
activeConnsMu sync.Mutex
// active connection -> most recent observation
activeConns map[network.Conn]ma.Multiaddr

mu sync.RWMutex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need two mutexes here?

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.

3 participants