]> Cypherpunks.ru repositories - nncp.git/commitdiff
AutoToss every second, not after call is finished
authorSergey Matveev <stargrave@stargrave.org>
Sun, 17 Jan 2021 15:20:21 +0000 (18:20 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 17 Jan 2021 16:38:55 +0000 (19:38 +0300)
doc/cmds.texi
doc/news.ru.texi
doc/news.texi
src/cmd/nncp-call/main.go
src/cmd/nncp-caller/main.go
src/cmd/nncp-daemon/main.go
src/nncp.go
src/toss.go

index 9c74dffa463510f94109dd5ebeb1301359e7ef44..05ffe54c479c3b0e41924731c5e0d54745a48444 100644 (file)
@@ -139,8 +139,8 @@ file is renamed from @file{.part} one and when you rerun
 @command{nncp-call} again, remote node will receive completion
 notification.
 
-@option{-autotoss} options runs tosser on node's spool after call
-is finished. All @option{-autotoss-*} options is the same as in
+@option{-autotoss} option runs tosser on node's spool every second
+during the call. All @option{-autotoss-*} options is the same as in
 @ref{nncp-toss} command.
 
 @node nncp-caller
@@ -264,8 +264,8 @@ Example inetd-entry:
 uucp   stream  tcp6    nowait  nncpuser        /usr/local/bin/nncp-daemon      nncp-daemon -quiet -inetd
 @end verbatim
 
-@option{-autotoss} options runs tosser on node's spool after call
-is finished. All @option{-autotoss-*} options is the same as in
+@option{-autotoss} option runs tosser on node's spool every second
+during the call. All @option{-autotoss-*} options is the same as in
 @ref{nncp-toss} command.
 
 @node nncp-exec
index 111645ef0f5bdf5b4cd7decea4565e6bde4f2127..9edf2aa445fcf3da811e1e9cbda9f45c108a68dd 100644 (file)
@@ -1,6 +1,16 @@
 @node Новости
 @section Новости
 
+@node Релиз 5.6.0
+@subsection Релиз 5.6.0
+@itemize
+
+@item
+@option{-autotoss*} опции запускают tosser не после завершения вызова, а
+во время него ежесекундно.
+
+@end itemize
+
 @node Релиз 5.5.1
 @subsection Релиз 5.5.1
 @itemize
index e8744e40e0be12fcbb51079e3b9df87462943994..624143d5db6710f49c35d42c20e737dfcbaec61f 100644 (file)
@@ -3,6 +3,16 @@
 
 See also this page @ref{Новости, on russian}.
 
+@node Release 5.6.0
+@section Release 5.6.0
+@itemize
+
+@item
+@option{-autotoss*} option runs tosser not after the call, but every
+second while it is active.
+
+@end itemize
+
 @node Release 5.5.1
 @section Release 5.5.1
 @itemize
index 52e0fcb2887dd8a247d7e057ed20ca30463b0c8a..9762d9216cd950f00390d1ea9a2ba1422eeb03a5 100644 (file)
@@ -59,12 +59,12 @@ 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")
+               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()
@@ -160,6 +160,21 @@ func main() {
        }
 
        ctx.Umask()
+
+       var autoTossFinish chan struct{}
+       var autoTossBadCode chan bool
+       if *autoToss {
+               autoTossFinish, autoTossBadCode = ctx.AutoToss(
+                       node.Id,
+                       nice,
+                       *autoTossDoSeen,
+                       *autoTossNoFile,
+                       *autoTossNoFreq,
+                       *autoTossNoExec,
+                       *autoTossNoTrns,
+               )
+       }
+
        badCode := !ctx.CallNode(
                node,
                addrs,
@@ -172,17 +187,10 @@ func main() {
                *listOnly,
                onlyPkts,
        )
-       if *autotoss {
-               badCode = ctx.Toss(
-                       node.Id,
-                       nice,
-                       false,
-                       *autotossDoSeen,
-                       *autotossNoFile,
-                       *autotossNoFreq,
-                       *autotossNoExec,
-                       *autotossNoTrns,
-               ) || badCode
+
+       if *autoToss {
+               close(autoTossFinish)
+               badCode = (<-autoTossBadCode) || badCode
        }
        if badCode {
                os.Exit(1)
index 421f0faa08d3593c94933dfb76f3b7776aa1584f..0a549e45e870c588c4d856a79a5be4771bd897ec 100644 (file)
@@ -50,12 +50,12 @@ func main() {
                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")
+               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()
@@ -140,6 +140,21 @@ func main() {
                                        } else {
                                                node.Busy = true
                                                node.Unlock()
+
+                                               var autoTossFinish chan struct{}
+                                               var autoTossBadCode chan bool
+                                               if *autoToss {
+                                                       autoTossFinish, autoTossBadCode = ctx.AutoToss(
+                                                               node.Id,
+                                                               call.Nice,
+                                                               *autoTossDoSeen,
+                                                               *autoTossNoFile,
+                                                               *autoTossNoFreq,
+                                                               *autoTossNoExec,
+                                                               *autoTossNoTrns,
+                                                       )
+                                               }
+
                                                ctx.CallNode(
                                                        node,
                                                        addrs,
@@ -152,17 +167,10 @@ func main() {
                                                        false,
                                                        nil,
                                                )
-                                               if *autotoss {
-                                                       ctx.Toss(
-                                                               node.Id,
-                                                               call.Nice,
-                                                               false,
-                                                               *autotossDoSeen,
-                                                               *autotossNoFile,
-                                                               *autotossNoFreq,
-                                                               *autotossNoExec,
-                                                               *autotossNoTrns,
-                                                       )
+
+                                               if *autoToss {
+                                                       close(autoTossFinish)
+                                                       <-autoTossBadCode
                                                }
 
                                                node.Lock()
index b7aceb75e11f90eb1f99f26c7da7915c981739b8..b2b8911ec21b2abbbc6daaf30b40d253d7b9fcc0 100644 (file)
@@ -66,13 +66,19 @@ func (c InetdConn) Close() error {
        return c.w.Close()
 }
 
-func performSP(ctx *nncp.Ctx, conn nncp.ConnDeadlined, nice uint8) *nncp.SPState {
+func performSP(
+       ctx *nncp.Ctx,
+       conn nncp.ConnDeadlined,
+       nice uint8,
+       nodeIdC chan *nncp.NodeId,
+) {
        state := nncp.SPState{
                Ctx:  ctx,
                Nice: nice,
        }
        if err := state.StartR(conn); err == nil {
                ctx.LogI("call-start", nncp.SDS{"node": state.Node.Id}, "connected")
+               nodeIdC <- state.Node.Id
                state.Wait()
                ctx.LogI("call-finish", nncp.SDS{
                        "node":     state.Node.Id,
@@ -84,12 +90,15 @@ func performSP(ctx *nncp.Ctx, conn nncp.ConnDeadlined, nice uint8) *nncp.SPState
                }, "")
        } else {
                nodeId := "unknown"
-               if state.Node != nil {
+               if state.Node == nil {
+                       nodeIdC <- nil
+               } else {
+                       nodeIdC <- state.Node.Id
                        nodeId = state.Node.Id.String()
                }
                ctx.LogE("call-start", nncp.SDS{"node": nodeId}, err, "")
        }
-       return &state
+       close(nodeIdC)
 }
 
 func main() {
@@ -108,12 +117,12 @@ func main() {
                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")
+               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()
@@ -150,7 +159,10 @@ func main() {
        if *inetd {
                os.Stderr.Close() // #nosec G104
                conn := &InetdConn{os.Stdin, os.Stdout}
-               performSP(ctx, conn, nice)
+               nodeIdC := make(chan *nncp.NodeId)
+               go performSP(ctx, conn, nice, nodeIdC)
+               <-nodeIdC    // nodeId
+               <-nodeIdC    // call completion
                conn.Close() // #nosec G104
                return
        }
@@ -167,20 +179,28 @@ func main() {
                }
                ctx.LogD("daemon", nncp.SDS{"addr": conn.RemoteAddr()}, "accepted")
                go func(conn net.Conn) {
-                       state := performSP(ctx, conn, nice)
-                       conn.Close() // #nosec G104
-                       if *autotoss && state.Node != nil {
-                               ctx.Toss(
-                                       state.Node.Id,
+                       nodeIdC := make(chan *nncp.NodeId)
+                       go performSP(ctx, conn, nice, nodeIdC)
+                       nodeId := <-nodeIdC
+                       var autoTossFinish chan struct{}
+                       var autoTossBadCode chan bool
+                       if *autoToss && nodeId != nil {
+                               autoTossFinish, autoTossBadCode = ctx.AutoToss(
+                                       nodeId,
                                        nice,
-                                       false,
-                                       *autotossDoSeen,
-                                       *autotossNoFile,
-                                       *autotossNoFreq,
-                                       *autotossNoExec,
-                                       *autotossNoTrns,
+                                       *autoTossDoSeen,
+                                       *autoTossNoFile,
+                                       *autoTossNoFreq,
+                                       *autoTossNoExec,
+                                       *autoTossNoTrns,
                                )
                        }
+                       <-nodeIdC // call completion
+                       if *autoToss {
+                               close(autoTossFinish)
+                               <-autoTossBadCode
+                       }
+                       conn.Close() // #nosec G104
                }(conn)
        }
 }
index b351b25390fd2b1d526940de53d933eb730154ec..f8915d9b5bf31bc5ba37f79568c29c8095531b6e 100644 (file)
@@ -38,7 +38,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.`
 )
 
 var (
-       Version string = "5.5.1"
+       Version string = "5.6.0"
 
        Base32Codec *base32.Encoding = base32.StdEncoding.WithPadding(base32.NoPadding)
 )
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
+}