X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fnncp-daemon%2Fmain.go;h=3fdba332684f1e0e0cdfecd5128ff60049256ae9;hb=1d2ce674b042d07fd9b37a46578c8b62bb0345b7;hp=318c3e450d9a190877cbc28554be5b1c904c9bda;hpb=0139e8deda4112d2c3dcd52e0ad72162e54caa03;p=nncp.git diff --git a/src/cmd/nncp-daemon/main.go b/src/cmd/nncp-daemon/main.go index 318c3e4..3fdba33 100644 --- a/src/cmd/nncp-daemon/main.go +++ b/src/cmd/nncp-daemon/main.go @@ -24,7 +24,6 @@ import ( "log" "net" "os" - "strconv" "time" "go.cypherpunks.ru/nncp/v5" @@ -43,20 +42,24 @@ type InetdConn struct { w *os.File } -func (ic *InetdConn) Read(p []byte) (n int, err error) { - return ic.r.Read(p) +func (c InetdConn) Read(p []byte) (n int, err error) { + return c.r.Read(p) } -func (ic *InetdConn) Write(p []byte) (n int, err error) { - return ic.w.Write(p) +func (c InetdConn) Write(p []byte) (n int, err error) { + return c.w.Write(p) } -func (ic *InetdConn) SetReadDeadline(t time.Time) error { - return ic.r.SetReadDeadline(t) +func (c InetdConn) SetReadDeadline(t time.Time) error { + return c.r.SetReadDeadline(t) } -func (ic *InetdConn) SetWriteDeadline(t time.Time) error { - return ic.w.SetWriteDeadline(t) +func (c InetdConn) SetWriteDeadline(t time.Time) error { + return c.w.SetWriteDeadline(t) +} + +func (c InetdConn) Close() error { + return c.w.Close() } func performSP(ctx *nncp.Ctx, conn nncp.ConnDeadlined, nice uint8) { @@ -69,18 +72,18 @@ func performSP(ctx *nncp.Ctx, conn nncp.ConnDeadlined, nice uint8) { state.Wait() ctx.LogI("call-finish", nncp.SDS{ "node": state.Node.Id, - "duration": strconv.FormatInt(int64(state.Duration.Seconds()), 10), - "rxbytes": strconv.FormatInt(state.RxBytes, 10), - "txbytes": strconv.FormatInt(state.TxBytes, 10), - "rxspeed": strconv.FormatInt(state.RxSpeed, 10), - "txspeed": strconv.FormatInt(state.TxSpeed, 10), + "duration": state.Duration.Seconds(), + "rxbytes": state.RxBytes, + "txbytes": state.TxBytes, + "rxspeed": state.RxSpeed, + "txspeed": state.TxSpeed, }, "") } else { nodeId := "unknown" if state.Node != nil { nodeId = state.Node.Id.String() } - ctx.LogE("call-start", nncp.SDS{"node": nodeId, "err": err}, "") + ctx.LogE("call-start", nncp.SDS{"node": nodeId}, err, "") } } @@ -94,6 +97,8 @@ func main() { spoolPath = flag.String("spool", "", "Override path to spool") logPath = flag.String("log", "", "Override path to logfile") quiet = flag.Bool("quiet", false, "Print only errors") + showPrgrs = flag.Bool("progress", false, "Force progress showing") + omitPrgrs = flag.Bool("noprogress", false, "Omit progress showing") debug = flag.Bool("debug", false, "Print debug messages") version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") @@ -113,13 +118,22 @@ func main() { log.Fatalln(err) } - ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug) + ctx, err := nncp.CtxFromCmdline( + *cfgPath, + *spoolPath, + *logPath, + *quiet, + *showPrgrs, + *omitPrgrs, + *debug, + ) if err != nil { log.Fatalln("Error during initialization:", err) } if ctx.Self == nil { log.Fatalln("Config lacks private keys") } + ctx.Umask() if *inetd { os.Stderr.Close()