mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 01:21:37 +00:00
Try to exchange MTUs when creating sessions
This commit is contained in:
parent
38567fffef
commit
536974f20c
@ -223,6 +223,7 @@ func (a *admin) getData_getSessions() []admin_nodeInfo {
|
|||||||
info := admin_nodeInfo{
|
info := admin_nodeInfo{
|
||||||
{"IP", net.IP(sinfo.theirAddr[:]).String()},
|
{"IP", net.IP(sinfo.theirAddr[:]).String()},
|
||||||
{"coords", fmt.Sprint(sinfo.coords)},
|
{"coords", fmt.Sprint(sinfo.coords)},
|
||||||
|
{"MTU", fmt.Sprint(sinfo.getMTU())},
|
||||||
}
|
}
|
||||||
infos = append(infos, info)
|
infos = append(infos, info)
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ package yggdrasil
|
|||||||
// The session information consists of crypto keys and coords
|
// The session information consists of crypto keys and coords
|
||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
import "net"
|
||||||
|
|
||||||
type sessionInfo struct {
|
type sessionInfo struct {
|
||||||
core *Core
|
core *Core
|
||||||
@ -19,6 +20,8 @@ type sessionInfo struct {
|
|||||||
myHandle handle
|
myHandle handle
|
||||||
theirNonce boxNonce
|
theirNonce boxNonce
|
||||||
myNonce boxNonce
|
myNonce boxNonce
|
||||||
|
theirMTU uint16
|
||||||
|
myMTU uint16
|
||||||
time time.Time // Time we last received a packet
|
time time.Time // Time we last received a packet
|
||||||
coords []byte // coords of destination
|
coords []byte // coords of destination
|
||||||
packet []byte // a buffered packet, sent immediately on ping/pong
|
packet []byte // a buffered packet, sent immediately on ping/pong
|
||||||
@ -36,6 +39,7 @@ type sessionPing struct {
|
|||||||
coords []byte
|
coords []byte
|
||||||
tstamp int64 // unix time, but the only real requirement is that it increases
|
tstamp int64 // unix time, but the only real requirement is that it increases
|
||||||
isPong bool
|
isPong bool
|
||||||
|
mtu uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the session was updated, false otherwise
|
// Returns true if the session was updated, false otherwise
|
||||||
@ -56,6 +60,10 @@ func (s *sessionInfo) update(p *sessionPing) bool {
|
|||||||
s.theirNonce = boxNonce{}
|
s.theirNonce = boxNonce{}
|
||||||
s.nonceMask = 0
|
s.nonceMask = 0
|
||||||
}
|
}
|
||||||
|
s.core.log.Printf("Received MTU %d from %s", p.mtu, net.IP(s.theirAddr[:]).String())
|
||||||
|
if p.mtu >= 1280 {
|
||||||
|
s.theirMTU = p.mtu
|
||||||
|
}
|
||||||
s.coords = append([]byte{}, p.coords...)
|
s.coords = append([]byte{}, p.coords...)
|
||||||
s.time = time.Now()
|
s.time = time.Now()
|
||||||
s.tstamp = p.tstamp
|
s.tstamp = p.tstamp
|
||||||
@ -144,6 +152,8 @@ func (ss *sessions) createSession(theirPermKey *boxPubKey) *sessionInfo {
|
|||||||
sinfo.mySesPub = *pub
|
sinfo.mySesPub = *pub
|
||||||
sinfo.mySesPriv = *priv
|
sinfo.mySesPriv = *priv
|
||||||
sinfo.myNonce = *newBoxNonce()
|
sinfo.myNonce = *newBoxNonce()
|
||||||
|
sinfo.theirMTU = 1280
|
||||||
|
sinfo.myMTU = uint16(ss.core.tun.mtu)
|
||||||
higher := false
|
higher := false
|
||||||
for idx := range ss.core.boxPub {
|
for idx := range ss.core.boxPub {
|
||||||
if ss.core.boxPub[idx] > sinfo.theirPermPub[idx] {
|
if ss.core.boxPub[idx] > sinfo.theirPermPub[idx] {
|
||||||
@ -195,12 +205,14 @@ func (sinfo *sessionInfo) close() {
|
|||||||
func (ss *sessions) getPing(sinfo *sessionInfo) sessionPing {
|
func (ss *sessions) getPing(sinfo *sessionInfo) sessionPing {
|
||||||
loc := ss.core.switchTable.getLocator()
|
loc := ss.core.switchTable.getLocator()
|
||||||
coords := loc.getCoords()
|
coords := loc.getCoords()
|
||||||
|
sinfo.core.log.Printf("Sending MTU %d to %s", sinfo.myMTU, net.IP(sinfo.theirAddr[:]).String())
|
||||||
ref := sessionPing{
|
ref := sessionPing{
|
||||||
sendPermPub: ss.core.boxPub,
|
sendPermPub: ss.core.boxPub,
|
||||||
handle: sinfo.myHandle,
|
handle: sinfo.myHandle,
|
||||||
sendSesPub: sinfo.mySesPub,
|
sendSesPub: sinfo.mySesPub,
|
||||||
tstamp: time.Now().Unix(),
|
tstamp: time.Now().Unix(),
|
||||||
coords: coords,
|
coords: coords,
|
||||||
|
mtu: sinfo.myMTU,
|
||||||
}
|
}
|
||||||
sinfo.myNonce.update()
|
sinfo.myNonce.update()
|
||||||
return ref
|
return ref
|
||||||
@ -289,6 +301,13 @@ func (n *boxNonce) minus(m *boxNonce) int64 {
|
|||||||
return diff
|
return diff
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sinfo *sessionInfo) getMTU() uint16 {
|
||||||
|
if sinfo.theirMTU < sinfo.myMTU {
|
||||||
|
return sinfo.theirMTU
|
||||||
|
}
|
||||||
|
return sinfo.myMTU
|
||||||
|
}
|
||||||
|
|
||||||
func (sinfo *sessionInfo) nonceIsOK(theirNonce *boxNonce) bool {
|
func (sinfo *sessionInfo) nonceIsOK(theirNonce *boxNonce) bool {
|
||||||
// The bitmask is to allow for some non-duplicate out-of-order packets
|
// The bitmask is to allow for some non-duplicate out-of-order packets
|
||||||
diff := theirNonce.minus(&sinfo.theirNonce)
|
diff := theirNonce.minus(&sinfo.theirNonce)
|
||||||
|
Loading…
Reference in New Issue
Block a user