Track TX/RX bytes over session and if MTU was adjusted, add to admin socket getSession

This commit is contained in:
Neil Alexander 2018-05-18 17:59:29 +01:00
parent 546c5f1412
commit ec371af84f
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
2 changed files with 9 additions and 0 deletions

View File

@ -374,6 +374,9 @@ func (a *admin) getData_getSessions() []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())}, {"MTU", fmt.Sprint(sinfo.getMTU())},
{"wasMTUFixed", fmt.Sprint(sinfo.wasMTUFixed)},
{"bytesSent", fmt.Sprint(sinfo.bytesSent)},
{"bytesRecvd", fmt.Sprint(sinfo.bytesRecvd)},
} }
infos = append(infos, info) infos = append(infos, info)
} }

View File

@ -21,6 +21,7 @@ type sessionInfo struct {
myNonce boxNonce myNonce boxNonce
theirMTU uint16 theirMTU uint16
myMTU uint16 myMTU uint16
wasMTUFixed bool // Was the MTU fixed by a receive error?
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
@ -32,6 +33,8 @@ type sessionInfo struct {
mtuTime time.Time // time myMTU was last changed mtuTime time.Time // time myMTU was last changed
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
bytesSent uint64 // Bytes of real traffic sent in this session
bytesRecvd uint64 // Bytes of real traffic received in this session
} }
type sessionPing struct { type sessionPing struct {
@ -384,6 +387,7 @@ func (sinfo *sessionInfo) doSend(bs []byte) {
payload: payload, payload: payload,
} }
packet := p.encode() packet := p.encode()
sinfo.bytesSent += uint64(len(bs))
sinfo.core.router.out(packet) 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.log.Println("DEBUG set MTU to:", sinfo.myMTU)
sinfo.core.sessions.sendPingPong(sinfo, false) sinfo.core.sessions.sendPingPong(sinfo, false)
sinfo.mtuTime = time.Now() sinfo.mtuTime = time.Now()
sinfo.wasMTUFixed = true
} }
} }
go func() { sinfo.core.router.admin <- fixSessionMTU }() 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 }() go func() { sinfo.core.router.admin <- fixSessionMTU }()
sinfo.updateNonce(&p.nonce) sinfo.updateNonce(&p.nonce)
sinfo.time = time.Now() sinfo.time = time.Now()
sinfo.bytesRecvd += uint64(len(bs))
sinfo.core.router.recvPacket(bs, &sinfo.theirAddr, &sinfo.theirSubnet) sinfo.core.router.recvPacket(bs, &sinfo.theirAddr, &sinfo.theirSubnet)
} }