]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cmd/nncp-call/main.go
Autotoss ability
[nncp.git] / src / cmd / nncp-call / main.go
index 0072e982e22345fe250e49edb0e0dfdfca2644e1..52e0fcb2887dd8a247d7e057ed20ca30463b0c8a 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-2021 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,6 +24,7 @@ import (
        "log"
        "os"
        "strings"
+       "time"
 
        "go.cypherpunks.ru/nncp/v5"
 )
@@ -55,8 +56,15 @@ func main() {
                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")
        )
        flag.Usage = usage
        flag.Parse()
@@ -105,11 +113,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
@@ -139,7 +149,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)
                        }
@@ -150,18 +160,31 @@ func main() {
        }
 
        ctx.Umask()
-       if !ctx.CallNode(
+       badCode := !ctx.CallNode(
                node,
                addrs,
                nice,
                xxOnly,
                *rxRate,
                *txRate,
-               *onlineDeadline,
-               *maxOnlineTime,
+               onlineDeadline,
+               maxOnlineTime,
                *listOnly,
                onlyPkts,
-       ) {
+       )
+       if *autotoss {
+               badCode = ctx.Toss(
+                       node.Id,
+                       nice,
+                       false,
+                       *autotossDoSeen,
+                       *autotossNoFile,
+                       *autotossNoFreq,
+                       *autotossNoExec,
+                       *autotossNoTrns,
+               ) || badCode
+       }
+       if badCode {
                os.Exit(1)
        }
 }