X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fnncp-daemon%2Fmain.go;h=252527f56a1520044d681419e1d7e10967768729;hb=0367cce2741e1ce6a89a49fd5c4e9df6005c9744;hp=39f2bbada1477935d610281c9036f50a7123e4af;hpb=0fad171c0d79ad583c0faf5427e22d1d62a0a52d;p=nncp.git diff --git a/src/cmd/nncp-daemon/main.go b/src/cmd/nncp-daemon/main.go index 39f2bba..252527f 100644 --- a/src/cmd/nncp-daemon/main.go +++ b/src/cmd/nncp-daemon/main.go @@ -1,6 +1,6 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2021 Sergey Matveev +Copyright (C) 2016-2022 Sergey Matveev 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 @@ -29,7 +29,7 @@ import ( "time" "github.com/dustin/go-humanize" - "go.cypherpunks.ru/nncp/v7" + "go.cypherpunks.ru/nncp/v8" "golang.org/x/net/netutil" ) @@ -40,35 +40,6 @@ func usage() { flag.PrintDefaults() } -type InetdConn struct { - r *os.File - w *os.File -} - -func (c InetdConn) Read(p []byte) (n int, err error) { - return c.r.Read(p) -} - -func (c InetdConn) Write(p []byte) (n int, err error) { - return c.w.Write(p) -} - -func (c InetdConn) SetReadDeadline(t time.Time) error { - return c.r.SetReadDeadline(t) -} - -func (c InetdConn) SetWriteDeadline(t time.Time) error { - return c.w.SetWriteDeadline(t) -} - -func (c InetdConn) Close() error { - if err := c.r.Close(); err != nil { - c.w.Close() // #nosec G104 - return err - } - return c.w.Close() -} - func performSP( ctx *nncp.Ctx, conn nncp.ConnDeadlined, @@ -105,7 +76,7 @@ func performSP( state.Node.Name, int(state.Duration.Hours()), int(state.Duration.Minutes()), - int(state.Duration.Seconds()/60), + int(state.Duration.Seconds())%60, humanize.IBytes(uint64(state.RxBytes)), humanize.IBytes(uint64(state.RxSpeed)), humanize.IBytes(uint64(state.TxBytes)), @@ -138,7 +109,8 @@ func main() { cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file") niceRaw = flag.String("nice", nncp.NicenessFmt(255), "Minimal required niceness") bind = flag.String("bind", "[::]:5400", "Address to bind to") - inetd = flag.Bool("inetd", false, "Is it started as inetd service") + ucspi = flag.Bool("ucspi", false, "Is it started as UCSPI-TCP server") + inetd = flag.Bool("inetd", false, "Obsolete, use -ucspi") maxConn = flag.Int("maxconn", 128, "Maximal number of simultaneous connections") noCK = flag.Bool("nock", false, "Do no checksum checking") mcdOnce = flag.Bool("mcd-once", false, "Send MCDs once and quit") @@ -152,11 +124,12 @@ func main() { 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") + 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") + autoTossNoArea = flag.Bool("autotoss-noarea", false, "Do not process \"area\" packets during tossing") ) log.SetFlags(log.Lshortfile) flag.Usage = usage @@ -173,6 +146,9 @@ func main() { if err != nil { log.Fatalln(err) } + if *inetd { + *ucspi = true + } ctx, err := nncp.CtxFromCmdline( *cfgPath, @@ -191,11 +167,15 @@ func main() { } ctx.Umask() - if *inetd { - os.Stderr.Close() // #nosec G104 - conn := &InetdConn{os.Stdin, os.Stdout} + if *ucspi { + os.Stderr.Close() + conn := &nncp.UCSPIConn{R: os.Stdin, W: os.Stdout} nodeIdC := make(chan *nncp.NodeId) - go performSP(ctx, conn, "PIPE", nice, *noCK, nodeIdC) + addr := nncp.UCSPITCPRemoteAddr() + if addr == "" { + addr = "PIPE" + } + go performSP(ctx, conn, addr, nice, *noCK, nodeIdC) nodeId := <-nodeIdC var autoTossFinish chan struct{} var autoTossBadCode chan bool @@ -208,6 +188,7 @@ func main() { *autoTossNoFreq, *autoTossNoExec, *autoTossNoTrns, + *autoTossNoArea, ) } <-nodeIdC // call completion @@ -215,7 +196,7 @@ func main() { close(autoTossFinish) <-autoTossBadCode } - conn.Close() // #nosec G104 + conn.Close() return } @@ -273,6 +254,7 @@ func main() { *autoTossNoFreq, *autoTossNoExec, *autoTossNoTrns, + *autoTossNoArea, ) } <-nodeIdC // call completion @@ -280,7 +262,7 @@ func main() { close(autoTossFinish) <-autoTossBadCode } - conn.Close() // #nosec G104 + conn.Close() }(conn) } }