]> Cypherpunks.ru repositories - nncp.git/commitdiff
-quiet option
authorSergey Matveev <stargrave@stargrave.org>
Sun, 8 Jan 2017 10:16:56 +0000 (13:16 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 8 Jan 2017 10:16:56 +0000 (13:16 +0300)
12 files changed:
src/cypherpunks.ru/nncp/check.go
src/cypherpunks.ru/nncp/cmd/nncp-call/main.go
src/cypherpunks.ru/nncp/cmd/nncp-check/main.go
src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go
src/cypherpunks.ru/nncp/cmd/nncp-file/main.go
src/cypherpunks.ru/nncp/cmd/nncp-freq/main.go
src/cypherpunks.ru/nncp/cmd/nncp-mail/main.go
src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go
src/cypherpunks.ru/nncp/cmd/nncp-xfer/main.go
src/cypherpunks.ru/nncp/ctx.go
src/cypherpunks.ru/nncp/humanizer.go
src/cypherpunks.ru/nncp/log.go

index 87f4bb8c83a123414937d7d705b8ccfdcf73b9e6..fff7c02be8e942fb8f448c7c77d7642dc2d46c69 100644 (file)
@@ -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 {
index ad28b7605b6f8b4c45ee51b5cd8d8f289d247a36..c6203e622e1264879882536b71e0ccb3319588d6 100644 (file)
@@ -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)
index 32625fdd5b63677372d81af6ef56a81b716b6fb0..d1d2d045e55a43f6eda24b483396182bf0dceb72 100644 (file)
@@ -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
index 9ed14d2e814c1a41dfe420866154a0d846129cca..de2f936d8636c58ccb769d276936b5852e25d496 100644 (file)
@@ -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)
index eb5188beee4b48ff3f5420922b564fe3f309fb92..6f37a96a904146e0a0dc63513b8000653e715dbb 100644 (file)
@@ -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)
index 946f36f326459e38708ed06b6ae598259f1b0f14..7360f50743ebd76d1fe8cf489cb6abc25da9a2c5 100644 (file)
@@ -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)
index 8eb98c71f82f2201dc135302d0a8421db579e54c..8b01b8cbc6b4313da655cff17912db4730bba5b4 100644 (file)
@@ -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))
index 1691a8f788027b159ca078d40f4decbf97dcaa41..e12e9015d975cb0a168af7374a6cea0985f391c9 100644 (file)
@@ -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
index 434613d495773988fb7cdc0273b5d10a2ca8b776..f12fa5f02f09f612417625bb6dcb9e9329b9bd01 100644 (file)
@@ -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
index 340791139b491b2ac36c446e90c16e0f92597db7..c3dc144d3d6284678b9fc2f8fc29c7c55fcbeaeb 100644 (file)
@@ -31,6 +31,7 @@ type Ctx struct {
 
        Spool      string
        LogPath    string
+       Quiet      bool
        Debug      bool
        NotifyFile *FromToYAML
        NotifyFreq *FromToYAML
index 87a20c2f6032e2f9f8ac52ae6105b527a91df5d8..6fda35899fb17a24aa61b6072bdfbb79bec071cd 100644 (file)
@@ -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":
index c3d5872a6e7b89f63ecbf43ed2d2616de1eb2070..f37d949b29acc144f1852f86b26730d0e344db07 100644 (file)
@@ -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) {