@cryptotaxi247 / kubo / commits / da80f22bf

Implemented @jbenet's suggestion to avoid panics if peerID is of length 0.

Alex committed Mar 3, 2015 at 09:20 UTC da80f22bfe69a7a0fce3061065913c4413ba5dd3
1 file changed +11 -4
p2p/peer/peer.go
+11 -4
@@ -5,6 +5,7 @@ import (
5 "encoding/hex"
6 "encoding/json"
7 "fmt"
8 + "strings"
9
10 b58 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
11 ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
@@ -38,12 +39,18 @@ func (id ID) Loggable() map[string]interface{} {
39 // codebase is known to be correct.
40 func (id ID) String() string {
41 pid := id.Pretty()
42 +
43 + //All sha256 nodes start with Qm
44 + //We can skip the Qm to make the peer.ID more useful
45 + if strings.HasPrefix(pid, "Qm") {
46 + pid = pid[2:]
47 + }
48 +
49 maxRunes := 6
42 - skip := 2 //Added to skip past Qm which is identical for all SHA256 nodes
43 - if len(pid) < maxRunes + skip {
44 - maxRunes = len(pid) - skip
50 + if len(pid) < maxRunes {
51 + maxRunes = len(pid)
52 }
46 - return fmt.Sprintf("<peer.ID %s>", pid[skip:maxRunes + skip])
53 + return fmt.Sprintf("<peer.ID %s>", pid[:maxRunes])
54 }
55
56 // MatchesPrivateKey tests whether this ID was derived from sk