diff --git a/src/yggdrasil/debug.go b/src/yggdrasil/debug.go index 46bbd98..f6410b4 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 39f6170..aa8e53c 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) } }