X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcall.go;fp=src%2Fcall.go;h=ab254b2dd5b6e8e9affb7e6280373111038c6117;hb=5a9bf58a2638e42f2d42fa4d43c363a664fe8198;hp=2f635d63d0aa7d36b9fb33a87206cd173db9f4fb;hpb=745d9fafe84b0745b84d93900722216dde6b88cc;p=nncp.git diff --git a/src/call.go b/src/call.go index 2f635d6..ab254b2 100644 --- a/src/call.go +++ b/src/call.go @@ -18,9 +18,11 @@ along with this program. If not, see . package nncp import ( + "fmt" "net" "time" + "github.com/dustin/go-humanize" "github.com/gorhill/cronexpr" ) @@ -57,7 +59,9 @@ func (ctx *Ctx) CallNode( ) (isGood bool) { for _, addr := range addrs { les := LEs{{"Node", node.Id}, {"Addr", addr}} - ctx.LogD("call", les, "dialing") + ctx.LogD("calling", les, func(les LEs) string { + return fmt.Sprintf("Calling %s (%s)", node.Name, addr) + }) var conn ConnDeadlined var err error if addr[0] == '|' { @@ -66,10 +70,14 @@ func (ctx *Ctx) CallNode( conn, err = net.Dial("tcp", addr) } if err != nil { - ctx.LogD("call", append(les, LE{"Err", err}), "dialing") + ctx.LogD("calling", append(les, LE{"Err", err}), func(les LEs) string { + return fmt.Sprintf("Calling %s (%s)", node.Name, addr) + }) continue } - ctx.LogD("call", les, "connected") + ctx.LogD("call-connected", les, func(les LEs) string { + return fmt.Sprintf("Connected %s (%s)", node.Name, addr) + }) state := SPState{ Ctx: ctx, Node: node, @@ -84,21 +92,37 @@ func (ctx *Ctx) CallNode( onlyPkts: onlyPkts, } if err = state.StartI(conn); err == nil { - ctx.LogI("call-start", les, "connected") + ctx.LogI("call-started", les, func(les LEs) string { + return fmt.Sprintf("Connection to %s (%s)", node.Name, addr) + }) state.Wait() - ctx.LogI("call-finish", LEs{ - {"Node", state.Node.Id}, - {"Duration", int64(state.Duration.Seconds())}, - {"RxBytes", state.RxBytes}, - {"TxBytes", state.TxBytes}, - {"RxSpeed", state.RxSpeed}, - {"TxSpeed", state.TxSpeed}, - }, "") + ctx.LogI("call-finished", append( + les, + LE{"Duration", int64(state.Duration.Seconds())}, + LE{"RxBytes", state.RxBytes}, + LE{"RxSpeed", state.RxSpeed}, + LE{"TxBytes", state.TxBytes}, + LE{"TxSpeed", state.TxSpeed}, + ), func(les LEs) string { + return fmt.Sprintf( + "Finished call with %s (%d:%d:%d): %s received (%s/sec), %s transferred (%s/sec)", + 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)), + ) + }) isGood = true conn.Close() // #nosec G104 break } else { - ctx.LogE("call-start", les, err, "") + ctx.LogE("call-started", les, err, func(les LEs) string { + return fmt.Sprintf("Connection to %s (%s)", node.Name, addr) + }) conn.Close() // #nosec G104 } }