]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go
Fix invalid -rx/-tx arguments processing
[nncp.git] / src / cypherpunks.ru / nncp / cmd / nncp-daemon / main.go
index 66f553e564efb35e9d234b8fc494cffc660ad950..e6ec2d385648ae1c84c8e959cc381addbc3d8e92 100644 (file)
@@ -35,7 +35,7 @@ import (
 func usage() {
        fmt.Fprintf(os.Stderr, nncp.UsageHeader())
        fmt.Fprintln(os.Stderr, "nncp-daemon -- TCP daemon\n")
-       fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:", os.Args[0])
+       fmt.Fprintf(os.Stderr, "Usage: %s [options]\nOptions:\n", os.Args[0])
        flag.PrintDefaults()
 }
 
@@ -43,10 +43,10 @@ func main() {
        var (
                cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
                niceRaw  = flag.Int("nice", 255, "Minimal required niceness")
-               bind     = flag.String("bind", ":5400", "Address to bind to")
+               bind     = flag.String("bind", "[::]:5400", "Address to bind to")
                maxConn  = flag.Int("maxconn", 128, "Maximal number of simultaneous connections")
                quiet    = flag.Bool("quiet", false, "Print only errors")
-               debug    = flag.Bool("debug", false, "Enable debugging information")
+               debug    = flag.Bool("debug", false, "Print debug messages")
                version  = flag.Bool("version", false, "Print version information")
                warranty = flag.Bool("warranty", false, "Print warranty information")
        )
@@ -65,7 +65,7 @@ func main() {
        }
        nice := uint8(*niceRaw)
 
-       cfgRaw, err := ioutil.ReadFile(*cfgPath)
+       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
        if err != nil {
                log.Fatalln("Can not read config:", err)
        }
@@ -73,6 +73,9 @@ func main() {
        if err != nil {
                log.Fatalln("Can not parse config:", err)
        }
+       if ctx.Self == nil {
+               log.Fatalln("Config lacks private keys")
+       }
        ctx.Quiet = *quiet
        ctx.Debug = *debug
 
@@ -88,12 +91,12 @@ func main() {
                }
                ctx.LogD("daemon", nncp.SDS{"addr": conn.RemoteAddr()}, "accepted")
                go func(conn net.Conn) {
-                       state, err := ctx.StartR(conn, nice, nil)
+                       state, err := ctx.StartR(conn, nice, "")
                        if err == nil {
-                               ctx.LogI("call-start", nncp.SDS{"node": state.NodeId}, "connected")
+                               ctx.LogI("call-start", nncp.SDS{"node": state.Node.Id}, "connected")
                                state.Wait()
                                ctx.LogI("call-finish", nncp.SDS{
-                                       "node":     state.NodeId,
+                                       "node":     state.Node.Id,
                                        "duration": strconv.FormatInt(int64(state.Duration.Seconds()), 10),
                                        "rxbytes":  strconv.FormatInt(state.RxBytes, 10),
                                        "txbytes":  strconv.FormatInt(state.TxBytes, 10),
@@ -101,7 +104,11 @@ func main() {
                                        "txspeed":  strconv.FormatInt(state.TxSpeed, 10),
                                }, "")
                        } else {
-                               ctx.LogE("call-start", nncp.SDS{"node": state.NodeId, "err": err}, "")
+                               nodeId := "unknown"
+                               if state != nil && state.Node != nil {
+                                       nodeId = state.Node.Id.String()
+                               }
+                               ctx.LogE("call-start", nncp.SDS{"node": nodeId, "err": err}, "")
                        }
                        conn.Close()
                }(conn)