cmd/client/main.go | 6 +++--- cmd/server/main.go | 4 ++-- internal/var.go | 12 +++++++++++- diff --git a/cmd/client/main.go b/cmd/client/main.go index 71fe10fda05b975e940ef0ad0ad93ffef70ee616f8baeae23f40f02c7e8fd228..c745deae7edb5fe17c921ab932581fbe2b82272e6b8b64b13b6fe9d44e6443fa 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -501,7 +501,7 @@ // log.Println("unknown stream:", buf[0]) continue } stream.stats.pkts++ - stream.stats.bytes += uint64(n) + stream.stats.bytes += vors.IPHdrLen(from.IP) + 8 + uint64(n) ctr = binary.BigEndian.Uint32(buf) if ctr <= stream.ctr { stream.stats.reorder++ @@ -519,7 +519,7 @@ if !OurStats.last.Add(time.Second).Before(now) { continue } OurStats.pkts++ - OurStats.bytes += 1 + OurStats.bytes += vors.IPHdrLen(srvAddrUDP.IP) + 8 + 1 if _, err = conn.Write([]byte{sid}); err != nil { log.Println("send:", err) Finish <- struct{}{} @@ -584,7 +584,7 @@ copy(buf[4+n:], tag[:vors.TagLen]) pkt = buf[:4+n+vors.TagLen] OurStats.pkts++ - OurStats.bytes += uint64(len(pkt)) + OurStats.bytes += vors.IPHdrLen(srvAddrUDP.IP) + 8 + uint64(len(pkt)) OurStats.last = time.Now() OurStats.AddRMS(pcm) if _, err = conn.Write(pkt); err != nil { diff --git a/cmd/server/main.go b/cmd/server/main.go index 37efdfbc779ca0f439de16289649c90a75fd573b4d8eb9f780daa9c6170ec2a6..354de6c88e68634b77459312a2dccff594a3b6cef1a64b2e949c2929f38e5aa2 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -406,7 +406,7 @@ continue } peer.stats.pktsRx++ - peer.stats.bytesRx += uint64(n) + peer.stats.bytesRx += vors.IPHdrLen(from.IP) + 8 + uint64(n) if n == 1 { continue } @@ -442,7 +442,7 @@ if p.sid == sid { continue } p.stats.pktsTx++ - p.stats.bytesTx += uint64(n) + p.stats.bytesTx += vors.IPHdrLen(p.addr.IP) + 8 + uint64(n) if _, err = lnUDP.WriteToUDP(buf[:n], p.addr); err != nil { slog.Warn("sendto", "peer", peer.name, "err", err) } diff --git a/internal/var.go b/internal/var.go index b4cb3ff551c66779fcb787a259d7a09c0377167c4497a2fa08391e93723349ca..8236a4d77bfcf305a1e86c1c3201cb42a27b3bf287ce5c3a35b4d883dd030402 100644 --- a/internal/var.go +++ b/internal/var.go @@ -1,6 +1,9 @@ package internal -import "time" +import ( + "net" + "time" +) const ( TagLen = 8 @@ -15,3 +18,10 @@ var ( PingTime = 10 * time.Second ScreenRefresh = 200 * time.Millisecond ) + +func IPHdrLen(ip net.IP) uint64 { + if ip.To4() == nil { + return 40 + } + return 20 +}