]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cmd/nncp-caller/main.go
On demand calling
[nncp.git] / src / cmd / nncp-caller / main.go
index 7297350d41b746efa23eb5380726eac15c19e2a9..f7ab13c23299cc301608920776df84f417266042 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
@@ -133,6 +133,40 @@ func main() {
                                        } else {
                                                node.Busy = true
                                                node.Unlock()
+
+                                               if call.WhenTxExists && call.Xx != "TRx" {
+                                                       ctx.LogD("caller", sds, "checking tx existence")
+                                                       txExists := false
+                                                       for job := range ctx.Jobs(node.Id, nncp.TTx) {
+                                                               job.Fd.Close()
+                                                               if job.PktEnc.Nice > call.Nice {
+                                                                       continue
+                                                               }
+                                                               txExists = true
+                                                       }
+                                                       if !txExists {
+                                                               ctx.LogD("caller", sds, "no tx")
+                                                               node.Lock()
+                                                               node.Busy = false
+                                                               node.Unlock()
+                                                               continue
+                                                       }
+                                               }
+
+                                               var autoTossFinish chan struct{}
+                                               var autoTossBadCode chan bool
+                                               if call.AutoToss {
+                                                       autoTossFinish, autoTossBadCode = ctx.AutoToss(
+                                                               node.Id,
+                                                               call.Nice,
+                                                               call.AutoTossDoSeen,
+                                                               call.AutoTossNoFile,
+                                                               call.AutoTossNoFreq,
+                                                               call.AutoTossNoExec,
+                                                               call.AutoTossNoTrns,
+                                                       )
+                                               }
+
                                                ctx.CallNode(
                                                        node,
                                                        addrs,
@@ -145,6 +179,12 @@ func main() {
                                                        false,
                                                        nil,
                                                )
+
+                                               if call.AutoToss {
+                                                       close(autoTossFinish)
+                                                       <-autoTossBadCode
+                                               }
+
                                                node.Lock()
                                                node.Busy = false
                                                node.Unlock()