From 2925920c703a3a743346d241097513952c80d979 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 29 Dec 2018 19:53:31 +0000 Subject: [PATCH] Use mutex in switch/tcp init --- src/yggdrasil/switch.go | 2 ++ src/yggdrasil/tcp.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index f3c95122..10c9563d 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -186,7 +186,9 @@ func (t *switchTable) init(core *Core) { now := time.Now() t.core = core t.reconfigure = make(chan bool, 1) + t.core.configMutex.RLock() t.key = t.core.sigPub + t.core.configMutex.RUnlock() locator := switchLocator{root: t.key, tstamp: now.Unix()} peers := make(map[switchPort]peerInfo) t.data = switchData{locator: locator, peers: peers} diff --git a/src/yggdrasil/tcp.go b/src/yggdrasil/tcp.go index c986dc62..ad50d780 100644 --- a/src/yggdrasil/tcp.go +++ b/src/yggdrasil/tcp.go @@ -83,8 +83,10 @@ func (iface *tcpInterface) connectSOCKS(socksaddr, peeraddr string) { // Initializes the struct. func (iface *tcpInterface) init(core *Core) (err error) { iface.core = core + iface.core.configMutex.RLock() iface.tcp_addr = iface.core.config.Listen iface.tcp_timeout = time.Duration(iface.core.config.ReadTimeout) * time.Millisecond + iface.core.configMutex.RUnlock() if iface.tcp_timeout >= 0 && iface.tcp_timeout < default_tcp_timeout { iface.tcp_timeout = default_tcp_timeout }