]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cmd/nncp-call/main.go
Raise copyright years
[nncp.git] / src / cmd / nncp-call / main.go
index 07deec1ca4f893e88a379ced3c6dc745f6be4bcf..077a907fdcd45761de28ac2bcf1629415bcb954f 100644 (file)
@@ -1,6 +1,6 @@
 /*
 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2019 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2022 Sergey Matveev <stargrave@stargrave.org>
 
 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
@@ -24,8 +24,9 @@ import (
        "log"
        "os"
        "strings"
+       "time"
 
-       "go.cypherpunks.ru/nncp/v5"
+       "go.cypherpunks.ru/nncp/v8"
 )
 
 func usage() {
@@ -39,23 +40,36 @@ func usage() {
 func main() {
        var (
                cfgPath     = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               ucspi       = flag.Bool("ucspi", false, "Is it started as UCSPI-TCP client")
                niceRaw     = flag.String("nice", nncp.NicenessFmt(255), "Minimal required niceness")
                rxOnly      = flag.Bool("rx", false, "Only receive packets")
                txOnly      = flag.Bool("tx", false, "Only transmit packets")
                listOnly    = flag.Bool("list", false, "Only list remote packets")
+               noCK        = flag.Bool("nock", false, "Do no checksum checking")
                onlyPktsRaw = flag.String("pkts", "", "Recieve only that packets, comma separated")
                rxRate      = flag.Int("rxrate", 0, "Maximal receive rate, pkts/sec")
                txRate      = flag.Int("txrate", 0, "Maximal transmit rate, pkts/sec")
                spoolPath   = flag.String("spool", "", "Override path to spool")
                logPath     = flag.String("log", "", "Override path to logfile")
                quiet       = flag.Bool("quiet", false, "Print only errors")
+               showPrgrs   = flag.Bool("progress", false, "Force progress showing")
+               omitPrgrs   = flag.Bool("noprogress", false, "Omit progress showing")
                debug       = flag.Bool("debug", false, "Print debug messages")
                version     = flag.Bool("version", false, "Print version information")
                warranty    = flag.Bool("warranty", false, "Print warranty information")
 
-               onlineDeadline = flag.Uint("onlinedeadline", 0, "Override onlinedeadline option")
-               maxOnlineTime  = flag.Uint("maxonlinetime", 0, "Override maxonlinetime option")
+               onlineDeadlineSec = flag.Uint("onlinedeadline", 0, "Override onlinedeadline option")
+               maxOnlineTimeSec  = flag.Uint("maxonlinetime", 0, "Override maxonlinetime option")
+
+               autoToss       = flag.Bool("autotoss", false, "Toss after call is finished")
+               autoTossDoSeen = flag.Bool("autotoss-seen", false, "Create seen/ files during tossing")
+               autoTossNoFile = flag.Bool("autotoss-nofile", false, "Do not process \"file\" packets during tossing")
+               autoTossNoFreq = flag.Bool("autotoss-nofreq", false, "Do not process \"freq\" packets during tossing")
+               autoTossNoExec = flag.Bool("autotoss-noexec", false, "Do not process \"exec\" packets during tossing")
+               autoTossNoTrns = flag.Bool("autotoss-notrns", false, "Do not process \"trns\" packets during tossing")
+               autoTossNoArea = flag.Bool("autotoss-noarea", false, "Do not process \"area\" packets during tossing")
        )
+       log.SetFlags(log.Lshortfile)
        flag.Usage = usage
        flag.Parse()
        if *warranty {
@@ -78,7 +92,15 @@ func main() {
                log.Fatalln("-rx and -tx can not be set simultaneously")
        }
 
-       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
+       ctx, err := nncp.CtxFromCmdline(
+               *cfgPath,
+               *spoolPath,
+               *logPath,
+               *quiet,
+               *showPrgrs,
+               *omitPrgrs,
+               *debug,
+       )
        if err != nil {
                log.Fatalln("Error during initialization:", err)
        }
@@ -95,11 +117,13 @@ func main() {
                log.Fatalln("Node does not have online communication capability")
        }
 
-       if *onlineDeadline == 0 {
-               onlineDeadline = &node.OnlineDeadline
+       onlineDeadline := node.OnlineDeadline
+       if *onlineDeadlineSec != 0 {
+               onlineDeadline = time.Duration(*onlineDeadlineSec) * time.Second
        }
-       if *maxOnlineTime == 0 {
-               maxOnlineTime = &node.MaxOnlineTime
+       maxOnlineTime := node.MaxOnlineTime
+       if *maxOnlineTimeSec != 0 {
+               maxOnlineTime = time.Duration(*maxOnlineTimeSec) * time.Second
        }
 
        var xxOnly nncp.TRxTx
@@ -110,7 +134,9 @@ func main() {
        }
 
        var addrs []string
-       if flag.NArg() == 2 {
+       if *ucspi {
+               addrs = append(addrs, nncp.UCSPITCPClient)
+       } else if flag.NArg() == 2 {
                addrs = append(addrs, flag.Arg(1))
        } else if len(splitted) == 2 {
                addr, known := ctx.Neigh[*node.Id].Addrs[splitted[1]]
@@ -129,7 +155,7 @@ func main() {
                splitted = strings.Split(*onlyPktsRaw, ",")
                onlyPkts = make(map[[32]byte]bool, len(splitted))
                for _, pktIdRaw := range splitted {
-                       pktId, err := nncp.FromBase32(pktIdRaw)
+                       pktId, err := nncp.Base32Codec.DecodeString(pktIdRaw)
                        if err != nil {
                                log.Fatalln("Invalid packet specified: ", err)
                        }
@@ -139,18 +165,43 @@ func main() {
                }
        }
 
-       if !ctx.CallNode(
+       ctx.Umask()
+
+       var autoTossFinish chan struct{}
+       var autoTossBadCode chan bool
+       if *autoToss {
+               autoTossFinish, autoTossBadCode = ctx.AutoToss(
+                       node.Id,
+                       nice,
+                       *autoTossDoSeen,
+                       *autoTossNoFile,
+                       *autoTossNoFreq,
+                       *autoTossNoExec,
+                       *autoTossNoTrns,
+                       *autoTossNoArea,
+               )
+       }
+
+       badCode := !ctx.CallNode(
                node,
                addrs,
                nice,
                xxOnly,
                *rxRate,
                *txRate,
-               *onlineDeadline,
-               *maxOnlineTime,
+               onlineDeadline,
+               maxOnlineTime,
                *listOnly,
+               *noCK,
                onlyPkts,
-       ) {
+       )
+
+       if *autoToss {
+               close(autoTossFinish)
+               badCode = (<-autoTossBadCode) || badCode
+       }
+       nncp.SPCheckerWg.Wait()
+       if badCode {
                os.Exit(1)
        }
 }