Skip to content

Commit

Permalink
removing network.CanConnect
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumemichel committed Aug 7, 2024
1 parent c3f177f commit f7d06b1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 23 deletions.
6 changes: 2 additions & 4 deletions dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,12 +737,10 @@ 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()

switch dht.host.Network().Connectedness(id) {
case network.Connected, network.CanConnect:
if dht.host.Network().Connectedness(id) == network.Connected {
return dht.peerstore.PeerInfo(id)
default:
return peer.AddrInfo{}
}
return peer.AddrInfo{}
}

// nearestPeersToQuery returns the routing tables closest peers.
Expand Down
8 changes: 3 additions & 5 deletions fullrt/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,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.
connectedness := dht.h.Network().Connectedness(id)
if connectedness == network.Connected || connectedness == network.CanConnect {
if connectedness == network.Connected {
return dht.h.Peerstore().PeerInfo(id), nil
}

Expand Down Expand Up @@ -1538,12 +1538,10 @@ 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 {
switch dht.h.Network().Connectedness(id) {
case network.Connected, network.CanConnect:
if dht.h.Network().Connectedness(id) == network.Connected {
return dht.h.Peerstore().PeerInfo(id)
default:
return peer.AddrInfo{}
}
return peer.AddrInfo{}
}

func (dht *FullRT) maybeAddAddrs(p peer.ID, addrs []multiaddr.Multiaddr, ttl time.Duration) {
Expand Down
12 changes: 2 additions & 10 deletions pb/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ func RawPeerInfosToPBPeers(peers []peer.AddrInfo) []Message_Peer {
// information from the given network.Network.
func PeerInfosToPBPeers(n network.Network, peers []peer.AddrInfo) []Message_Peer {
pbps := RawPeerInfosToPBPeers(peers)
for i, pbp := range pbps {
for i := range pbps {
c := ConnectionType(n.Connectedness(peers[i].ID))
pbp.Connection = c
pbps[i].Connection = c
}
return pbps
}
Expand Down Expand Up @@ -146,10 +146,6 @@ func ConnectionType(c network.Connectedness) Message_ConnectionType {
return Message_NOT_CONNECTED
case network.Connected:
return Message_CONNECTED
case network.CanConnect:
return Message_CAN_CONNECT
case network.CannotConnect:
return Message_CANNOT_CONNECT
}
}

Expand All @@ -163,9 +159,5 @@ func Connectedness(c Message_ConnectionType) network.Connectedness {
return network.NotConnected
case Message_CONNECTED:
return network.Connected
case Message_CAN_CONNECT:
return network.CanConnect
case Message_CANNOT_CONNECT:
return network.CannotConnect
}
}
6 changes: 3 additions & 3 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestRTEvictionOnFailedQuery(t *testing.T) {
// peers should be in the RT because of fixLowPeers
require.NoError(t, tu.WaitFor(ctx, func() error {
if !checkRoutingTable(d1, d2) {
return fmt.Errorf("should have routes")
return fmt.Errorf("should have routes 0")
}
return nil
}))
Expand All @@ -45,7 +45,7 @@ func TestRTEvictionOnFailedQuery(t *testing.T) {
// peers will still be in the RT because we have decoupled membership from connectivity
require.NoError(t, tu.WaitFor(ctx, func() error {
if !checkRoutingTable(d1, d2) {
return fmt.Errorf("should have routes")
return fmt.Errorf("should have routes 1")
}
return nil
}))
Expand All @@ -59,7 +59,7 @@ func TestRTEvictionOnFailedQuery(t *testing.T) {

require.NoError(t, tu.WaitFor(ctx, func() error {
if checkRoutingTable(d1, d2) {
return fmt.Errorf("should not have routes")
return fmt.Errorf("should not have routes 2")
}
return nil
}))
Expand Down
2 changes: 1 addition & 1 deletion routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,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.
connectedness := dht.host.Network().Connectedness(id)
if dialedPeerDuringQuery || connectedness == network.Connected || connectedness == network.CanConnect {
if dialedPeerDuringQuery || connectedness == network.Connected {
return dht.peerstore.PeerInfo(id), nil
}

Expand Down

0 comments on commit f7d06b1

Please sign in to comment.