X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fnncp-daemon%2Fmain.go;h=a1b7982a8bdab14819674323cb11299f0b764049;hb=fd6a79c14ead6eefcb0bc327ea67687952b7ed3a;hp=3b40f1cc9e7bf6673e49110029db5d55794e37f3;hpb=28344f84b8a4543758436739360446509ead86ce;p=nncp.git diff --git a/src/cmd/nncp-daemon/main.go b/src/cmd/nncp-daemon/main.go index 3b40f1c..a1b7982 100644 --- a/src/cmd/nncp-daemon/main.go +++ b/src/cmd/nncp-daemon/main.go @@ -26,6 +26,7 @@ import ( "os" "time" + "github.com/dustin/go-humanize" "go.cypherpunks.ru/nncp/v6" "golang.org/x/net/netutil" ) @@ -79,26 +80,50 @@ func performSP( NoCK: noCK, } if err := state.StartR(conn); err == nil { - ctx.LogI("call-start", nncp.LEs{{K: "Node", V: state.Node.Id}}, "connected") + ctx.LogI( + "call-started", + nncp.LEs{{K: "Node", V: state.Node.Id}}, + func(les nncp.LEs) string { return "Connection with " + state.Node.Name }, + ) nodeIdC <- state.Node.Id state.Wait() - ctx.LogI("call-finish", nncp.LEs{ + ctx.LogI("call-finished", nncp.LEs{ {K: "Node", V: state.Node.Id}, {K: "Duration", V: int64(state.Duration.Seconds())}, {K: "RxBytes", V: state.RxBytes}, {K: "TxBytes", V: state.TxBytes}, {K: "RxSpeed", V: state.RxSpeed}, {K: "TxSpeed", V: state.TxSpeed}, - }, "") + }, func(les nncp.LEs) string { + return fmt.Sprintf( + "Finished call with %s (%d:%d:%d): %s received (%s/sec), %s transferred (%s/sec)", + state.Node.Name, + int(state.Duration.Hours()), + int(state.Duration.Minutes()), + int(state.Duration.Seconds()), + humanize.IBytes(uint64(state.RxBytes)), + humanize.IBytes(uint64(state.RxSpeed)), + humanize.IBytes(uint64(state.TxBytes)), + humanize.IBytes(uint64(state.TxSpeed)), + ) + }) } 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-start", nncp.LEs{{K: "Node", V: nodeId}}, "connected") + ctx.LogI( + "call-started", + nncp.LEs{{K: "Node", V: nodeId}}, + func(les nncp.LEs) string { return "Connected to " + nodeName }, + ) } close(nodeIdC) } @@ -197,7 +222,13 @@ func main() { if err != nil { log.Fatalln("Can not accept connection:", err) } - ctx.LogD("daemon", nncp.LEs{{K: "Addr", V: conn.RemoteAddr()}}, "accepted") + ctx.LogD( + "daemon-accepted", + nncp.LEs{{K: "Addr", V: conn.RemoteAddr()}}, + func(les nncp.LEs) string { + return "Accepted connection with " + conn.RemoteAddr().String() + }, + ) go func(conn net.Conn) { nodeIdC := make(chan *nncp.NodeId) go performSP(ctx, conn, nice, *noCK, nodeIdC)