5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 23:41:35 +00:00

get rid of old buffered session packets

This commit is contained in:
Arceliar 2019-06-28 20:02:58 -05:00
parent e7cb76cea3
commit e88bef35c0
3 changed files with 3 additions and 15 deletions

View File

@ -215,7 +215,7 @@ func (c *Conn) Write(b []byte) (bytesWritten int, err error) {
} }
switch { switch {
case !sinfo.init: case !sinfo.init:
doSearch() sinfo.core.sessions.ping(sinfo)
case time.Since(sinfo.time) > 6*time.Second: case time.Since(sinfo.time) > 6*time.Second:
if sinfo.time.Before(sinfo.pingTime) && time.Since(sinfo.pingTime) > 6*time.Second { if sinfo.time.Before(sinfo.pingTime) && time.Since(sinfo.pingTime) > 6*time.Second {
// TODO double check that the above condition is correct // TODO double check that the above condition is correct

View File

@ -37,7 +37,6 @@ type searchInfo struct {
dest crypto.NodeID dest crypto.NodeID
mask crypto.NodeID mask crypto.NodeID
time time.Time time time.Time
packet []byte
toVisit []*dhtInfo toVisit []*dhtInfo
visited map[crypto.NodeID]bool visited map[crypto.NodeID]bool
callback func(*sessionInfo, error) callback func(*sessionInfo, error)
@ -215,7 +214,6 @@ func (sinfo *searchInfo) checkDHTRes(res *dhtRes) bool {
} }
// FIXME (!) replay attacks could mess with coords? Give it a handle (tstamp)? // FIXME (!) replay attacks could mess with coords? Give it a handle (tstamp)?
sess.coords = res.Coords sess.coords = res.Coords
sess.packet = sinfo.packet
sinfo.core.sessions.ping(sess) sinfo.core.sessions.ping(sess)
sinfo.callback(sess, nil) sinfo.callback(sess, nil)
// Cleanup // Cleanup

View File

@ -39,7 +39,6 @@ type sessionInfo struct {
pingTime time.Time // time the first ping was sent since the last received packet pingTime time.Time // time the first ping was sent since the last received packet
pingSend time.Time // time the last ping was sent pingSend time.Time // time the last ping was sent
coords []byte // coords of destination coords []byte // coords of destination
packet []byte // a buffered packet, sent immediately on ping/pong
init bool // Reset if coords change init bool // Reset if coords change
tstamp int64 // ATOMIC - tstamp from their last session ping, replay attack mitigation tstamp int64 // ATOMIC - tstamp from their last session ping, replay attack mitigation
bytesSent uint64 // Bytes of real traffic sent in this session bytesSent uint64 // Bytes of real traffic sent in this session
@ -325,8 +324,8 @@ func (ss *sessions) sendPingPong(sinfo *sessionInfo, isPong bool) {
} }
packet := p.encode() packet := p.encode()
ss.core.router.out(packet) ss.core.router.out(packet)
if !isPong { if sinfo.pingTime.Before(sinfo.time) {
sinfo.pingSend = time.Now() sinfo.pingTime = time.Now()
} }
} }
@ -367,15 +366,6 @@ func (ss *sessions) handlePing(ping *sessionPing) {
if !ping.IsPong { if !ping.IsPong {
ss.sendPingPong(sinfo, true) ss.sendPingPong(sinfo, true)
} }
if sinfo.packet != nil {
/* FIXME this needs to live in the net.Conn or something, needs work in Write
// send
var bs []byte
bs, sinfo.packet = sinfo.packet, nil
ss.core.router.sendPacket(bs) // FIXME this needs to live in the net.Conn or something, needs work in Write
*/
sinfo.packet = nil
}
}) })
} }