]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/toss.go
AutoToss every second, not after call is finished
[nncp.git] / src / toss.go
index f70ffd3dd7674051af5cc74c5a7d5b0a8061ce3e..8e8dc27789b0e741432be27498433faee69827c8 100644 (file)
@@ -33,6 +33,7 @@ import (
        "path/filepath"
        "strconv"
        "strings"
+       "time"
 
        xdr "github.com/davecgh/go-xdr/xdr2"
        "github.com/dustin/go-humanize"
@@ -426,3 +427,26 @@ func (ctx *Ctx) Toss(
        }
        return isBad
 }
+
+func (ctx *Ctx) AutoToss(
+       nodeId *NodeId,
+       nice uint8,
+       doSeen, noFile, noFreq, noExec, noTrns bool,
+) (chan struct{}, chan bool) {
+       finish := make(chan struct{})
+       badCode := make(chan bool)
+       go func() {
+               bad := false
+               for {
+                       select {
+                       case <-finish:
+                               badCode <- bad
+                               break
+                       default:
+                       }
+                       time.Sleep(time.Second)
+                       bad = !ctx.Toss(nodeId, nice, false, doSeen, noFile, noFreq, noExec, noTrns)
+               }
+       }()
+       return finish, badCode
+}