From f35b8c3ead116771268d49cbc8b47c481c59d7db Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 21 Aug 2021 19:50:50 -0700 Subject: [PATCH] derp: fix meshing accounting edge case bug If a peer is connected to multiple nodes in a region (so multiForwarder is in use) and then a node restarts and re-sends all its additions, this bug about whether an element is in the multiForwarder could cause a one-time flip in the which peer node we forward to. Note a huge deal, but not written as intended. Thanks to @lewgun for the bug report in #2141. Signed-off-by: Brad Fitzpatrick --- derp/derp_server.go | 2 +- derp/derp_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/derp/derp_server.go b/derp/derp_server.go index f85f195a4..30402a332 100644 --- a/derp/derp_server.go +++ b/derp/derp_server.go @@ -1275,7 +1275,7 @@ func (s *Server) AddPacketForwarder(dst key.Public, fwd PacketForwarder) { return } if m, ok := prev.(multiForwarder); ok { - if _, ok := m[fwd]; !ok { + if _, ok := m[fwd]; ok { // Duplicate registration of same forwarder in set; ignore. return } diff --git a/derp/derp_test.go b/derp/derp_test.go index d8dfa714b..1aa45363b 100644 --- a/derp/derp_test.go +++ b/derp/derp_test.go @@ -712,6 +712,7 @@ func TestForwarderRegistration(t *testing.T) { // Adding a dup for a user. wantCounter(&s.multiForwarderCreated, 0) s.AddPacketForwarder(u1, testFwd(100)) + s.AddPacketForwarder(u1, testFwd(100)) // dup to trigger dup path want(map[key.Public]PacketForwarder{ u1: multiForwarder{ testFwd(1): 1,