]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cmd/nncp-caller/main.go
Intermediate .nock packets step
[nncp.git] / src / cmd / nncp-caller / main.go
index 421f0faa08d3593c94933dfb76f3b7776aa1584f..7ccefdd7a56b7eb622bb03665ef54c3d8a44e524 100644 (file)
@@ -49,13 +49,6 @@ func main() {
                debug     = flag.Bool("debug", false, "Print debug messages")
                version   = flag.Bool("version", false, "Print version information")
                warranty  = flag.Bool("warranty", false, "Print warranty information")
-
-               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()
@@ -93,7 +86,7 @@ func main() {
                                log.Fatalln("Invalid NODE specified:", err)
                        }
                        if len(node.Calls) == 0 {
-                               ctx.LogD("caller", nncp.SDS{"node": node.Id}, "has no calls, skipping")
+                               ctx.LogD("caller", nncp.LEs{{K: "Node", V: node.Id}}, "has no calls, skipping")
                                continue
                        }
                        nodes = append(nodes, node)
@@ -101,7 +94,7 @@ func main() {
        } else {
                for _, node := range ctx.Neigh {
                        if len(node.Calls) == 0 {
-                               ctx.LogD("caller", nncp.SDS{"node": node.Id}, "has no calls, skipping")
+                               ctx.LogD("caller", nncp.LEs{{K: "Node", V: node.Id}}, "has no calls, skipping")
                                continue
                        }
                        nodes = append(nodes, node)
@@ -122,24 +115,57 @@ func main() {
                                } else {
                                        addrs = append(addrs, *call.Addr)
                                }
-                               sds := nncp.SDS{"node": node.Id, "callindex": i}
+                               les := nncp.LEs{{K: "Node", V: node.Id}, {K: "CallIndex", V: i}}
                                for {
                                        n := time.Now()
                                        t := call.Cron.Next(n)
-                                       ctx.LogD("caller", sds, t.String())
+                                       ctx.LogD("caller", les, t.String())
                                        if t.IsZero() {
-                                               ctx.LogE("caller", sds, errors.New("got zero time"), "")
+                                               ctx.LogE("caller", les, errors.New("got zero time"), "")
                                                return
                                        }
                                        time.Sleep(t.Sub(n))
                                        node.Lock()
                                        if node.Busy {
                                                node.Unlock()
-                                               ctx.LogD("caller", sds, "busy")
+                                               ctx.LogD("caller", les, "busy")
                                                continue
                                        } else {
                                                node.Busy = true
                                                node.Unlock()
+
+                                               if call.WhenTxExists && call.Xx != "TRx" {
+                                                       ctx.LogD("caller", les, "checking tx existence")
+                                                       txExists := false
+                                                       for job := range ctx.Jobs(node.Id, nncp.TTx) {
+                                                               if job.PktEnc.Nice > call.Nice {
+                                                                       continue
+                                                               }
+                                                               txExists = true
+                                                       }
+                                                       if !txExists {
+                                                               ctx.LogD("caller", les, "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,
@@ -150,19 +176,13 @@ func main() {
                                                        call.OnlineDeadline,
                                                        call.MaxOnlineTime,
                                                        false,
+                                                       call.NoCK,
                                                        nil,
                                                )
-                                               if *autotoss {
-                                                       ctx.Toss(
-                                                               node.Id,
-                                                               call.Nice,
-                                                               false,
-                                                               *autotossDoSeen,
-                                                               *autotossNoFile,
-                                                               *autotossNoFreq,
-                                                               *autotossNoExec,
-                                                               *autotossNoTrns,
-                                                       )
+
+                                               if call.AutoToss {
+                                                       close(autoTossFinish)
+                                                       <-autoTossBadCode
                                                }
 
                                                node.Lock()