]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/humanizer.go
Remote command execution
[nncp.git] / src / cypherpunks.ru / nncp / humanizer.go
index 062c070589ea9f6a42ad7a32083f8e4a2071601c..cea9546b150d619f9022bb415fd686949f3a390b 100644 (file)
@@ -1,6 +1,6 @@
 /*
-NNCP -- Node-to-Node CoPy
-Copyright (C) 2016-2017 Sergey Matveev <stargrave@stargrave.org>
+NNCP -- Node to Node copy
+Copyright (C) 2016-2018 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
@@ -76,18 +76,18 @@ func (ctx *Ctx) Humanize(s string) string {
                switch sds["type"] {
                case "file":
                        msg = fmt.Sprintf(
-                               "File %s (%s) transfer to %s:%s (nice %s): %s",
-                               sds["src"], size, nodeS, sds["dst"], sds["nice"], rem,
+                               "File %s (%s) transfer to %s:%s: %s",
+                               sds["src"], size, nodeS, sds["dst"], rem,
                        )
                case "freq":
                        msg = fmt.Sprintf(
-                               "File request from %s:%s to %s (nice %s): %s",
-                               nodeS, sds["src"], sds["dst"], sds["nice"], rem,
+                               "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) (nice %s): %s",
-                               nodeS, strings.Replace(sds["dst"], " ", ",", -1), size, sds["nice"], rem,
+                               "Exec to %s@%s (%s): %s",
+                               nodeS, sds["dst"], size, rem,
                        )
                case "trns":
                        msg = fmt.Sprintf(
@@ -102,10 +102,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)
@@ -127,11 +127,11 @@ func (ctx *Ctx) Humanize(s string) string {
                if err, exists := sds["err"]; exists {
                        msg += ": " + err
                }
-       case "toss-check":
-               msg = fmt.Sprintf(
-                       "Integrity check: %s/%s/%s %s",
-                       sds["node"], sds["xx"], sds["pkt"], sds["err"],
-               )
+       case "check":
+               msg = fmt.Sprintf("Checking: %s/%s/%s", sds["node"], sds["xx"], sds["pkt"])
+               if err, exists := sds["err"]; exists {
+                       msg += fmt.Sprintf(" %s", err)
+               }
        case "nncp-xfer":
                switch sds["xx"] {
                case "rx":
@@ -150,8 +150,27 @@ func (ctx *Ctx) Humanize(s string) string {
                if err, exists := sds["err"]; exists {
                        msg += ": " + err
                }
-       case "daemon":
-               msg = fmt.Sprintf("Daemon listening on %s", sds["bind"])
+       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":
@@ -177,22 +196,22 @@ func (ctx *Ctx) Humanize(s string) string {
                        humanize.IBytes(uint64(rx)), humanize.IBytes(uint64(rxs)),
                        humanize.IBytes(uint64(tx)), humanize.IBytes(uint64(txs)),
                )
-       case "llp-infos":
+       case "sp-infos":
                switch sds["xx"] {
                case "rx":
-                       msg = fmt.Sprintf("We have got for %s: ", nodeS)
-               case "tx":
                        msg = fmt.Sprintf("%s has got for us: ", nodeS)
+               case "tx":
+                       msg = fmt.Sprintf("We have got for %s: ", nodeS)
                default:
                        return s
                }
                msg += fmt.Sprintf("%s packets, %s", sds["pkts"], size)
-       case "llp-file":
+       case "sp-file":
                switch sds["xx"] {
                case "rx":
-                       msg = "Got file "
+                       msg = "Got packet "
                case "tx":
-                       msg = "Sent file "
+                       msg = "Sent packet "
                default:
                        return s
                }
@@ -211,15 +230,36 @@ func (ctx *Ctx) Humanize(s string) string {
                        humanize.IBytes(uint64(sizeParsed)),
                        humanize.IBytes(uint64(fullsize)),
                )
-       case "llp-done":
+       case "sp-done":
                switch sds["xx"] {
                case "rx":
-                       msg = fmt.Sprintf("File %s is retreived (%s)", sds["hash"], size)
+                       msg = fmt.Sprintf("Packet %s is retreived (%s)", sds["hash"], size)
                case "tx":
-                       msg = fmt.Sprintf("File %s is sent (%s)", sds["hash"], size)
+                       msg = fmt.Sprintf("Packet %s is sent", sds["hash"])
                default:
                        return s
                }
+       case "nncp-reass":
+               chunkNum, exists := sds["chunk"]
+               if exists {
+                       msg = fmt.Sprintf(
+                               "Reassembling chunked file \"%s\" (chunk %s): %s",
+                               sds["path"],
+                               chunkNum,
+                               rem,
+                       )
+               } else {
+                       msg = fmt.Sprintf(
+                               "Reassembling chunked file \"%s\": %s",
+                               sds["path"],
+                               rem,
+                       )
+               }
+               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
        }