]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/cmd/nncp-toss/main.go
Ability to create and deal with .seen files after tossing
[nncp.git] / src / cypherpunks.ru / nncp / cmd / nncp-toss / main.go
index 5fd73b3f6afd2728c8aa058da0e1949c0a4a2482..12dc214d8a4b7e77029dcfb6034640ae8edbaffe 100644 (file)
@@ -25,6 +25,7 @@ import (
        "io/ioutil"
        "log"
        "os"
+       "time"
 
        "cypherpunks.ru/nncp"
 )
@@ -42,6 +43,8 @@ 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")
+               doSeen   = flag.Bool("seen", false, "Create .seen files")
+               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")
@@ -70,6 +73,9 @@ func main() {
        if err != nil {
                log.Fatalln("Can not parse config:", err)
        }
+       if ctx.Self == nil {
+               log.Fatalln("Config lacks private keys")
+       }
        ctx.Quiet = *quiet
        ctx.Debug = *debug
 
@@ -81,12 +87,17 @@ func main() {
                }
        }
 
+Cycle:
        isBad := false
        for nodeId, node := range ctx.Neigh {
                if nodeOnly != nil && nodeId != *nodeOnly.Id {
                        continue
                }
-               isBad = ctx.Toss(node.Id, nice, *dryRun)
+               isBad = ctx.Toss(node.Id, nice, *dryRun, *doSeen)
+       }
+       if *cycle > 0 {
+               time.Sleep(time.Duration(*cycle) * time.Second)
+               goto Cycle
        }
        if isBad {
                os.Exit(1)