From ee01db86c79b253e997824dede4fa7ee2be5e13e Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 21 Aug 2024 11:44:49 -0700 Subject: [PATCH] fix: Unexport hasValidConnectedness to make a patch release --- dht.go | 4 ++-- dht_filters.go | 2 +- fullrt/dht.go | 11 ++++++++--- routing.go | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/dht.go b/dht.go index 824c17e5..95f028ec 100644 --- a/dht.go +++ b/dht.go @@ -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{} @@ -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) diff --git a/dht_filters.go b/dht_filters.go index c56c3ca1..aa7c4799 100644 --- a/dht_filters.go +++ b/dht_filters.go @@ -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 } diff --git a/fullrt/dht.go b/fullrt/dht.go index 3383b27e..a630d995 100644 --- a/fullrt/dht.go +++ b/fullrt/dht.go @@ -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 } @@ -1537,7 +1537,7 @@ 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{} @@ -1545,8 +1545,13 @@ func (dht *FullRT) FindLocal(id peer.ID) 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 +} diff --git a/routing.go b/routing.go index bba9bdb1..1df05e1b 100644 --- a/routing.go +++ b/routing.go @@ -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) }, ) @@ -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 }