X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcypherpunks.ru%2Fnncp%2Fhumanizer.go;h=5c6989526841fdf4b861216cec4621e3b1edae20;hb=dd92823db3d72fb21a4c712a7fb052dce16443dd;hp=49b715a1c91f6c7c118196b0bf7e948c0aac4a02;hpb=093f249044a62ce4d988542c7267caf1da5d0968;p=nncp.git diff --git a/src/cypherpunks.ru/nncp/humanizer.go b/src/cypherpunks.ru/nncp/humanizer.go index 49b715a..5c69895 100644 --- a/src/cypherpunks.ru/nncp/humanizer.go +++ b/src/cypherpunks.ru/nncp/humanizer.go @@ -1,11 +1,10 @@ /* NNCP -- Node to Node copy -Copyright (C) 2016-2017 Sergey Matveev +Copyright (C) 2016-2019 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. +the Free Software Foundation, version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -84,10 +83,10 @@ func (ctx *Ctx) Humanize(s string) string { "File request from %s:%s to %s: %s", nodeS, sds["src"], sds["dst"], rem, ) - case "mail": + case "exec": msg = fmt.Sprintf( - "Mail to %s@%s (%s): %s", - nodeS, strings.Replace(sds["dst"], " ", ",", -1), size, rem, + "Exec to %s@%s (%s): %s", + nodeS, sds["dst"], size, rem, ) case "trns": msg = fmt.Sprintf( @@ -102,10 +101,10 @@ func (ctx *Ctx) Humanize(s string) string { } case "rx": switch sds["type"] { - case "mail": + case "exec": msg = fmt.Sprintf( - "Got mail from %s to %s (%s)", - nodeS, strings.Replace(sds["dst"], " ", ",", -1), size, + "Got exec from %s to %s (%s)", + nodeS, sds["dst"], size, ) case "file": msg = fmt.Sprintf("Got file %s (%s) from %s", sds["dst"], size, nodeS) @@ -147,9 +146,32 @@ func (ctx *Ctx) Humanize(s string) string { if size != "" { msg += fmt.Sprintf(" (%s)", size) } + if err, exists := sds["err"]; exists { + msg += ": " + err + } else { + msg += " " + rem + } + case "nncp-bundle": + switch sds["xx"] { + case "rx": + msg = "Bundle transfer, received from" + case "tx": + msg = "Bundle transfer, sent to" + default: + return s + } + if nodeS != "" { + msg += " node " + nodeS + } + msg += " " + sds["pkt"] + if size != "" { + msg += fmt.Sprintf(" (%s)", size) + } if err, exists := sds["err"]; exists { msg += ": " + err } + case "nncp-rm": + msg += "removing " + sds["file"] case "call-start": msg = fmt.Sprintf("Connected to %s", nodeS) case "call-finish": @@ -175,6 +197,29 @@ func (ctx *Ctx) Humanize(s string) string { humanize.IBytes(uint64(rx)), humanize.IBytes(uint64(rxs)), humanize.IBytes(uint64(tx)), humanize.IBytes(uint64(txs)), ) + case "sp-info": + nice, err := NicenessParse(sds["nice"]) + if err != nil { + return s + } + msg = fmt.Sprintf( + "Packet %s (%s) (nice %s)", + sds["hash"], + size, + NicenessFmt(nice), + ) + offsetParsed, err := strconv.ParseUint(sds["offset"], 10, 64) + if err != nil { + return s + } + sizeParsed, err := strconv.ParseUint(sds["size"], 10, 64) + if err != nil { + return s + } + msg += fmt.Sprintf(": %d%%", 100*offsetParsed/sizeParsed) + if len(rem) > 0 { + msg += ": " + rem + } case "sp-infos": switch sds["xx"] { case "rx": @@ -185,6 +230,8 @@ func (ctx *Ctx) Humanize(s string) string { return s } msg += fmt.Sprintf("%s packets, %s", sds["pkts"], size) + case "sp-process": + msg = fmt.Sprintf("%s has %s (%s): %s", nodeS, sds["hash"], size, rem) case "sp-file": switch sds["xx"] { case "rx": @@ -237,6 +284,8 @@ func (ctx *Ctx) Humanize(s string) string { if err, exists := sds["err"]; exists { msg += ": " + err } + case "lockdir": + msg = fmt.Sprintf("Acquire lock for %s: %s", sds["path"], sds["err"]) default: return s }