From d1c445dc41837d5f3c85d37acc8d693a9f4df279 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 21 Nov 2019 09:28:36 +0000 Subject: [PATCH] Thread safety for MTU API functions --- src/yggdrasil/api.go | 21 +++++++++++---------- src/yggdrasil/session.go | 2 -- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/yggdrasil/api.go b/src/yggdrasil/api.go index 59cc8310..e6b32e68 100644 --- a/src/yggdrasil/api.go +++ b/src/yggdrasil/api.go @@ -365,18 +365,19 @@ func (c *Core) SetNodeInfo(nodeinfo interface{}, nodeinfoprivacy bool) { // GetMaximumSessionMTU returns the maximum allowed session MTU size. func (c *Core) GetMaximumSessionMTU(mtu uint16) uint16 { - return c.router.sessions.myMaximumMTU + mtu := 0 + phony.Block(c.router, func() { + mtu = c.router.sessions.myMaximumMTU + }) + return mtu } -// SetMaximumSessionMTU sets the maximum allowed session MTU size. The return -// value contains the actual set value, since Yggdrasil will not accept MTUs -// below 1280 bytes. The default value is 65535 bytes. -func (c *Core) SetMaximumSessionMTU(mtu uint16) uint16 { - if mtu < 1280 { - mtu = 1280 - } - c.router.sessions.myMaximumMTU = mtu - return mtu +// SetMaximumSessionMTU sets the maximum allowed session MTU size. The default +// value is 65535 bytes. +func (c *Core) SetMaximumSessionMTU(mtu uint16) { + phony.Block(c.router, func() { + c.router.sessions.myMaximumMTU = mtu + }) } // GetNodeInfo requests nodeinfo from a remote node, as specified by the public diff --git a/src/yggdrasil/session.go b/src/yggdrasil/session.go index b287377a..78b0a3b2 100644 --- a/src/yggdrasil/session.go +++ b/src/yggdrasil/session.go @@ -189,8 +189,6 @@ func (ss *sessions) createSession(theirPermKey *crypto.BoxPubKey) *sessionInfo { sinfo.mySesPriv = *priv sinfo.myNonce = *crypto.NewBoxNonce() sinfo.theirMTU = 1280 - // TODO: sinfo.myMTU becomes unnecessary if we always have a reference to the - // sessions struct so let's check if that is the case sinfo.myMTU = ss.myMaximumMTU now := time.Now() sinfo.timeOpened = now