-
Notifications
You must be signed in to change notification settings - Fork 226
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
Changes from 1 commit
9387b5a
03293e8
c6cd6d5
8bf0863
f34a5b1
9bc949d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -299,18 +299,29 @@ func (dht *IpfsDHT) shouldAddPeerToRoutingTable(c network.Conn) bool { | |
if isRelayAddr(c.RemoteMultiaddr()) { | ||
return false | ||
} | ||
return c.Stat().Direction == network.DirOutbound || | ||
dht.hasSensibleAddressesForPeer(c) | ||
if c.Stat().Direction == network.DirOutbound { | ||
// we established this connection, so they're definitely diallable. | ||
return true | ||
} | ||
if dht.peerIsOnSameSubnet(c) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
// TODO: for now, we can't easily tell if the peer on our subnet | ||
// is dialable or not, so don't discriminate. | ||
magik6k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// We won't return these peers in queries unless the requester's | ||
// remote addr is also private. | ||
return true | ||
} | ||
ai := dht.host.Peerstore().PeerInfo(c.RemotePeer()) | ||
return dht.hasSensibleAddressesForPeer(ai) | ||
} | ||
|
||
func (dht *IpfsDHT) hasSensibleAddressesForPeer(c network.Conn) bool { | ||
addrs := dht.host.Peerstore().Addrs(c.RemotePeer()) | ||
if len(addrs) == 0 { | ||
func (dht *IpfsDHT) hasSensibleAddressesForPeer(ai peer.AddrInfo) bool { | ||
if len(ai.Addrs) == 0 { | ||
return false | ||
} | ||
|
||
var hasPublicAddr bool | ||
for _, a := range addrs { | ||
for _, a := range ai.Addrs { | ||
if isRelayAddr(a) { | ||
return false | ||
} | ||
|
@@ -319,19 +330,7 @@ func (dht *IpfsDHT) hasSensibleAddressesForPeer(c network.Conn) bool { | |
hasPublicAddr = true | ||
} | ||
} | ||
|
||
if dht.peerIsOnSameSubnet(c) && !hasPublicAddr { | ||
// TODO: for now, we can't easily tell if the peer on our subnet | ||
// is dialable or not, so don't discriminate. | ||
// ! It may be okay to not add these to our routing table... | ||
return true | ||
} | ||
|
||
if !hasPublicAddr { | ||
return false | ||
} | ||
|
||
return true | ||
return hasPublicAddr | ||
} | ||
|
||
// taken from go-libp2p/p2p/host/relay | ||
|
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 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.