/*
-NNCP -- Node-to-Node CoPy
+NNCP -- Node to Node copy, utilities for store-and-forward data exchange
Copyright (C) 2016-2017 Sergey Matveev <stargrave@stargrave.org>
This program is free software: you can redistribute it and/or modify
"io/ioutil"
"log"
"os"
+ "sort"
"cypherpunks.ru/nncp"
"github.com/dustin/go-humanize"
func usage() {
fmt.Fprintf(os.Stderr, nncp.UsageHeader())
fmt.Fprintln(os.Stderr, "nncp-stat -- show queued Rx/Tx stats\n")
- fmt.Fprintln(os.Stderr, "Usage: %s [options]\nOptions:", os.Args[0])
+ fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:\n", os.Args[0])
flag.PrintDefaults()
}
var (
cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
nodeRaw = flag.String("node", "", "Process only that node")
- debug = flag.Bool("debug", false, "Enable debugging information")
+ debug = flag.Bool("debug", false, "Print debug messages")
version = flag.Bool("version", false, "Print version information")
warranty = flag.Bool("warranty", false, "Print warranty information")
)
return
}
- cfgRaw, err := ioutil.ReadFile(*cfgPath)
+ cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
if err != nil {
log.Fatalln("Can not read config:", err)
}
}
}
- for nodeId, node := range ctx.Neigh {
- if nodeOnly != nil && nodeId != *nodeOnly.Id {
+ nodeNames := make([]string, 0, len(ctx.Neigh))
+ nodeNameToNode := make(map[string]*nncp.Node, len(ctx.Neigh))
+ for _, node := range ctx.Neigh {
+ nodeNames = append(nodeNames, node.Name)
+ nodeNameToNode[node.Name] = node
+ }
+ sort.Strings(nodeNames)
+
+ var node *nncp.Node
+ for _, nodeName := range nodeNames {
+ node = nodeNameToNode[nodeName]
+ if nodeOnly != nil && *node.Id != *nodeOnly.Id {
continue
}
rxNums := make(map[uint8]int)
rxBytes := make(map[uint8]int64)
- for job := range ctx.Jobs(&nodeId, nncp.TRx) {
+ for job := range ctx.Jobs(node.Id, nncp.TRx) {
job.Fd.Close()
rxNums[job.PktEnc.Nice] = rxNums[job.PktEnc.Nice] + 1
rxBytes[job.PktEnc.Nice] = rxBytes[job.PktEnc.Nice] + job.Size
}
txNums := make(map[uint8]int)
txBytes := make(map[uint8]int64)
- for job := range ctx.Jobs(&nodeId, nncp.TTx) {
+ for job := range ctx.Jobs(node.Id, nncp.TTx) {
job.Fd.Close()
txNums[job.PktEnc.Nice] = txNums[job.PktEnc.Nice] + 1
txBytes[job.PktEnc.Nice] = txBytes[job.PktEnc.Nice] + job.Size