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

don't add peers with only private addresses to your routing table #360

Merged
merged 6 commits into from
Jun 26, 2019

Conversation

whyrusleeping
Copy link
Contributor

No description provided.

dht.go Show resolved Hide resolved
Copy link
Contributor

@magik6k magik6k left a comment

Choose a reason for hiding this comment

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

Other than iterating all peers addresses, LGTM

dht.go Outdated
return true
}

for _, a := range dht.host.Peerstore().Addrs(p) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we already deal with advertising tons of relay addresses? If not this can get quite expensive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oooh, I think we're mostly past that, but should we check the number of addresses here? If we have a ton, we probably don't want that peer in the routing table...

dht.go Show resolved Hide resolved
@magik6k
Copy link
Contributor

magik6k commented Jun 25, 2019

Also, this makes some tests fail with Got unexpected error: failed to find any peer in table

@whyrusleeping
Copy link
Contributor Author

Also, this makes some tests fail

Yeah, because now peers being included in the routing table depends on identify having finished. Now theres a race between identify and the rest of the code handling adding peers to the routing table

dht.go Outdated
}

func (dht *IpfsDHT) shouldAddPeerToRoutingTable(p peer.ID) bool {
return dht.hasOutboundConnToPeer(p) ||
Copy link
Member

@raulk raulk Jun 25, 2019

Choose a reason for hiding this comment

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

Based on new discoveries, I think we should ignore if:

  1. we don't have addresses for the peer; after merging identify: Update addr advertise logic to exclude localhost addrs selectively go-libp2p#657, peers that are not routable (e.g. no NAT mapping or pinhole) nor connected to a relay will advertise 0 addrs for themselves.
  2. if we only have localhost addresses for the peer (old, non-routable peers without the above patch).
  3. if remote multiaddr != any of peer's advertised addrs
    • likely to be an inbound connection via an ephemeral NAT port mapping
    • this correctly covers the LAN connection case, i.e. if we're on LAN, we will be connected to their advertised address, so we'll add them to the routing table. IMPORTANT: we should not return these peers in queries from peers who are not also in the LAN.
  4. if the remote advertises relay addresses (consequence of being behind a NAT, we don't want them in the routing table).
  5. if they don't support the DHT server protocol (upgraded peers).

dht.go Outdated
}

func (dht *IpfsDHT) UpdateConn(ctx context.Context, c network.Conn) {
logger.Event(ctx, "updatePeer", c.RemotePeer())
Copy link
Member

Choose a reason for hiding this comment

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

Should move this inside the if?

dht.go Outdated
}

var hasPublicAddr bool
for _, a := range dht.host.Peerstore().Addrs(c.RemotePeer()) {
Copy link
Member

Choose a reason for hiding this comment

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

Use the addrs local var?

dht.go Outdated
return false
}

return false
Copy link
Member

Choose a reason for hiding this comment

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

return true?

Copy link
Member

Choose a reason for hiding this comment

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

Assuming we want to return true ^^, we could reach here if the peer has a public address, yet with an ephemeral port mapping. I'm starting to think the c.RemoteMultiaddr() in addrs check is not that bad.

}

func (dht *IpfsDHT) peerIsOnSameSubnet(c network.Conn) bool {
return manet.IsPrivateAddr(c.RemoteMultiaddr())
Copy link
Member

Choose a reason for hiding this comment

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

How is this checking if we're on the same subnet as the peer? How about a manet.IsPrivateAddr(c.RemoteMultiaddr()) && c.RemoteMultiaddr() in addrs check here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we are connected to someone, and the connection is a private IP address, we must be on the same subnet as them, as private IPs are never routed outside of their subnet

Copy link
Member

Choose a reason for hiding this comment

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

duh, of course

// we established this connection, so they're definitely diallable.
return true
}
if dht.peerIsOnSameSubnet(c) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we do this here, we don't return false for peers with no addresses at all, or peers with relay addresses.

Copy link
Member

@raulk raulk Jun 26, 2019

Choose a reason for hiding this comment

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

peers with relay addrs are caught in L299. let me look at the 0-addr case.

Copy link
Member

Choose a reason for hiding this comment

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

wait no, they're covered iff we're connected to them via a relay, but not if we are directly connected but they advertise relay addrs.

@raulk raulk changed the base branch from master to stabilize June 26, 2019 11:55
}

func (dht *IpfsDHT) shouldAddPeerToRoutingTable(c network.Conn) bool {
if isRelayAddr(c.RemoteMultiaddr()) {
Copy link
Member

Choose a reason for hiding this comment

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

We should only check this for outbound connections. If we're behind a relay and operating in client mode, we still want to use relayed peers in our DHT.

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.

4 participants