]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cmd/nncp-call/main.go
Autotoss ability
[nncp.git] / src / cmd / nncp-call / main.go
index ae6bffeb39b7f997e3cf5e45d952b3964c28a840..52e0fcb2887dd8a247d7e057ed20ca30463b0c8a 100644 (file)
@@ -1,6 +1,6 @@
 /*
 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2020 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
@@ -58,6 +58,13 @@ func main() {
 
                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()
@@ -142,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)
                        }
@@ -153,7 +160,7 @@ func main() {
        }
 
        ctx.Umask()
-       if !ctx.CallNode(
+       badCode := !ctx.CallNode(
                node,
                addrs,
                nice,
@@ -164,7 +171,20 @@ func main() {
                maxOnlineTime,
                *listOnly,
                onlyPkts,
-       ) {
+       )
+       if *autotoss {
+               badCode = ctx.Toss(
+                       node.Id,
+                       nice,
+                       false,
+                       *autotossDoSeen,
+                       *autotossNoFile,
+                       *autotossNoFreq,
+                       *autotossNoExec,
+                       *autotossNoTrns,
+               ) || badCode
+       }
+       if badCode {
                os.Exit(1)
        }
 }