X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fnncp-daemon%2Fmain.go;h=f27c2a371461b0dad558509be8a09f670c75b507;hb=9481faded654975d4bc0539412fd925a278b51bd;hp=b0628fe421a39c8ab37f21e8cb6f733d79b343c8;hpb=895d916d6bbd3c61b0209625e3a88f5f62f71a6d;p=nncp.git diff --git a/src/cmd/nncp-daemon/main.go b/src/cmd/nncp-daemon/main.go index b0628fe..f27c2a3 100644 --- a/src/cmd/nncp-daemon/main.go +++ b/src/cmd/nncp-daemon/main.go @@ -40,28 +40,28 @@ func usage() { flag.PrintDefaults() } -type InetdConn struct { +type UCSPIConn struct { r *os.File w *os.File } -func (c InetdConn) Read(p []byte) (n int, err error) { +func (c UCSPIConn) Read(p []byte) (n int, err error) { return c.r.Read(p) } -func (c InetdConn) Write(p []byte) (n int, err error) { +func (c UCSPIConn) Write(p []byte) (n int, err error) { return c.w.Write(p) } -func (c InetdConn) SetReadDeadline(t time.Time) error { +func (c UCSPIConn) SetReadDeadline(t time.Time) error { return c.r.SetReadDeadline(t) } -func (c InetdConn) SetWriteDeadline(t time.Time) error { +func (c UCSPIConn) SetWriteDeadline(t time.Time) error { return c.w.SetWriteDeadline(t) } -func (c InetdConn) Close() error { +func (c UCSPIConn) Close() error { if err := c.r.Close(); err != nil { c.w.Close() // #nosec G104 return err @@ -138,7 +138,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") @@ -174,6 +175,9 @@ func main() { if err != nil { log.Fatalln(err) } + if *inetd { + *ucspi = true + } ctx, err := nncp.CtxFromCmdline( *cfgPath, @@ -192,11 +196,20 @@ func main() { } ctx.Umask() - if *inetd { + if *ucspi { os.Stderr.Close() // #nosec G104 - conn := &InetdConn{os.Stdin, os.Stdout} + conn := &UCSPIConn{os.Stdin, os.Stdout} nodeIdC := make(chan *nncp.NodeId) - go performSP(ctx, conn, "PIPE", nice, *noCK, nodeIdC) + addr := "PIPE" + if proto := os.Getenv("PROTO"); proto == "TCP" { + port := os.Getenv("TCPREMOTEPORT") + if host := os.Getenv("TCPREMOTEHOST"); host == "" { + addr = fmt.Sprintf("[%s]:%s", os.Getenv("TCPREMOTEIP"), port) + } else { + addr = fmt.Sprintf("%s:%s", host, port) + } + } + go performSP(ctx, conn, addr, nice, *noCK, nodeIdC) nodeId := <-nodeIdC var autoTossFinish chan struct{} var autoTossBadCode chan bool