From: Sergey Matveev Date: Sun, 8 Jan 2017 10:16:56 +0000 (+0300) Subject: -quiet option X-Git-Tag: 0.1~21 X-Git-Url: http://www.git.cypherpunks.ru/?a=commitdiff_plain;h=cca813a5428d68fc711000ab436652a0fb21c4be;p=nncp.git -quiet option --- diff --git a/src/cypherpunks.ru/nncp/check.go b/src/cypherpunks.ru/nncp/check.go index 87f4bb8..fff7c02 100644 --- a/src/cypherpunks.ru/nncp/check.go +++ b/src/cypherpunks.ru/nncp/check.go @@ -41,7 +41,12 @@ func Check(src io.Reader, checksum []byte) (bool, error) { func (ctx *Ctx) checkXx(nodeId *NodeId, xx TRxTx) bool { isBad := false for job := range ctx.Jobs(nodeId, xx) { - sds := SDS{"xx": string(xx), "node": nodeId, "pkt": job.Fd.Name()} + sds := SDS{ + "xx": string(xx), + "node": nodeId, + "pkt": ToBase32(job.HshValue[:]), + } + ctx.LogI("check", sds, "") gut, err := Check(job.Fd, job.HshValue[:]) job.Fd.Close() if err != nil { diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-call/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-call/main.go index ad28b76..c6203e6 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-call/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-call/main.go @@ -47,6 +47,7 @@ func main() { niceRaw = flag.Int("nice", 255, "Minimal required niceness") rxOnly = flag.Bool("rx", false, "Only receive packets") txOnly = flag.Bool("tx", false, "Only transfer packets") + quiet = flag.Bool("quiet", false, "Print only errors") debug = flag.Bool("debug", false, "Enable debugging information") version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") @@ -81,6 +82,7 @@ func main() { if err != nil { log.Fatalln("Can not parse config:", err) } + ctx.Quiet = *quiet ctx.Debug = *debug splitted := strings.SplitN(flag.Arg(0), ":", 2) diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-check/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-check/main.go index 32625fd..d1d2d04 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-check/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-check/main.go @@ -40,6 +40,7 @@ func main() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") nodeRaw = flag.String("node", "", "Process only that node") + quiet = flag.Bool("quiet", false, "Print only errors") debug = flag.Bool("debug", false, "Enable debugging information") version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") @@ -63,6 +64,7 @@ func main() { if err != nil { log.Fatalln("Can not parse config:", err) } + ctx.Quiet = *quiet ctx.Debug = *debug var nodeOnly *nncp.Node diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go index 9ed14d2..de2f936 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go @@ -45,6 +45,7 @@ func main() { niceRaw = flag.Int("nice", 255, "Minimal required niceness") bind = flag.String("bind", ":5400", "Address to bind to") maxConn = flag.Int("maxconn", 128, "Maximal number of simultaneous connections") + quiet = flag.Bool("quiet", false, "Print only errors") debug = flag.Bool("debug", false, "Enable debugging information") version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") @@ -72,6 +73,7 @@ func main() { if err != nil { log.Fatalln("Can not parse config:", err) } + ctx.Quiet = *quiet ctx.Debug = *debug ln, err := net.Listen("tcp", *bind) diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-file/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-file/main.go index eb5188b..6f37a96 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-file/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-file/main.go @@ -41,6 +41,7 @@ func main() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") niceRaw = flag.Int("nice", nncp.DefaultNiceMail, "Outbound packet niceness") + quiet = flag.Bool("quiet", false, "Print only errors") debug = flag.Bool("debug", false, "Enable debugging information") version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") @@ -72,6 +73,7 @@ func main() { if err != nil { log.Fatalln("Can not parse config:", err) } + ctx.Quiet = *quiet ctx.Debug = *debug splitted := strings.SplitN(flag.Arg(1), ":", 2) diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go index 946f36f..7360f50 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go @@ -41,6 +41,7 @@ func main() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") niceRaw = flag.Int("nice", nncp.DefaultNiceMail, "Outbound packet niceness") + quiet = flag.Bool("quiet", false, "Print only errors") debug = flag.Bool("debug", false, "Enable debugging information") version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") @@ -72,6 +73,7 @@ func main() { if err != nil { log.Fatalln("Can not parse config:", err) } + ctx.Quiet = *quiet ctx.Debug = *debug splitted := strings.SplitN(flag.Arg(0), ":", 2) diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go index 8eb98c7..8b01b8c 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go @@ -43,6 +43,7 @@ func main() { var ( cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") niceRaw = flag.Int("nice", nncp.DefaultNiceMail, "Outbound packet niceness") + quiet = flag.Bool("quiet", false, "Print only errors") debug = flag.Bool("debug", false, "Enable debugging information") version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") @@ -74,6 +75,7 @@ func main() { if err != nil { log.Fatalln("Can not parse config:", err) } + ctx.Quiet = *quiet ctx.Debug = *debug node, err := ctx.FindNode(flag.Arg(0)) diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go index 1691a8f..e12e901 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go @@ -42,6 +42,7 @@ func main() { nodeRaw = flag.String("node", "", "Process only that node") niceRaw = flag.Int("nice", 255, "Minimal required niceness") dryRun = flag.Bool("dryrun", false, "Do not actually write any tossed data") + quiet = flag.Bool("quiet", false, "Print only errors") debug = flag.Bool("debug", false, "Enable debugging information") version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") @@ -69,6 +70,7 @@ func main() { if err != nil { log.Fatalln("Can not parse config:", err) } + ctx.Quiet = *quiet ctx.Debug = *debug var nodeOnly *nncp.Node diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go index 434613d..f12fa5f 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go @@ -50,6 +50,7 @@ func main() { txOnly = flag.Bool("tx", false, "Only transfer packets") force = flag.Bool("force", false, "Force outbound directories creation") keep = flag.Bool("keep", false, "Do not delete transferred packets") + quiet = flag.Bool("quiet", false, "Print only errors") debug = flag.Bool("debug", false, "Enable debugging information") version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") @@ -84,6 +85,7 @@ func main() { if err != nil { log.Fatalln("Can not parse config:", err) } + ctx.Quiet = *quiet ctx.Debug = *debug var nodeOnly *nncp.Node diff --git a/src/cypherpunks.ru/nncp/ctx.go b/src/cypherpunks.ru/nncp/ctx.go index 3407911..c3dc144 100644 --- a/src/cypherpunks.ru/nncp/ctx.go +++ b/src/cypherpunks.ru/nncp/ctx.go @@ -31,6 +31,7 @@ type Ctx struct { Spool string LogPath string + Quiet bool Debug bool NotifyFile *FromToYAML NotifyFreq *FromToYAML diff --git a/src/cypherpunks.ru/nncp/humanizer.go b/src/cypherpunks.ru/nncp/humanizer.go index 87a20c2..6fda358 100644 --- a/src/cypherpunks.ru/nncp/humanizer.go +++ b/src/cypherpunks.ru/nncp/humanizer.go @@ -128,10 +128,10 @@ func (ctx *Ctx) Humanize(s string) string { msg += ": " + err } case "check": - msg = fmt.Sprintf( - "Integrity check: %s/%s/%s %s", - sds["node"], sds["xx"], sds["pkt"], sds["err"], - ) + msg = fmt.Sprintf("Checking: %s/%s/%s", sds["node"], sds["xx"], sds["pkt"]) + if err, exists := sds["err"]; exists { + msg += fmt.Sprintf(" %s", err) + } case "nncp-xfer": switch sds["xx"] { case "rx": diff --git a/src/cypherpunks.ru/nncp/log.go b/src/cypherpunks.ru/nncp/log.go index c3d5872..f37d949 100644 --- a/src/cypherpunks.ru/nncp/log.go +++ b/src/cypherpunks.ru/nncp/log.go @@ -98,12 +98,16 @@ func (ctx *Ctx) LogD(who string, sds SDS, msg string) { func (ctx *Ctx) LogI(who string, sds SDS, msg string) { msg = msgFmt(LogLevel("I"), who, sds, msg) - fmt.Fprintln(os.Stderr, ctx.Humanize(msg)) + if !ctx.Quiet { + fmt.Fprintln(os.Stderr, ctx.Humanize(msg)) + } ctx.Log(msg) } func (ctx *Ctx) LogP(who string, sds SDS, msg string) { - fmt.Fprintln(os.Stderr, ctx.Humanize(msgFmt(LogLevel("P"), who, sds, msg))) + if !ctx.Quiet { + fmt.Fprintln(os.Stderr, ctx.Humanize(msgFmt(LogLevel("P"), who, sds, msg))) + } } func (ctx *Ctx) LogE(who string, sds SDS, msg string) {