]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/humanizer.go
Forbid any later GNU GPL versions autousage
[nncp.git] / src / cypherpunks.ru / nncp / humanizer.go
index cea9546b150d619f9022bb415fd686949f3a390b..5c6989526841fdf4b861216cec4621e3b1edae20 100644 (file)
@@ -1,11 +1,10 @@
 /*
 NNCP -- Node to Node copy
-Copyright (C) 2016-2018 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2019 Sergey Matveev <stargrave@stargrave.org>
 
 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
@@ -149,6 +148,8 @@ func (ctx *Ctx) Humanize(s string) string {
                }
                if err, exists := sds["err"]; exists {
                        msg += ": " + err
+               } else {
+                       msg += " " + rem
                }
        case "nncp-bundle":
                switch sds["xx"] {
@@ -196,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":
@@ -206,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":