From: Sergey Matveev Date: Fri, 13 Dec 2019 15:33:17 +0000 (+0300) Subject: Nicer SP handshake messages X-Git-Tag: v5.1.2^2~2 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=d44ffffaf98db3797529af2fa70a8ed344841415;p=nncp.git Nicer SP handshake messages --- diff --git a/src/humanizer.go b/src/humanizer.go index 5c69895..14b615f 100644 --- a/src/humanizer.go +++ b/src/humanizer.go @@ -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 { diff --git a/src/sp.go b/src/sp.go index c5cfb07..7b8fc31 100644 --- 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()