]> Sergey Matveev's repositories - vors.git/commitdiff
Show bad packets counter
authorSergey Matveev <stargrave@stargrave.org>
Thu, 11 Apr 2024 17:21:39 +0000 (20:21 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 11 Apr 2024 17:21:39 +0000 (20:21 +0300)
cmd/client/main.go
cmd/client/stats.go
cmd/server/main.go
cmd/server/peer.go
cmd/server/stats.go [deleted file]

index f33814f53bdf4e64756fc2e76774fd76a5548cf3427bf7740f98570d8a54ff01..118a7fed55b076517fd8339680307bfa1ad0c03d59dc976006d5903715de0d1e 100644 (file)
@@ -362,7 +362,7 @@ func main() {
                                                        tag[:vors.TagLen],
                                                        buf[len(buf)-vors.TagLen:],
                                                ) != 1 {
-                                                       log.Println("decrypt:", stream.name, "tag differs")
+                                                       stream.stats.bads++
                                                        continue
                                                }
                                                pkt = buf[4 : len(buf)-vors.TagLen]
index 24e3f9941f10d4499450c23f230b8c6cff529d1a11aa8014949caad63c1c81b4..795dfbf2b7fd73b556d31ebc13ab126930ddeeda6ea581b928b947cfd049f48a 100644 (file)
@@ -30,6 +30,7 @@ import (
 type Stats struct {
        pkts    int64
        bytes   uint64
+       bads    int64
        lost    int64
        reorder int64
        last    time.Time
@@ -62,9 +63,10 @@ func statsDrawer(stats *Stats, name string) {
                        return
                case now = <-tick:
                        s := fmt.Sprintf(
-                               "%s  |  %s  |  L/R: %s / %s",
+                               "%s  |  %s  |  B/L/R: %s/%s/%s",
                                humanize.Comma(stats.pkts),
                                humanize.IBytes(stats.bytes),
+                               humanize.Comma(stats.bads),
                                humanize.Comma(stats.lost),
                                humanize.Comma(stats.reorder),
                        )
index 17c9ce3daecaf66a17ffd27dc99ed892e04e60262e1f76e2e71f89ed98af2980..fd60e914b190568e27db7e55096cb07083e2813f65e07933b736316f0dd9c2fb 100644 (file)
@@ -256,10 +256,11 @@ func newPeer(conn *net.TCPConn) {
                                return
                        case now = <-tick:
                                s := fmt.Sprintf(
-                                       "%s | Rx/Tx: %s / %s  |  %s / %s",
+                                       "%s | Rx/Tx/Bad: %s / %s / %s |  %s / %s",
                                        peer.addr,
                                        humanize.Comma(stats.pktsRx),
                                        humanize.Comma(stats.pktsTx),
+                                       humanize.Comma(stats.bads),
                                        humanize.IBytes(stats.bytesRx),
                                        humanize.IBytes(stats.bytesTx),
                                )
@@ -394,7 +395,7 @@ func main() {
                                continue
                        }
                        if n <= 4+vors.TagLen {
-                               slog.Info("too small", "peer", peer.name, "len", n)
+                               peer.stats.bads++
                                continue
                        }
 
@@ -415,8 +416,7 @@ func main() {
                                tag[:vors.TagLen],
                                buf[n-vors.TagLen:n],
                        ) != 1 {
-                               log.Println("decrypt:", peer.name, "tag differs")
-                               slog.Info("MAC failed", "peer", peer.name, "len", n)
+                               peer.stats.bads++
                                continue
                        }
 
index ef0693b6d86846ced607c9289f2ae6aecfea0e26e75588ed924d60460cced056..960d5b2dbbd225fb38e3b75d8b48415ca5db851368d359b25adbd3fecc0af8d1 100644 (file)
@@ -4,11 +4,22 @@ import (
        "log/slog"
        "net"
        "sync"
+       "time"
 
        "github.com/flynn/noise"
        vors "go.stargrave.org/vors/internal"
 )
 
+type Stats struct {
+       pktsRx  int64
+       pktsTx  int64
+       bytesRx uint64
+       bytesTx uint64
+       bads    int64
+       last    time.Time
+       alive   chan struct{}
+}
+
 type Peer struct {
        name  string
        sid   byte
diff --git a/cmd/server/stats.go b/cmd/server/stats.go
deleted file mode 100644 (file)
index 86c010e..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-package main
-
-import "time"
-
-type Stats struct {
-       pktsRx  int64
-       pktsTx  int64
-       bytesRx uint64
-       bytesTx uint64
-       last    time.Time
-       alive   chan struct{}
-}