Skip to content

Agent Mesh

Inline the revoked-peer check in the discovery loop

Tomas Tormo78c000f34f93
diff --git a/internal/node/node.go b/internal/node/node.go
index 525dd8e9..57152ed6 100644
--- a/internal/node/node.go
+++ b/internal/node/node.go
@@ -1536,7 +1536,9 @@ func (n *SamNode) startDiscovery(ctx context.Context, meshID string, interval ti
continue
}
for p := range peers {
- if !n.shouldDialDiscovered(p.ID) {
+ // Revoked peers keep advertising the mesh rendezvous, so without
+ // this every tick re-dials them and the gater denies it.
+ if p.ID == n.Host.ID() || n.peerIsRevoked(p.ID) {
continue
}
@@ -1575,13 +1577,6 @@ func (n *SamNode) startDiscovery(ctx context.Context, meshID string, interval ti
}
}
-// shouldDialDiscovered filters the DHT discovery results. Revoked peers keep
-// advertising the mesh rendezvous, so without this every tick re-dials them
-// and the connection gater denies it.
-func (n *SamNode) shouldDialDiscovered(p peer.ID) bool {
- return p != n.Host.ID() && !n.peerIsRevoked(p)
-}
-
// awaitRoutingTable blocks until the DHT routing table has a peer, ctx ends
// or bound elapses. DHT.Bootstrap only triggers a refresh: the router enters
// the table after an asynchronous FIND_NODE liveliness check that nothing
@@ -1753,7 +1748,7 @@ func (n *SamNode) findProvidersByCID(ctx context.Context, c cid.Cid) ([]peer.Add
}
providers := make([]peer.AddrInfo, 0, len(providersMap))
for _, p := range providersMap {
- // Same reason as shouldDialDiscovered: a revoked peer's provider
+ // Same reason as the discovery loop: a revoked peer's provider
// record outlives its ban, so without this every service lookup
// fans out a doomed dial and returns one fewer usable provider.
if n.peerIsRevoked(p.ID) {
diff --git a/internal/node/node_test.go b/internal/node/node_test.go
index 997560cf..2352db3f 100644
--- a/internal/node/node_test.go
+++ b/internal/node/node_test.go
@@ -761,46 +761,3 @@ func TestNewSamNode_DHTOptions(t *testing.T) {
t.Errorf("expected DiscoveryConcurrency to be 5, got %d", node.config.DiscoveryConcurrency)
}
}
-
-func TestShouldDialDiscovered(t *testing.T) {
- host, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0"))
- if err != nil {
- t.Fatal(err)
- }
- defer func() { _ = host.Close() }()
-
- revokedCache, err := lru.New[string, int64](10)
- if err != nil {
- t.Fatal(err)
- }
- node := &SamNode{Host: host, revokedPeers: revokedCache}
-
- _, revokedPub, err := crypto.GenerateEd25519Key(nil)
- if err != nil {
- t.Fatal(err)
- }
- revoked, err := peer.IDFromPublicKey(revokedPub)
- if err != nil {
- t.Fatal(err)
- }
- node.revokedPeers.Add(revoked.String(), time.Now().UnixMilli())
-
- _, healthyPub, err := crypto.GenerateEd25519Key(nil)
- if err != nil {
- t.Fatal(err)
- }
- healthy, err := peer.IDFromPublicKey(healthyPub)
- if err != nil {
- t.Fatal(err)
- }
-
- if node.shouldDialDiscovered(revoked) {
- t.Error("revoked peer should not be dialled from DHT discovery")
- }
- if node.shouldDialDiscovered(host.ID()) {
- t.Error("self should not be dialled from DHT discovery")
- }
- if !node.shouldDialDiscovered(healthy) {
- t.Error("healthy peer should be dialled from DHT discovery")
- }
-}