X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fnncp-daemon%2Fmain.go;h=b3687e8e05a668859ee1825a737f7911da024df3;hb=e068d88291cd45a4d6b748e258077dd6c0ffb9c2;hp=f27c2a371461b0dad558509be8a09f670c75b507;hpb=9481faded654975d4bc0539412fd925a278b51bd;p=nncp.git diff --git a/src/cmd/nncp-daemon/main.go b/src/cmd/nncp-daemon/main.go index f27c2a3..b3687e8 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 UCSPIConn struct { - r *os.File - w *os.File -} - -func (c UCSPIConn) Read(p []byte) (n int, err error) { - return c.r.Read(p) -} - -func (c UCSPIConn) Write(p []byte) (n int, err error) { - return c.w.Write(p) -} - -func (c UCSPIConn) SetReadDeadline(t time.Time) error { - return c.r.SetReadDeadline(t) -} - -func (c UCSPIConn) SetWriteDeadline(t time.Time) error { - return c.w.SetWriteDeadline(t) -} - -func (c UCSPIConn) 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, @@ -140,6 +111,7 @@ func main() { bind = flag.String("bind", "[::]:5400", "Address to bind to") ucspi = flag.Bool("ucspi", false, "Is it started as UCSPI-TCP server") inetd = flag.Bool("inetd", false, "Obsolete, use -ucspi") + yggdrasil = flag.String("yggdrasil", "", "Start Yggdrasil listener: PRV;BIND[,...];[PUB,...];[PEER,...]") 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") @@ -153,7 +125,7 @@ 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") @@ -197,17 +169,12 @@ func main() { ctx.Umask() if *ucspi { - os.Stderr.Close() // #nosec G104 - conn := &UCSPIConn{os.Stdin, os.Stdout} + os.Stderr.Close() + conn := &nncp.UCSPIConn{R: os.Stdin, W: os.Stdout} nodeIdC := make(chan *nncp.NodeId) - 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) - } + addr := nncp.UCSPITCPRemoteAddr() + if addr == "" { + addr = "PIPE" } go performSP(ctx, conn, addr, nice, *noCK, nodeIdC) nodeId := <-nodeIdC @@ -230,33 +197,41 @@ func main() { close(autoTossFinish) <-autoTossBadCode } - conn.Close() // #nosec G104 + conn.Close() return } - cols := strings.Split(*bind, ":") - port, err := strconv.Atoi(cols[len(cols)-1]) - if err != nil { - log.Fatalln("Can not parse port:", err) - } + var ln net.Listener + if *yggdrasil != "" { + ln, err = nncp.NewYggdrasilListener(ctx.YggdrasilAliases, *yggdrasil) + if err != nil { + log.Fatalln("Can not listen:", err) + } + } else { + cols := strings.Split(*bind, ":") + port, err := strconv.Atoi(cols[len(cols)-1]) + if err != nil { + log.Fatalln("Can not parse port:", err) + } - if *mcdOnce { - for ifiName := range ctx.MCDTxIfis { - if err = ctx.MCDTx(ifiName, port, 0); err != nil { - log.Fatalln("Can not do MCD transmission:", err) + if *mcdOnce { + for ifiName := range ctx.MCDTxIfis { + if err = ctx.MCDTx(ifiName, port, 0); err != nil { + log.Fatalln("Can not do MCD transmission:", err) + } } + return } - return - } - ln, err := net.Listen("tcp", *bind) - if err != nil { - log.Fatalln("Can not listen:", err) - } + ln, err = net.Listen("tcp", *bind) + if err != nil { + log.Fatalln("Can not listen:", err) + } - for ifiName, secs := range ctx.MCDTxIfis { - if err = ctx.MCDTx(ifiName, port, time.Duration(secs)*time.Second); err != nil { - log.Fatalln("Can not run MCD transmission:", err) + for ifiName, secs := range ctx.MCDTxIfis { + if err = ctx.MCDTx(ifiName, port, time.Duration(secs)*time.Second); err != nil { + log.Fatalln("Can not run MCD transmission:", err) + } } } @@ -296,7 +271,7 @@ func main() { close(autoTossFinish) <-autoTossBadCode } - conn.Close() // #nosec G104 + conn.Close() }(conn) } }