5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 17:40:26 +00:00

Thread safety for MTU API functions

This commit is contained in:
Neil Alexander 2019-11-21 09:28:36 +00:00
parent e90be6f569
commit d1c445dc41
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
2 changed files with 11 additions and 12 deletions

View File

@ -365,18 +365,19 @@ func (c *Core) SetNodeInfo(nodeinfo interface{}, nodeinfoprivacy bool) {
// GetMaximumSessionMTU returns the maximum allowed session MTU size. // GetMaximumSessionMTU returns the maximum allowed session MTU size.
func (c *Core) GetMaximumSessionMTU(mtu uint16) uint16 { 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 // SetMaximumSessionMTU sets the maximum allowed session MTU size. The default
// value contains the actual set value, since Yggdrasil will not accept MTUs // value is 65535 bytes.
// below 1280 bytes. The default value is 65535 bytes. func (c *Core) SetMaximumSessionMTU(mtu uint16) {
func (c *Core) SetMaximumSessionMTU(mtu uint16) uint16 { phony.Block(c.router, func() {
if mtu < 1280 { c.router.sessions.myMaximumMTU = mtu
mtu = 1280 })
}
c.router.sessions.myMaximumMTU = mtu
return mtu
} }
// GetNodeInfo requests nodeinfo from a remote node, as specified by the public // GetNodeInfo requests nodeinfo from a remote node, as specified by the public

View File

@ -189,8 +189,6 @@ func (ss *sessions) createSession(theirPermKey *crypto.BoxPubKey) *sessionInfo {
sinfo.mySesPriv = *priv sinfo.mySesPriv = *priv
sinfo.myNonce = *crypto.NewBoxNonce() sinfo.myNonce = *crypto.NewBoxNonce()
sinfo.theirMTU = 1280 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 sinfo.myMTU = ss.myMaximumMTU
now := time.Now() now := time.Now()
sinfo.timeOpened = now sinfo.timeOpened = now