mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 14:45:07 +03:00
Add API functions for manipulating maximum session MTU, fix TUN/TAP to use that
This commit is contained in:
parent
789307d52b
commit
e90be6f569
3 changed files with 24 additions and 3 deletions
|
@ -363,6 +363,22 @@ func (c *Core) SetNodeInfo(nodeinfo interface{}, nodeinfoprivacy bool) {
|
|||
c.router.nodeinfo.setNodeInfo(nodeinfo, nodeinfoprivacy)
|
||||
}
|
||||
|
||||
// GetMaximumSessionMTU returns the maximum allowed session MTU size.
|
||||
func (c *Core) GetMaximumSessionMTU(mtu uint16) uint16 {
|
||||
return c.router.sessions.myMaximumMTU
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// GetNodeInfo requests nodeinfo from a remote node, as specified by the public
|
||||
// key and coordinates specified. The third parameter specifies whether a cached
|
||||
// result is acceptable - this results in less traffic being generated than is
|
||||
|
|
|
@ -121,6 +121,7 @@ type sessions struct {
|
|||
lastCleanup time.Time
|
||||
isAllowedHandler func(pubkey *crypto.BoxPubKey, initiator bool) bool // Returns true or false if session setup is allowed
|
||||
isAllowedMutex sync.RWMutex // Protects the above
|
||||
myMaximumMTU uint16 // Maximum allowed session MTU
|
||||
permShared map[crypto.BoxPubKey]*crypto.BoxSharedKey // Maps known permanent keys to their shared key, used by DHT a lot
|
||||
sinfos map[crypto.Handle]*sessionInfo // Maps handle onto session info
|
||||
byTheirPerm map[crypto.BoxPubKey]*crypto.Handle // Maps theirPermPub onto handle
|
||||
|
@ -133,6 +134,7 @@ func (ss *sessions) init(r *router) {
|
|||
ss.sinfos = make(map[crypto.Handle]*sessionInfo)
|
||||
ss.byTheirPerm = make(map[crypto.BoxPubKey]*crypto.Handle)
|
||||
ss.lastCleanup = time.Now()
|
||||
ss.myMaximumMTU = 65535
|
||||
}
|
||||
|
||||
func (ss *sessions) reconfigure() {
|
||||
|
@ -187,9 +189,9 @@ func (ss *sessions) createSession(theirPermKey *crypto.BoxPubKey) *sessionInfo {
|
|||
sinfo.mySesPriv = *priv
|
||||
sinfo.myNonce = *crypto.NewBoxNonce()
|
||||
sinfo.theirMTU = 1280
|
||||
ss.router.core.config.Mutex.RLock()
|
||||
sinfo.myMTU = uint16(ss.router.core.config.Current.IfMTU)
|
||||
ss.router.core.config.Mutex.RUnlock()
|
||||
// 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
|
||||
sinfo.time = now
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue