]> Cypherpunks.ru repositories - nncp.git/commitdiff
Nicer SP handshake messages
authorSergey Matveev <stargrave@stargrave.org>
Fri, 13 Dec 2019 15:33:17 +0000 (18:33 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 13 Dec 2019 15:47:52 +0000 (18:47 +0300)
src/humanizer.go
src/sp.go

index 5c6989526841fdf4b861216cec4621e3b1edae20..14b615fbfdcc8369872aed37183d71d72c25b003 100644 (file)
@@ -173,7 +173,10 @@ func (ctx *Ctx) Humanize(s string) string {
        case "nncp-rm":
                msg += "removing " + sds["file"]
        case "call-start":
-               msg = fmt.Sprintf("Connected to %s", nodeS)
+               msg = fmt.Sprintf("Connection to %s", nodeS)
+               if err, exists := sds["err"]; exists {
+                       msg += ": " + err
+               }
        case "call-finish":
                rx, err := strconv.ParseUint(sds["rxbytes"], 10, 64)
                if err != nil {
@@ -197,6 +200,26 @@ 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-start":
+               if nodeS == "" {
+                       msg += "SP"
+                       if peer, exists := sds["peer"]; exists {
+                               msg += fmt.Sprintf(": %s", peer)
+                       }
+               } else {
+                       nice, err := NicenessParse(sds["nice"])
+                       if err != nil {
+                               return s
+                       }
+                       msg += fmt.Sprintf("SP with %s (nice %s)", nodeS, NicenessFmt(nice))
+               }
+               if len(rem) > 0 {
+                       msg += ": " + rem
+               }
+               if err, exists := sds["err"]; exists {
+                       msg += ": " + err
+               }
+
        case "sp-info":
                nice, err := NicenessParse(sds["nice"])
                if err != nil {
index c5cfb07452a0452f4d766ee0328e24411f51158c..7b8fc3113b2db7d2111ba68bf7c1f0c346bc98cf 100644 (file)
--- a/src/sp.go
+++ b/src/sp.go
@@ -231,6 +231,10 @@ func (state *SPState) ReadSP(src io.Reader) ([]byte, error) {
        var sp SPRaw
        n, err := xdr.UnmarshalLimited(src, &sp, 1<<17)
        if err != nil {
+               ue := err.(*xdr.UnmarshalError)
+               if ue.Err == io.EOF {
+                       return nil, ue.Err
+               }
                return nil, err
        }
        state.RxLastSeen = time.Now()