X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcall.go;h=1e20aa23f340a40549660de2878dfb1b97986c78;hb=ab7c7eca0e53661f0ba904c2a6ba752990bea367;hp=f859167550741e30109990558f9ae4b948a633b5;hpb=fa24572f1280b56977c6dcf6969a736403d1280e;p=nncp.git diff --git a/src/call.go b/src/call.go index f859167..1e20aa2 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" ) @@ -33,6 +35,17 @@ type Call struct { Addr *string OnlineDeadline time.Duration MaxOnlineTime time.Duration + WhenTxExists bool + NoCK bool + MCDIgnore bool + + AutoToss bool + AutoTossDoSeen bool + AutoTossNoFile bool + AutoTossNoFreq bool + AutoTossNoExec bool + AutoTossNoTrns bool + AutoTossNoArea bool } func (ctx *Ctx) CallNode( @@ -43,11 +56,14 @@ func (ctx *Ctx) CallNode( rxRate, txRate int, onlineDeadline, maxOnlineTime time.Duration, listOnly bool, - onlyPkts map[[32]byte]bool, + noCK bool, + onlyPkts map[[MTHSize]byte]bool, ) (isGood bool) { for _, addr := range addrs { - sds := SDS{"node": node.Id, "addr": addr} - ctx.LogD("call", sds, "dialing") + les := LEs{{"Node", node.Id}, {"Addr", addr}} + 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] == '|' { @@ -56,10 +72,14 @@ func (ctx *Ctx) CallNode( conn, err = net.Dial("tcp", addr) } if err != nil { - ctx.LogD("call", SdsAdd(sds, SDS{"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", sds, "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, @@ -70,24 +90,41 @@ func (ctx *Ctx) CallNode( rxRate: rxRate, txRate: txRate, listOnly: listOnly, + NoCK: noCK, onlyPkts: onlyPkts, } if err = state.StartI(conn); err == nil { - ctx.LogI("call-start", sds, "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", SDS{ - "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())%60, + 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", sds, 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 } }