"io/ioutil"
"log"
"os"
+ "time"
"cypherpunks.ru/nncp"
)
func usage() {
fmt.Fprintf(os.Stderr, nncp.UsageHeader())
fmt.Fprintln(os.Stderr, "nncp-toss -- process inbound packets\n")
- fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:", os.Args[0])
+ fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:\n", os.Args[0])
flag.PrintDefaults()
}
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")
- debug = flag.Bool("debug", false, "Enable debugging information")
+ 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")
warranty = flag.Bool("warranty", false, "Print warranty information")
)
}
nice := uint8(*niceRaw)
- cfgRaw, err := ioutil.ReadFile(*cfgPath)
+ cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
if err != nil {
log.Fatalln("Can not read config:", err)
}
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
var nodeOnly *nncp.Node
}
}
+Cycle:
+ isBad := false
for nodeId, node := range ctx.Neigh {
if nodeOnly != nil && nodeId != *nodeOnly.Id {
continue
}
- 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)
}
}