-
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
fix: keep observed addrs alive as long as their associated connections are alive #899
Conversation
…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(), |
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.
Moved into the observed addr manager.
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 | ||
} |
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.
Moved from identify.
2276bfd
to
84b923c
Compare
activeConnsMu sync.Mutex | ||
// active connection -> most recent observation | ||
activeConns map[network.Conn]ma.Multiaddr | ||
|
||
mu sync.RWMutex |
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.
why do we need two mutexes here?
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.