Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
236dfd1e
Commit
236dfd1e
authored
Mar 03, 2015
by
Alex
Browse files
Implemented @jbenet's suggestion to avoid panics if peerID is of length 0.
parent
4b52be28
Changes
1
Hide whitespace changes
Inline
Side-by-side
peer/peer.go
View file @
236dfd1e
...
...
@@ -5,6 +5,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"strings"
b58
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
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{} {
// codebase is known to be correct.
func
(
id
ID
)
String
()
string
{
pid
:=
id
.
Pretty
()
//All sha256 nodes start with Qm
//We can skip the Qm to make the peer.ID more useful
if
strings
.
HasPrefix
(
pid
,
"Qm"
)
{
pid
=
pid
[
2
:
]
}
maxRunes
:=
6
skip
:=
2
//Added to skip past Qm which is identical for all SHA256 nodes
if
len
(
pid
)
<
maxRunes
+
skip
{
maxRunes
=
len
(
pid
)
-
skip
if
len
(
pid
)
<
maxRunes
{
maxRunes
=
len
(
pid
)
}
return
fmt
.
Sprintf
(
"<peer.ID %s>"
,
pid
[
skip
:
maxRunes
+
skip
])
return
fmt
.
Sprintf
(
"<peer.ID %s>"
,
pid
[
:
maxRunes
])
}
// MatchesPrivateKey tests whether this ID was derived from sk
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment