mirror of
https://github.com/fluencelabs/go-libp2p-kad-dht
synced 2025-04-24 14:22:13 +00:00
revert removal of 'peerFound' function
This commit is contained in:
parent
90907b584c
commit
2fc9c2ac33
7
dht.go
7
dht.go
@ -403,6 +403,13 @@ func (dht *IpfsDHT) putLocal(key string, rec *recpb.Record) error {
|
||||
return dht.datastore.Put(mkDsKey(key), data)
|
||||
}
|
||||
|
||||
// peerFound signals the routingTable that we've found a peer that
|
||||
// supports the DHT protocol.
|
||||
func (dht *IpfsDHT) peerFound(ctx context.Context, p peer.ID) {
|
||||
logger.Event(ctx, "peerFound", p)
|
||||
dht.routingTable.HandlePeerAlive(p)
|
||||
}
|
||||
|
||||
// peerStoppedDHT signals the routing table that a peer has stopped supporting the DHT protocol.
|
||||
func (dht *IpfsDHT) peerStoppedDHT(ctx context.Context, p peer.ID) {
|
||||
logger.Event(ctx, "peerStoppedDHT", p)
|
||||
|
@ -40,7 +40,7 @@ func TestHungRequest(t *testing.T) {
|
||||
defer s.Reset()
|
||||
<-ctx.Done()
|
||||
})
|
||||
d.routingTable.HandlePeerAlive(hosts[1].ID())
|
||||
d.peerFound(ctx, hosts[1].ID())
|
||||
|
||||
ctx1, cancel1 := context.WithTimeout(ctx, 1*time.Second)
|
||||
defer cancel1()
|
||||
@ -214,7 +214,7 @@ func TestNotFound(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, p := range hosts {
|
||||
d.routingTable.HandlePeerAlive(p.ID())
|
||||
d.peerFound(ctx, p.ID())
|
||||
}
|
||||
|
||||
// Reply with random peers to every message
|
||||
@ -294,7 +294,7 @@ func TestLessThanKResponses(t *testing.T) {
|
||||
}
|
||||
|
||||
for i := 1; i < 5; i++ {
|
||||
d.routingTable.HandlePeerAlive(hosts[i].ID())
|
||||
d.peerFound(ctx, hosts[i].ID())
|
||||
}
|
||||
|
||||
// Reply with random peers to every message
|
||||
@ -363,7 +363,7 @@ func TestMultipleQueries(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
d.routingTable.HandlePeerAlive(hosts[1].ID())
|
||||
d.peerFound(ctx, hosts[1].ID())
|
||||
|
||||
// It would be nice to be able to just get a value and succeed but then
|
||||
// we'd need to deal with selectors and validators...
|
||||
|
@ -89,7 +89,7 @@ func BenchmarkHandleFindPeer(b *testing.B) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
d.routingTable.HandlePeerAlive(id)
|
||||
d.peerFound(ctx, id)
|
||||
|
||||
peers = append(peers, id)
|
||||
a, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", 2000+i))
|
||||
|
@ -66,7 +66,7 @@ func newSubscriberNotifiee(dht *IpfsDHT) (*subscriberNotifee, error) {
|
||||
return nil, fmt.Errorf("could not check peerstore for protocol support: err: %s", err)
|
||||
}
|
||||
if valid {
|
||||
dht.routingTable.HandlePeerAlive(p)
|
||||
dht.peerFound(dht.ctx, p)
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ func handlePeerIdentificationCompletedEvent(dht *IpfsDHT, e event.EvtPeerIdentif
|
||||
return
|
||||
}
|
||||
if valid {
|
||||
dht.routingTable.HandlePeerAlive(e.Peer)
|
||||
dht.peerFound(dht.ctx, e.Peer)
|
||||
fixLowPeers(dht)
|
||||
}
|
||||
}
|
||||
@ -144,7 +144,7 @@ func handlePeerProtocolsUpdatedEvent(dht *IpfsDHT, e event.EvtPeerProtocolsUpdat
|
||||
}
|
||||
|
||||
if valid {
|
||||
dht.routingTable.HandlePeerAlive(e.Peer)
|
||||
dht.peerFound(dht.ctx, e.Peer)
|
||||
} else {
|
||||
dht.peerStoppedDHT(dht.ctx, e.Peer)
|
||||
}
|
||||
@ -201,7 +201,7 @@ func fixLowPeers(dht *IpfsDHT) {
|
||||
// Don't bother probing, we do that on connect.
|
||||
valid, _ := dht.validRTPeer(p)
|
||||
if valid {
|
||||
dht.routingTable.HandlePeerAlive(p)
|
||||
dht.peerFound(dht.Context(), p)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user