diff --git a/node/addrdiscovery.go b/node/addrdiscovery.go index f3a3666..160c7a0 100644 --- a/node/addrdiscovery.go +++ b/node/addrdiscovery.go @@ -26,6 +26,10 @@ func (store *pubAddrStore) Store(add netip.AddrPort) { return } + if !add.IsValid() { + return + } + if _, exists := store.lastSeen[add]; !exists { store.addrList = append(store.addrList, add) } diff --git a/node/globals.go b/node/globals.go index 9b465f1..b72acc4 100644 --- a/node/globals.go +++ b/node/globals.go @@ -68,7 +68,7 @@ var ( }() // Messages for the supervisor. - messages = make(chan any, 512) + messages = make(chan any, 1024) // Global routing table. routingTable [256]*atomic.Pointer[peerRoute] = func() (out [256]*atomic.Pointer[peerRoute]) { diff --git a/node/supervisor.go b/node/supervisor.go index 9d89ee4..9ecc1ec 100644 --- a/node/supervisor.go +++ b/node/supervisor.go @@ -102,6 +102,8 @@ type peerStateData struct { // For logging. Set per-state. client bool + // We rate limit per remote endpoint because if we don't we tend to lose + // packets. limiter *ratelimiter.Limiter } @@ -142,21 +144,21 @@ func (s *peerStateData) logf(format string, args ...any) { b.WriteString(fmt.Sprintf("%30s: ", s.peer.Name)) if s.client { - b.WriteString("CLIENT|") + b.WriteString("CLIENT | ") } else { - b.WriteString("SERVER|") + b.WriteString("SERVER | ") } if s.staged.Direct { - b.WriteString("DIRECT |") + b.WriteString("DIRECT | ") } else { - b.WriteString("RELAYED|") + b.WriteString("RELAYED | ") } if s.staged.Up { - b.WriteString("UP |") + b.WriteString("UP | ") } else { - b.WriteString("DOWN|") + b.WriteString("DOWN | ") } log.Printf(b.String()+format, args...) @@ -270,9 +272,10 @@ func (s *stateServer) OnSyn(msg controlMsg[synPacket]) { // Not direct => send probes. for _, addr := range p.PossibleAddrs { - if addr.IsValid() { - s.sendControlPacketTo(probePacket{TraceID: newTraceID()}, addr) + if !addr.IsValid() { + break } + s.sendControlPacketTo(probePacket{TraceID: newTraceID()}, addr) } } @@ -410,11 +413,11 @@ func (s *stateClient) OnPingTimer() peerState { } clear(s.probes) - for _, ip := range publicAddrs.Get() { - if !ip.IsValid() { + for _, addr := range s.ack.PossibleAddrs { + if !addr.IsValid() { break } - s.sendProbeTo(ip) + s.sendProbeTo(addr) } select {