/*
NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2020 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
return c.w.Close()
}
-func performSP(ctx *nncp.Ctx, conn nncp.ConnDeadlined, nice uint8) {
+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,
}, "")
} 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, "")
}
+ close(nodeIdC)
}
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()
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
}
}
ctx.LogD("daemon", nncp.SDS{"addr": conn.RemoteAddr()}, "accepted")
go func(conn net.Conn) {
- performSP(ctx, conn, nice)
+ 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,
+ *autoTossDoSeen,
+ *autoTossNoFile,
+ *autoTossNoFreq,
+ *autoTossNoExec,
+ *autoTossNoTrns,
+ )
+ }
+ <-nodeIdC // call completion
+ if *autoToss {
+ close(autoTossFinish)
+ <-autoTossBadCode
+ }
conn.Close() // #nosec G104
}(conn)
}