From: Sergey Matveev Date: Thu, 11 Apr 2024 17:21:39 +0000 (+0300) Subject: Show bad packets counter X-Git-Tag: v1.0.0~11 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=4cc487267dc294c46b308cb9419bb07399a51a0689bcf52aa69d49c0191be03d;p=vors.git Show bad packets counter --- diff --git a/cmd/client/main.go b/cmd/client/main.go index f33814f..118a7fe 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -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] diff --git a/cmd/client/stats.go b/cmd/client/stats.go index 24e3f99..795dfbf 100644 --- a/cmd/client/stats.go +++ b/cmd/client/stats.go @@ -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), ) diff --git a/cmd/server/main.go b/cmd/server/main.go index 17c9ce3..fd60e91 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -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 } diff --git a/cmd/server/peer.go b/cmd/server/peer.go index ef0693b..960d5b2 100644 --- a/cmd/server/peer.go +++ b/cmd/server/peer.go @@ -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 index 86c010e..0000000 --- a/cmd/server/stats.go +++ /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{} -}