5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-25 21:51:38 +00:00

adjust how sessions learn source routes, try to recover faster if coords change (but assume the old path still works until we get a ping through that gives us a new path)

This commit is contained in:
Arceliar 2020-11-08 05:39:30 -06:00
parent e19e938f64
commit 0ac203b007

View File

@ -95,7 +95,7 @@ func (sinfo *sessionInfo) _update(p *sessionPing, rpath []byte) bool {
} }
sinfo.time = time.Now() sinfo.time = time.Now()
sinfo.tstamp = p.Tstamp sinfo.tstamp = p.Tstamp
if p.IsPong && sinfo.path == nil { if p.IsPong {
path := switch_reverseCoordBytes(rpath) path := switch_reverseCoordBytes(rpath)
sinfo.path = append(sinfo.path[:0], path...) sinfo.path = append(sinfo.path[:0], path...)
} }
@ -335,13 +335,8 @@ func (sinfo *sessionInfo) _sendPingPong(isPong bool, path []byte) {
packet := p.encode() packet := p.encode()
// TODO rewrite the below if/when the peer struct becomes an actor, to not go through the router first // TODO rewrite the below if/when the peer struct becomes an actor, to not go through the router first
sinfo.sessions.router.Act(sinfo, func() { sinfo.sessions.router.out(packet) }) sinfo.sessions.router.Act(sinfo, func() { sinfo.sessions.router.out(packet) })
if !isPong && sinfo.pingTime.Before(sinfo.time) {
sinfo.pingTime = time.Now()
}
if !isPong { if !isPong {
// Sending a ping may happen when we don't know if our path info is good anymore... sinfo.pingTime = time.Now()
// Reset paths just to be safe...
sinfo.path = nil
} }
} }
@ -483,9 +478,6 @@ func (sinfo *sessionInfo) _recvPacket(p *wire_trafficPacket) {
sinfo._updateNonce(&p.Nonce) sinfo._updateNonce(&p.Nonce)
sinfo.bytesRecvd += uint64(len(bs)) sinfo.bytesRecvd += uint64(len(bs))
sinfo.conn.recvMsg(sinfo, bs) sinfo.conn.recvMsg(sinfo, bs)
if sinfo.path == nil {
sinfo._sendPingPong(false, nil)
}
} }
ch <- callback ch <- callback
sinfo.checkCallbacks() sinfo.checkCallbacks()
@ -529,6 +521,9 @@ func (sinfo *sessionInfo) _send(msg FlowKeyMessage) {
sinfo.sessions.router.Act(sinfo, func() { sinfo.sessions.router.Act(sinfo, func() {
sinfo.sessions.router.out(packet) sinfo.sessions.router.out(packet)
}) })
if time.Since(sinfo.pingTime) > 3*time.Second {
sinfo._sendPingPong(false, nil)
}
} }
ch <- callback ch <- callback
sinfo.checkCallbacks() sinfo.checkCallbacks()