From 82fd43521143deec23d39022e05bd98789c63152 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Tue, 2 Jan 2018 18:45:09 -0600 Subject: [PATCH] Avoid sending unnecessairy udp key packets, and try config peers less often --- src/yggdrasil/debug.go | 7 +++++-- yggdrasil.go | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/yggdrasil/debug.go b/src/yggdrasil/debug.go index 46bbd98e..f6410b46 100644 --- a/src/yggdrasil/debug.go +++ b/src/yggdrasil/debug.go @@ -262,9 +262,12 @@ func (c *Core) DEBUG_getGlobalUDPAddr() net.Addr { return c.udp.sock.LocalAddr() } -func (c *Core) DEBUG_sendUDPKeys(saddr string) { +func (c *Core) DEBUG_maybeSendUDPKeys(saddr string) { addr := connAddr(saddr) - c.udp.sendKeys(addr) + c.udp.mutex.RLock() + _, isIn := c.udp.conns[connAddr(addr)] + c.udp.mutex.RUnlock() + if !isIn { c.udp.sendKeys(addr) } } //////////////////////////////////////////////////////////////////////////////// diff --git a/yggdrasil.go b/yggdrasil.go index 39f6170c..aa8e53c6 100644 --- a/yggdrasil.go +++ b/yggdrasil.go @@ -60,9 +60,10 @@ func (n *node) init(cfg *nodeConfig, logger *log.Logger) { if len(cfg.Peers) == 0 { return } for { for _, p := range cfg.Peers { - n.core.DEBUG_sendUDPKeys(p) + n.core.DEBUG_maybeSendUDPKeys(p) time.Sleep(time.Second) } + time.Sleep(time.Minute) } }() } @@ -112,7 +113,7 @@ func (n *node) listen() { saddr := addr.String() //if _, isIn := n.peers[saddr]; isIn { continue } //n.peers[saddr] = struct{}{} - n.core.DEBUG_sendUDPKeys(saddr) + n.core.DEBUG_maybeSendUDPKeys(saddr) //fmt.Println("DEBUG:", "added multicast peer:", saddr) } }