2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2023 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 // Show queued NNCP Rx/Tx stats.
28 "github.com/dustin/go-humanize"
29 "go.cypherpunks.ru/nncp/v8"
33 fmt.Fprint(os.Stderr, nncp.UsageHeader())
34 fmt.Fprint(os.Stderr, "nncp-stat -- show queued Rx/Tx stats\n\n")
35 fmt.Fprintf(os.Stderr, "Usage: %s [options] [-pkt] [-node NODE]\nOptions:\n", os.Args[0])
39 func jobPrint(xx nncp.TRxTx, job nncp.Job, suffix string) {
41 "\t%s %s%s %s (nice: %s)\n",
43 nncp.Base32Codec.EncodeToString(job.HshValue[:]), suffix,
44 humanize.IBytes(uint64(job.Size)),
45 nncp.NicenessFmt(job.PktEnc.Nice),
51 showPkt = flag.Bool("pkt", false, "Show packets listing")
52 cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
53 nodeRaw = flag.String("node", "", "Process only that node")
54 spoolPath = flag.String("spool", "", "Override path to spool")
55 debug = flag.Bool("debug", false, "Print debug messages")
56 version = flag.Bool("version", false, "Print version information")
57 warranty = flag.Bool("warranty", false, "Print warranty information")
59 log.SetFlags(log.Lshortfile)
63 fmt.Println(nncp.Warranty)
67 fmt.Println(nncp.VersionGet())
71 ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, "", false, false, false, *debug)
73 log.Fatalln("Error during initialization:", err)
76 var nodeOnly *nncp.Node
78 nodeOnly, err = ctx.FindNode(*nodeRaw)
80 log.Fatalln("Invalid -node specified:", err)
84 nodeNames := make([]string, 0, len(ctx.Neigh))
85 nodeNameToNode := make(map[string]*nncp.Node, len(ctx.Neigh))
86 for _, node := range ctx.Neigh {
87 nodeNames = append(nodeNames, node.Name)
88 nodeNameToNode[node.Name] = node
90 sort.Strings(nodeNames)
94 for _, nodeName := range nodeNames {
95 node = nodeNameToNode[nodeName]
96 if nodeOnly != nil && *node.Id != *nodeOnly.Id {
99 fmt.Println(node.Name)
100 rxNums := make(map[uint8]int)
101 rxBytes := make(map[uint8]int64)
102 noCKNums := make(map[uint8]int)
103 noCKBytes := make(map[uint8]int64)
105 partBytes := int64(0)
106 for job := range ctx.Jobs(node.Id, nncp.TRx) {
108 jobPrint(nncp.TRx, job, "")
110 rxNums[job.PktEnc.Nice] = rxNums[job.PktEnc.Nice] + 1
111 rxBytes[job.PktEnc.Nice] = rxBytes[job.PktEnc.Nice] + job.Size
113 for job := range ctx.JobsNoCK(node.Id) {
115 jobPrint(nncp.TRx, job, ".nock")
117 noCKNums[job.PktEnc.Nice] = noCKNums[job.PktEnc.Nice] + 1
118 noCKBytes[job.PktEnc.Nice] = noCKBytes[job.PktEnc.Nice] + job.Size
120 for job := range ctx.JobsPart(node.Id) {
125 nncp.Base32Codec.EncodeToString(job.HshValue[:]),
126 humanize.IBytes(uint64(job.Size)),
130 partBytes += job.Size
132 txNums := make(map[uint8]int)
133 txBytes := make(map[uint8]int64)
134 for job := range ctx.Jobs(node.Id, nncp.TTx) {
136 jobPrint(nncp.TTx, job, "")
138 txNums[job.PktEnc.Nice] = txNums[job.PktEnc.Nice] + 1
139 txBytes[job.PktEnc.Nice] = txBytes[job.PktEnc.Nice] + job.Size
144 "\tpart: % 10s, % 3d pkts\n",
145 humanize.IBytes(uint64(partBytes)), partNums,
148 for nice = 1; nice > 0; nice++ {
149 rxNum, rxExists := rxNums[nice]
150 txNum, txExists := txNums[nice]
151 noCKNum, noCKExists := noCKNums[nice]
152 if !(rxExists || txExists || noCKExists) {
156 "\tnice:% 4s | Rx: % 10s, % 3d pkts | Tx: % 10s, % 3d pkts",
157 nncp.NicenessFmt(nice),
158 humanize.IBytes(uint64(rxBytes[nice])),
160 humanize.IBytes(uint64(txBytes[nice])),
165 " | NoCK: % 10s, % 3d pkts",
166 humanize.IBytes(uint64(noCKBytes[nice])),