]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cmd/nncp-daemon/main.go
Correctly show seconds
[nncp.git] / src / cmd / nncp-daemon / main.go
index a69175a299f417794e465758e8df3176f2eb95a6..3d52dcc710ee9b4f3c7f43cb1f1b4f2a05f49b8e 100644 (file)
@@ -24,6 +24,8 @@ import (
        "log"
        "net"
        "os"
+       "strconv"
+       "strings"
        "time"
 
        "github.com/dustin/go-humanize"
@@ -100,7 +102,7 @@ func performSP(
                                state.Node.Name,
                                int(state.Duration.Hours()),
                                int(state.Duration.Minutes()),
-                               int(state.Duration.Seconds()),
+                               int(state.Duration.Seconds()/60),
                                humanize.IBytes(uint64(state.RxBytes)),
                                humanize.IBytes(uint64(state.RxSpeed)),
                                humanize.IBytes(uint64(state.TxBytes)),
@@ -108,17 +110,21 @@ func performSP(
                        )
                })
        } else {
-               nodeId := "unknown"
+               var nodeId string
+               var nodeName string
                if state.Node == nil {
+                       nodeId = "unknown"
+                       nodeName = "unknown"
                        nodeIdC <- nil
                } else {
-                       nodeIdC <- state.Node.Id
                        nodeId = state.Node.Id.String()
+                       nodeName = state.Node.Name
+                       nodeIdC <- state.Node.Id
                }
                ctx.LogI(
                        "call-started",
                        nncp.LEs{{K: "Node", V: nodeId}},
-                       func(les nncp.LEs) string { return "Connected to " + state.Node.Name },
+                       func(les nncp.LEs) string { return "Connected to " + nodeName },
                )
        }
        close(nodeIdC)
@@ -132,6 +138,7 @@ func main() {
                inetd     = flag.Bool("inetd", false, "Is it started as inetd service")
                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")
                spoolPath = flag.String("spool", "", "Override path to spool")
                logPath   = flag.String("log", "", "Override path to logfile")
                quiet     = flag.Bool("quiet", false, "Print only errors")
@@ -148,6 +155,7 @@ func main() {
                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")
        )
+       log.SetFlags(log.Lshortfile)
        flag.Usage = usage
        flag.Parse()
        if *warranty {
@@ -208,10 +216,32 @@ func main() {
                return
        }
 
+       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)
+                       }
+               }
+               return
+       }
+
        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)
+               }
+       }
+
        ln = netutil.LimitListener(ln, *maxConn)
        for {
                conn, err := ln.Accept()