From: Sergey Matveev Date: Sun, 17 Jan 2021 15:20:21 +0000 (+0300) Subject: AutoToss every second, not after call is finished X-Git-Tag: v5.6.0^2~4 X-Git-Url: http://www.git.cypherpunks.ru/?p=nncp.git;a=commitdiff_plain;h=cda0acc2c336734be25a7cdb3e79000486fc5901 AutoToss every second, not after call is finished --- diff --git a/doc/cmds.texi b/doc/cmds.texi index 9c74dff..05ffe54 100644 --- a/doc/cmds.texi +++ b/doc/cmds.texi @@ -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 diff --git a/doc/news.ru.texi b/doc/news.ru.texi index 111645e..9edf2aa 100644 --- a/doc/news.ru.texi +++ b/doc/news.ru.texi @@ -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 diff --git a/doc/news.texi b/doc/news.texi index e8744e4..624143d 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -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 diff --git a/src/cmd/nncp-call/main.go b/src/cmd/nncp-call/main.go index 52e0fcb..9762d92 100644 --- a/src/cmd/nncp-call/main.go +++ b/src/cmd/nncp-call/main.go @@ -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) diff --git a/src/cmd/nncp-caller/main.go b/src/cmd/nncp-caller/main.go index 421f0fa..0a549e4 100644 --- a/src/cmd/nncp-caller/main.go +++ b/src/cmd/nncp-caller/main.go @@ -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() diff --git a/src/cmd/nncp-daemon/main.go b/src/cmd/nncp-daemon/main.go index b7aceb7..b2b8911 100644 --- a/src/cmd/nncp-daemon/main.go +++ b/src/cmd/nncp-daemon/main.go @@ -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) } } diff --git a/src/nncp.go b/src/nncp.go index b351b25..f8915d9 100644 --- a/src/nncp.go +++ b/src/nncp.go @@ -38,7 +38,7 @@ along with this program. If not, see .` ) var ( - Version string = "5.5.1" + Version string = "5.6.0" Base32Codec *base32.Encoding = base32.StdEncoding.WithPadding(base32.NoPadding) ) diff --git a/src/toss.go b/src/toss.go index f70ffd3..8e8dc27 100644 --- a/src/toss.go +++ b/src/toss.go @@ -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 +}