X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fnncp-check%2Fmain.go;h=2c9eafb4b6a5469b6b77516bf439b9542663ec9b;hb=0367cce2741e1ce6a89a49fd5c4e9df6005c9744;hp=77fae4a87a515ff0cb1fd7718e739e235da389c6;hpb=04e3fde9391f487e67c67f7f12c019319490658f;p=nncp.git diff --git a/src/cmd/nncp-check/main.go b/src/cmd/nncp-check/main.go index 77fae4a..2c9eafb 100644 --- a/src/cmd/nncp-check/main.go +++ b/src/cmd/nncp-check/main.go @@ -1,6 +1,6 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2019 Sergey Matveev +Copyright (C) 2016-2022 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,19 +23,23 @@ import ( "fmt" "log" "os" + "path/filepath" + "time" - "go.cypherpunks.ru/nncp/v5" + "go.cypherpunks.ru/nncp/v8" ) func usage() { fmt.Fprintf(os.Stderr, nncp.UsageHeader()) fmt.Fprintf(os.Stderr, "nncp-check -- verify Rx/Tx packets checksum\n\n") - fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:\n", os.Args[0]) + fmt.Fprintf(os.Stderr, "Usage: %s [-nock] [options]\nOptions:\n", os.Args[0]) flag.PrintDefaults() } func main() { var ( + nock = flag.Bool("nock", false, "Process .nock files") + cycle = flag.Uint("cycle", 0, "Repeat check after N seconds in infinite loop") cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") nodeRaw = flag.String("node", "", "Process only that node") spoolPath = flag.String("spool", "", "Override path to spool") @@ -47,6 +51,7 @@ func main() { version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") ) + log.SetFlags(log.Lshortfile) flag.Usage = usage flag.Parse() if *warranty { @@ -80,15 +85,33 @@ func main() { } } +Cycle: isBad := false for nodeId, node := range ctx.Neigh { if nodeOnly != nil && nodeId != *nodeOnly.Id { continue } - if !ctx.Check(node.Id) { + if *nock { + for job := range ctx.JobsNoCK(node.Id) { + if _, err = ctx.CheckNoCK(node.Id, job.HshValue, nil); err != nil { + pktName := nncp.Base32Codec.EncodeToString(job.HshValue[:]) + log.Println(filepath.Join( + ctx.Spool, + nodeId.String(), + string(nncp.TRx), + pktName+nncp.NoCKSuffix, + ), err) + isBad = true + } + } + } else if !ctx.Check(node.Id) { isBad = true } } + if *cycle > 0 { + time.Sleep(time.Duration(*cycle) * time.Second) + goto Cycle + } if isBad { os.Exit(1) }