Skip to content

Commit

Permalink
Merge pull request #982 from libp2p/marco/unexport-hasValidConnectedness
Browse files Browse the repository at this point in the history
fix: Unexport hasValidConnectedness to make a patch release
  • Loading branch information
MarcoPolo authored Aug 21, 2024
2 parents 1626e6b + ee01db8 commit 08676fa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ func (dht *IpfsDHT) FindLocal(ctx context.Context, id peer.ID) peer.AddrInfo {
_, span := internal.StartSpan(ctx, "IpfsDHT.FindLocal", trace.WithAttributes(attribute.Stringer("PeerID", id)))
defer span.End()

if HasValidConnectedness(dht.host, id) {
if hasValidConnectedness(dht.host, id) {
return dht.peerstore.PeerInfo(id)
}
return peer.AddrInfo{}
Expand Down Expand Up @@ -926,7 +926,7 @@ func (dht *IpfsDHT) newContextWithLocalTags(ctx context.Context, extraTags ...ta

func (dht *IpfsDHT) maybeAddAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Duration) {
// Don't add addresses for self or our connected peers. We have better ones.
if p == dht.self || HasValidConnectedness(dht.host, p) {
if p == dht.self || hasValidConnectedness(dht.host, p) {
return
}
dht.peerstore.AddAddrs(p, dht.filterAddrs(addrs), ttl)
Expand Down
2 changes: 1 addition & 1 deletion dht_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func inAddrRange(ip net.IP, ipnets []*net.IPNet) bool {
return false
}

func HasValidConnectedness(host host.Host, id peer.ID) bool {
func hasValidConnectedness(host host.Host, id peer.ID) bool {
connectedness := host.Network().Connectedness(id)
return connectedness == network.Connected || connectedness == network.Limited
}
11 changes: 8 additions & 3 deletions fullrt/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ func (dht *FullRT) FindPeer(ctx context.Context, id peer.ID) (pi peer.AddrInfo,

// Return peer information if we tried to dial the peer during the query or we are (or recently were) connected
// to the peer.
if kaddht.HasValidConnectedness(dht.h, id) {
if hasValidConnectedness(dht.h, id) {
return dht.h.Peerstore().PeerInfo(id), nil
}

Expand Down Expand Up @@ -1537,16 +1537,21 @@ func (dht *FullRT) getRecordFromDatastore(ctx context.Context, dskey ds.Key) (*r

// FindLocal looks for a peer with a given ID connected to this dht and returns the peer and the table it was found in.
func (dht *FullRT) FindLocal(id peer.ID) peer.AddrInfo {
if kaddht.HasValidConnectedness(dht.h, id) {
if hasValidConnectedness(dht.h, id) {
return dht.h.Peerstore().PeerInfo(id)
}
return peer.AddrInfo{}
}

func (dht *FullRT) maybeAddAddrs(p peer.ID, addrs []multiaddr.Multiaddr, ttl time.Duration) {
// Don't add addresses for self or our connected peers. We have better ones.
if p == dht.h.ID() || kaddht.HasValidConnectedness(dht.h, p) {
if p == dht.h.ID() || hasValidConnectedness(dht.h, p) {
return
}
dht.h.Peerstore().AddAddrs(p, addrs, ttl)
}

func hasValidConnectedness(host host.Host, id peer.ID) bool {
connectedness := host.Network().Connectedness(id)
return connectedness == network.Connected || connectedness == network.Limited
}
4 changes: 2 additions & 2 deletions routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (pi peer.AddrInfo,
return peers, err
},
func(*qpeerset.QueryPeerset) bool {
return HasValidConnectedness(dht.host, id)
return hasValidConnectedness(dht.host, id)
},
)

Expand All @@ -684,7 +684,7 @@ func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (pi peer.AddrInfo,

// Return peer information if we tried to dial the peer during the query or we are (or recently were) connected
// to the peer.
if dialedPeerDuringQuery || HasValidConnectedness(dht.host, id) {
if dialedPeerDuringQuery || hasValidConnectedness(dht.host, id) {
return dht.peerstore.PeerInfo(id), nil
}

Expand Down

0 comments on commit 08676fa

Please sign in to comment.