From 2cd373fc1e41a115299dc8f56bd2d4e6b0b40ab6 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 15 Jan 2019 08:51:19 +0000 Subject: [PATCH] Remove unnecessary selects --- src/yggdrasil/admin.go | 18 ++++++++---------- src/yggdrasil/dht.go | 6 ++---- src/yggdrasil/multicast.go | 12 +++++------- src/yggdrasil/peer.go | 6 ++---- src/yggdrasil/search.go | 6 ++---- src/yggdrasil/session.go | 26 ++++++++++++-------------- src/yggdrasil/tcp.go | 22 ++++++++++------------ src/yggdrasil/tun.go | 24 +++++++++++------------- 8 files changed, 52 insertions(+), 68 deletions(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index db85629..5524fe2 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -57,17 +57,15 @@ func (a *admin) init(c *Core) { a.reconfigure = make(chan chan error, 1) go func() { for { - select { - case e := <-a.reconfigure: - a.core.configMutex.RLock() - if a.core.config.AdminListen != a.core.configOld.AdminListen { - a.listenaddr = a.core.config.AdminListen - a.close() - a.start() - } - a.core.configMutex.RUnlock() - e <- nil + e := <-a.reconfigure + a.core.configMutex.RLock() + if a.core.config.AdminListen != a.core.configOld.AdminListen { + a.listenaddr = a.core.config.AdminListen + a.close() + a.start() } + a.core.configMutex.RUnlock() + e <- nil } }() a.core.configMutex.RLock() diff --git a/src/yggdrasil/dht.go b/src/yggdrasil/dht.go index bba6dfc..5427aca 100644 --- a/src/yggdrasil/dht.go +++ b/src/yggdrasil/dht.go @@ -82,10 +82,8 @@ func (t *dht) init(c *Core) { t.reconfigure = make(chan chan error, 1) go func() { for { - select { - case e := <-t.reconfigure: - e <- nil - } + e := <-t.reconfigure + e <- nil } }() t.nodeID = *t.core.GetNodeID() diff --git a/src/yggdrasil/multicast.go b/src/yggdrasil/multicast.go index 4087895..08f0954 100644 --- a/src/yggdrasil/multicast.go +++ b/src/yggdrasil/multicast.go @@ -25,13 +25,11 @@ func (m *multicast) init(core *Core) { m.reconfigure = make(chan chan error, 1) go func() { for { - select { - case e := <-m.reconfigure: - m.myAddrMutex.Lock() - m.myAddr = m.core.tcp.getAddr() - m.myAddrMutex.Unlock() - e <- nil - } + e := <-m.reconfigure + m.myAddrMutex.Lock() + m.myAddr = m.core.tcp.getAddr() + m.myAddrMutex.Unlock() + e <- nil } }() m.groupAddr = "[ff02::114]:9001" diff --git a/src/yggdrasil/peer.go b/src/yggdrasil/peer.go index 98cbe02..c83504f 100644 --- a/src/yggdrasil/peer.go +++ b/src/yggdrasil/peer.go @@ -35,10 +35,8 @@ func (ps *peers) init(c *Core) { ps.reconfigure = make(chan chan error, 1) go func() { for { - select { - case e := <-ps.reconfigure: - e <- nil - } + e := <-ps.reconfigure + e <- nil } }() ps.allowedEncryptionPublicKeys = make(map[crypto.BoxPubKey]struct{}) diff --git a/src/yggdrasil/search.go b/src/yggdrasil/search.go index 8106fb7..c391dda 100644 --- a/src/yggdrasil/search.go +++ b/src/yggdrasil/search.go @@ -53,10 +53,8 @@ func (s *searches) init(core *Core) { s.reconfigure = make(chan chan error, 1) go func() { for { - select { - case e := <-s.reconfigure: - e <- nil - } + e := <-s.reconfigure + e <- nil } }() s.searches = make(map[crypto.NodeID]*searchInfo) diff --git a/src/yggdrasil/session.go b/src/yggdrasil/session.go index 3cd1cf7..e29cd4f 100644 --- a/src/yggdrasil/session.go +++ b/src/yggdrasil/session.go @@ -131,21 +131,19 @@ func (ss *sessions) init(core *Core) { ss.reconfigure = make(chan chan error, 1) go func() { for { - select { - case e := <-ss.reconfigure: - responses := make(map[crypto.Handle]chan error) - for index, session := range ss.sinfos { - responses[index] = make(chan error) - session.reconfigure <- responses[index] - } - for _, response := range responses { - if err := <-response; err != nil { - e <- err - continue - } - } - e <- nil + e := <-ss.reconfigure + responses := make(map[crypto.Handle]chan error) + for index, session := range ss.sinfos { + responses[index] = make(chan error) + session.reconfigure <- responses[index] } + for _, response := range responses { + if err := <-response; err != nil { + e <- err + continue + } + } + e <- nil } }() ss.permShared = make(map[crypto.BoxPubKey]*crypto.BoxSharedKey) diff --git a/src/yggdrasil/tcp.go b/src/yggdrasil/tcp.go index b47b553..9cab9ea 100644 --- a/src/yggdrasil/tcp.go +++ b/src/yggdrasil/tcp.go @@ -90,18 +90,16 @@ func (iface *tcpInterface) init(core *Core) (err error) { iface.reconfigure = make(chan chan error, 1) go func() { for { - select { - case e := <-iface.reconfigure: - iface.core.configMutex.RLock() - updated := iface.core.config.Listen != iface.core.configOld.Listen - iface.core.configMutex.RUnlock() - if updated { - iface.serv_stop <- true - iface.serv.Close() - e <- iface.listen() - } else { - e <- nil - } + e := <-iface.reconfigure + iface.core.configMutex.RLock() + updated := iface.core.config.Listen != iface.core.configOld.Listen + iface.core.configMutex.RUnlock() + if updated { + iface.serv_stop <- true + iface.serv.Close() + e <- iface.listen() + } else { + e <- nil } } }() diff --git a/src/yggdrasil/tun.go b/src/yggdrasil/tun.go index 46fabbc..c0a7139 100644 --- a/src/yggdrasil/tun.go +++ b/src/yggdrasil/tun.go @@ -46,19 +46,17 @@ func (tun *tunAdapter) init(core *Core, send chan<- []byte, recv <-chan []byte) tun.icmpv6.init(tun) go func() { for { - select { - case e := <-tun.reconfigure: - tun.core.configMutex.RLock() - updated := tun.core.config.IfName != tun.core.configOld.IfName || - tun.core.config.IfTAPMode != tun.core.configOld.IfTAPMode || - tun.core.config.IfMTU != tun.core.configOld.IfMTU - tun.core.configMutex.RUnlock() - if updated { - tun.core.log.Println("Reconfiguring TUN/TAP is not supported yet") - e <- nil - } else { - e <- nil - } + e := <-tun.reconfigure + tun.core.configMutex.RLock() + updated := tun.core.config.IfName != tun.core.configOld.IfName || + tun.core.config.IfTAPMode != tun.core.configOld.IfTAPMode || + tun.core.config.IfMTU != tun.core.configOld.IfMTU + tun.core.configMutex.RUnlock() + if updated { + tun.core.log.Println("Reconfiguring TUN/TAP is not supported yet") + e <- nil + } else { + e <- nil } } }()