]> Sergey Matveev's repositories - vors.git/commitdiff
Consider overhead length in statistics
authorSergey Matveev <stargrave@stargrave.org>
Sun, 14 Apr 2024 08:41:21 +0000 (11:41 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 14 Apr 2024 08:41:21 +0000 (11:41 +0300)
cmd/client/main.go
cmd/server/main.go
internal/var.go

index 71fe10fda05b975e940ef0ad0ad93ffef70ee616f8baeae23f40f02c7e8fd228..c745deae7edb5fe17c921ab932581fbe2b82272e6b8b64b13b6fe9d44e6443fa 100644 (file)
@@ -501,7 +501,7 @@ func main() {
                                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 @@ func main() {
                                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 @@ func main() {
                        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 {
index 37efdfbc779ca0f439de16289649c90a75fd573b4d8eb9f780daa9c6170ec2a6..354de6c88e68634b77459312a2dccff594a3b6cef1a64b2e949c2929f38e5aa2 100644 (file)
@@ -406,7 +406,7 @@ func main() {
                        }
 
                        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 @@ func main() {
                                        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)
                                }
index b4cb3ff551c66779fcb787a259d7a09c0377167c4497a2fa08391e93723349ca..8236a4d77bfcf305a1e86c1c3201cb42a27b3bf287ce5c3a35b4d883dd030402 100644 (file)
@@ -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
+}