]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go
Documentation updates
[nncp.git] / src / cypherpunks.ru / nncp / cmd / nncp-toss / main.go
index 7bdffb6d74e42ab8b96f520e3a959bc6b71d2229..9b50866e8198cc78330a459835fc6fc3751f781b 100644 (file)
@@ -1,5 +1,5 @@
 /*
-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
@@ -32,7 +32,7 @@ import (
 func usage() {
        fmt.Fprintf(os.Stderr, nncp.UsageHeader())
        fmt.Fprintln(os.Stderr, "nncp-toss -- process inbound packets\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()
 }
 
@@ -41,7 +41,9 @@ func main() {
                cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
                nodeRaw  = flag.String("node", "", "Process only that node")
                niceRaw  = flag.Int("nice", 255, "Minimal required niceness")
-               debug    = flag.Bool("debug", false, "Enable debugging information")
+               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, "Print debug messages")
                version  = flag.Bool("version", false, "Print version information")
                warranty = flag.Bool("warranty", false, "Print warranty information")
        )
@@ -68,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
@@ -78,10 +81,14 @@ func main() {
                }
        }
 
+       isBad := false
        for nodeId, node := range ctx.Neigh {
                if nodeOnly != nil && nodeId != *nodeOnly.Id {
                        continue
                }
-               ctx.Toss(node.Id, nice)
+               isBad = ctx.Toss(node.Id, nice, *dryRun)
+       }
+       if isBad {
+               os.Exit(1)
        }
 }