"os"
"time"
+ "github.com/dustin/go-humanize"
"go.cypherpunks.ru/nncp/v6"
"golang.org/x/net/netutil"
)
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)
}
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)