]> Cypherpunks.ru repositories - nncp.git/commitdiff
nncp-toss -cycle option
authorSergey Matveev <stargrave@stargrave.org>
Mon, 16 Jan 2017 09:26:42 +0000 (12:26 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 16 Jan 2017 09:26:42 +0000 (12:26 +0300)
doc/cmds.texi
src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go

index 54348c832cf67ea0bbc0e38a6087ea63119a3e34..9097044773b37c88ff414284f7ca60856fdd3870 100644 (file)
@@ -235,7 +235,7 @@ queues.
 @section nncp-toss
 
 @verbatim
-% nncp-toss [options] [-dryrun]
+% nncp-toss [options] [-dryrun] [-cycle INT]
 @end verbatim
 
 Perform "tossing" operation on all inbound packets. This is the tool
@@ -246,6 +246,10 @@ packets. It should be run after each online/offline exchange.
 @option{-dryrun} option does not perform any writing and sending, just
 tells what it will do.
 
+@option{-cycle} option tells not to quit, but to repeat tossing every
+@option{INT} seconds in an infinite loop. That can be useful when
+running this command as a daemon.
+
 @node nncp-xfer
 @section nncp-xfer
 
index 5fd73b3f6afd2728c8aa058da0e1949c0a4a2482..11066956a3fcbbc6b9495158fa4d6a2cb41ac059 100644 (file)
@@ -25,6 +25,7 @@ import (
        "io/ioutil"
        "log"
        "os"
+       "time"
 
        "cypherpunks.ru/nncp"
 )
@@ -42,6 +43,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")
+               cycle    = flag.Uint("cycle", 0, "Repeat tossing after N seconds in infinite loop")
                quiet    = flag.Bool("quiet", false, "Print only errors")
                debug    = flag.Bool("debug", false, "Print debug messages")
                version  = flag.Bool("version", false, "Print version information")
@@ -81,6 +83,7 @@ func main() {
                }
        }
 
+Cycle:
        isBad := false
        for nodeId, node := range ctx.Neigh {
                if nodeOnly != nil && nodeId != *nodeOnly.Id {
@@ -88,6 +91,10 @@ func main() {
                }
                isBad = ctx.Toss(node.Id, nice, *dryRun)
        }
+       if *cycle > 0 {
+               time.Sleep(time.Duration(*cycle) * time.Second)
+               goto Cycle
+       }
        if isBad {
                os.Exit(1)
        }