5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 15:21:37 +00:00

Remove unnecessary selects

This commit is contained in:
Neil Alexander 2019-01-15 08:51:19 +00:00
parent 39567bed83
commit 2cd373fc1e
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
8 changed files with 52 additions and 68 deletions

View File

@ -57,17 +57,15 @@ func (a *admin) init(c *Core) {
a.reconfigure = make(chan chan error, 1) a.reconfigure = make(chan chan error, 1)
go func() { go func() {
for { for {
select { e := <-a.reconfigure
case e := <-a.reconfigure: a.core.configMutex.RLock()
a.core.configMutex.RLock() if a.core.config.AdminListen != a.core.configOld.AdminListen {
if a.core.config.AdminListen != a.core.configOld.AdminListen { a.listenaddr = a.core.config.AdminListen
a.listenaddr = a.core.config.AdminListen a.close()
a.close() a.start()
a.start()
}
a.core.configMutex.RUnlock()
e <- nil
} }
a.core.configMutex.RUnlock()
e <- nil
} }
}() }()
a.core.configMutex.RLock() a.core.configMutex.RLock()

View File

@ -82,10 +82,8 @@ func (t *dht) init(c *Core) {
t.reconfigure = make(chan chan error, 1) t.reconfigure = make(chan chan error, 1)
go func() { go func() {
for { for {
select { e := <-t.reconfigure
case e := <-t.reconfigure: e <- nil
e <- nil
}
} }
}() }()
t.nodeID = *t.core.GetNodeID() t.nodeID = *t.core.GetNodeID()

View File

@ -25,13 +25,11 @@ func (m *multicast) init(core *Core) {
m.reconfigure = make(chan chan error, 1) m.reconfigure = make(chan chan error, 1)
go func() { go func() {
for { for {
select { e := <-m.reconfigure
case e := <-m.reconfigure: m.myAddrMutex.Lock()
m.myAddrMutex.Lock() m.myAddr = m.core.tcp.getAddr()
m.myAddr = m.core.tcp.getAddr() m.myAddrMutex.Unlock()
m.myAddrMutex.Unlock() e <- nil
e <- nil
}
} }
}() }()
m.groupAddr = "[ff02::114]:9001" m.groupAddr = "[ff02::114]:9001"

View File

@ -35,10 +35,8 @@ func (ps *peers) init(c *Core) {
ps.reconfigure = make(chan chan error, 1) ps.reconfigure = make(chan chan error, 1)
go func() { go func() {
for { for {
select { e := <-ps.reconfigure
case e := <-ps.reconfigure: e <- nil
e <- nil
}
} }
}() }()
ps.allowedEncryptionPublicKeys = make(map[crypto.BoxPubKey]struct{}) ps.allowedEncryptionPublicKeys = make(map[crypto.BoxPubKey]struct{})

View File

@ -53,10 +53,8 @@ func (s *searches) init(core *Core) {
s.reconfigure = make(chan chan error, 1) s.reconfigure = make(chan chan error, 1)
go func() { go func() {
for { for {
select { e := <-s.reconfigure
case e := <-s.reconfigure: e <- nil
e <- nil
}
} }
}() }()
s.searches = make(map[crypto.NodeID]*searchInfo) s.searches = make(map[crypto.NodeID]*searchInfo)

View File

@ -131,21 +131,19 @@ func (ss *sessions) init(core *Core) {
ss.reconfigure = make(chan chan error, 1) ss.reconfigure = make(chan chan error, 1)
go func() { go func() {
for { for {
select { e := <-ss.reconfigure
case e := <-ss.reconfigure: responses := make(map[crypto.Handle]chan error)
responses := make(map[crypto.Handle]chan error) for index, session := range ss.sinfos {
for index, session := range ss.sinfos { responses[index] = make(chan error)
responses[index] = make(chan error) session.reconfigure <- responses[index]
session.reconfigure <- responses[index]
}
for _, response := range responses {
if err := <-response; err != nil {
e <- err
continue
}
}
e <- nil
} }
for _, response := range responses {
if err := <-response; err != nil {
e <- err
continue
}
}
e <- nil
} }
}() }()
ss.permShared = make(map[crypto.BoxPubKey]*crypto.BoxSharedKey) ss.permShared = make(map[crypto.BoxPubKey]*crypto.BoxSharedKey)

View File

@ -90,18 +90,16 @@ func (iface *tcpInterface) init(core *Core) (err error) {
iface.reconfigure = make(chan chan error, 1) iface.reconfigure = make(chan chan error, 1)
go func() { go func() {
for { for {
select { e := <-iface.reconfigure
case e := <-iface.reconfigure: iface.core.configMutex.RLock()
iface.core.configMutex.RLock() updated := iface.core.config.Listen != iface.core.configOld.Listen
updated := iface.core.config.Listen != iface.core.configOld.Listen iface.core.configMutex.RUnlock()
iface.core.configMutex.RUnlock() if updated {
if updated { iface.serv_stop <- true
iface.serv_stop <- true iface.serv.Close()
iface.serv.Close() e <- iface.listen()
e <- iface.listen() } else {
} else { e <- nil
e <- nil
}
} }
} }
}() }()

View File

@ -46,19 +46,17 @@ func (tun *tunAdapter) init(core *Core, send chan<- []byte, recv <-chan []byte)
tun.icmpv6.init(tun) tun.icmpv6.init(tun)
go func() { go func() {
for { for {
select { e := <-tun.reconfigure
case e := <-tun.reconfigure: tun.core.configMutex.RLock()
tun.core.configMutex.RLock() updated := tun.core.config.IfName != tun.core.configOld.IfName ||
updated := tun.core.config.IfName != tun.core.configOld.IfName || tun.core.config.IfTAPMode != tun.core.configOld.IfTAPMode ||
tun.core.config.IfTAPMode != tun.core.configOld.IfTAPMode || tun.core.config.IfMTU != tun.core.configOld.IfMTU
tun.core.config.IfMTU != tun.core.configOld.IfMTU tun.core.configMutex.RUnlock()
tun.core.configMutex.RUnlock() if updated {
if updated { tun.core.log.Println("Reconfiguring TUN/TAP is not supported yet")
tun.core.log.Println("Reconfiguring TUN/TAP is not supported yet") e <- nil
e <- nil } else {
} else { e <- nil
e <- nil
}
} }
} }
}() }()