5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-12-22 14:05:41 +00:00

Avoid sending unnecessairy udp key packets, and try config peers less often

This commit is contained in:
Arceliar 2018-01-02 18:45:09 -06:00
parent c3e236b7fb
commit 82fd435211
2 changed files with 8 additions and 4 deletions

View File

@ -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) }
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -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)
}
}