From ec371af84f133167b6310c1ffa827b72a9e6dc66 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 18 May 2018 17:59:29 +0100 Subject: [PATCH] Track TX/RX bytes over session and if MTU was adjusted, add to admin socket getSession --- src/yggdrasil/admin.go | 3 +++ src/yggdrasil/session.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index 3270365..db485d1 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -374,6 +374,9 @@ func (a *admin) getData_getSessions() []admin_nodeInfo { {"IP", net.IP(sinfo.theirAddr[:]).String()}, {"coords", fmt.Sprint(sinfo.coords)}, {"MTU", fmt.Sprint(sinfo.getMTU())}, + {"wasMTUFixed", fmt.Sprint(sinfo.wasMTUFixed)}, + {"bytesSent", fmt.Sprint(sinfo.bytesSent)}, + {"bytesRecvd", fmt.Sprint(sinfo.bytesRecvd)}, } infos = append(infos, info) } diff --git a/src/yggdrasil/session.go b/src/yggdrasil/session.go index f413174..df76042 100644 --- a/src/yggdrasil/session.go +++ b/src/yggdrasil/session.go @@ -21,6 +21,7 @@ type sessionInfo struct { myNonce boxNonce theirMTU uint16 myMTU uint16 + wasMTUFixed bool // Was the MTU fixed by a receive error? time time.Time // Time we last received a packet coords []byte // coords of destination packet []byte // a buffered packet, sent immediately on ping/pong @@ -32,6 +33,8 @@ type sessionInfo struct { mtuTime time.Time // time myMTU was last changed pingTime time.Time // time the first ping was sent since the last received packet pingSend time.Time // time the last ping was sent + bytesSent uint64 // Bytes of real traffic sent in this session + bytesRecvd uint64 // Bytes of real traffic received in this session } type sessionPing struct { @@ -384,6 +387,7 @@ func (sinfo *sessionInfo) doSend(bs []byte) { payload: payload, } packet := p.encode() + sinfo.bytesSent += uint64(len(bs)) sinfo.core.router.out(packet) } @@ -411,6 +415,7 @@ func (sinfo *sessionInfo) doRecv(p *wire_trafficPacket) { //sinfo.core.log.Println("DEBUG set MTU to:", sinfo.myMTU) sinfo.core.sessions.sendPingPong(sinfo, false) sinfo.mtuTime = time.Now() + sinfo.wasMTUFixed = true } } go func() { sinfo.core.router.admin <- fixSessionMTU }() @@ -427,5 +432,6 @@ func (sinfo *sessionInfo) doRecv(p *wire_trafficPacket) { go func() { sinfo.core.router.admin <- fixSessionMTU }() sinfo.updateNonce(&p.nonce) sinfo.time = time.Now() + sinfo.bytesRecvd += uint64(len(bs)) sinfo.core.router.recvPacket(bs, &sinfo.theirAddr, &sinfo.theirSubnet) }