Skip to content

Agent Mesh

router: admit an authenticated peer router to the table on every pass

Antonio Ojea98ea016be551
diff --git a/internal/router/auth_gate_test.go b/internal/router/auth_gate_test.go
index 990d8045..68e8df1b 100644
--- a/internal/router/auth_gate_test.go
+++ b/internal/router/auth_gate_test.go
@@ -236,9 +236,15 @@ func TestRouterDHTServesAuthenticatedMembersAndTablesPeerRouters(t *testing.T) {
t.Fatal("a server-mode peer that never authenticated entered the routing table")
}
r.authenticatedPeers.Store(other.ID(), time.Now().Add(time.Hour))
- r.admitPeerRouter(other.ID())
- if kdht.RoutingTable().Find(other.ID()) == "" {
- t.Fatal("an authenticated peer router is not in the routing table")
+ // kad-dht handles the identify event on its own schedule and drops a
+ // peer its filter refused at that instant; the federation pass admits
+ // an authenticated router again on every tick, which this stands in for.
+ deadline := time.Now().Add(5 * time.Second)
+ for r.admitPeerRouter(other.ID()); kdht.RoutingTable().Find(other.ID()) == ""; r.admitPeerRouter(other.ID()) {
+ if time.Now().After(deadline) {
+ t.Fatal("an authenticated peer router is not in the routing table")
+ }
+ time.Sleep(20 * time.Millisecond)
}
r.forgetPeer(other.ID())
if kdht.RoutingTable().Find(other.ID()) != "" {
diff --git a/internal/router/router.go b/internal/router/router.go
index 1871bd70..cf3027be 100644
--- a/internal/router/router.go
+++ b/internal/router/router.go
@@ -1365,6 +1365,12 @@ func (r *Router) connectBootstrapRouters() {
r.peerRouters.Store(pi.ID, true)
r.Host.ConnManager().Protect(pi.ID, federationTag)
if r.isPeerAuthenticated(pi.ID) {
+ // Already admitted; make sure the table has it. kad-dht
+ // drops a peer its filter refused, and a router that
+ // authenticated while that was being decided would
+ // otherwise stay out of the table until it authenticated
+ // again.
+ r.admitPeerRouter(pi.ID)
continue
}
r.authenticatePeerRouter(*pi)