Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
fba5db20
Commit
fba5db20
authored
Nov 16, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #222 from jbenet/fix/peer-string-2014-10-28
fix(peer) String() bounds check
parents
1840a01f
2e0371c6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
1 deletion
+20
-1
peer/peer.go
peer/peer.go
+11
-1
peer/peer_test.go
peer/peer_test.go
+9
-0
No files found.
peer/peer.go
View file @
fba5db20
...
...
@@ -115,8 +115,18 @@ type peer struct {
}
// String prints out the peer.
//
// TODO(brian): ensure correctness at ID generation and
// enforce this by only exposing functions that generate
// IDs safely. Then any peer.ID type found in the
// codebase is known to be correct.
func
(
p
*
peer
)
String
()
string
{
return
"[Peer "
+
p
.
id
.
String
()[
:
12
]
+
"]"
pid
:=
p
.
id
.
String
()
maxRunes
:=
12
if
len
(
pid
)
<
maxRunes
{
maxRunes
=
len
(
pid
)
}
return
"[Peer "
+
pid
[
:
maxRunes
]
+
"]"
}
// Key returns the ID as a Key (string) for maps.
...
...
peer/peer_test.go
View file @
fba5db20
...
...
@@ -46,3 +46,12 @@ func TestNetAddress(t *testing.T) {
t
.
Error
(
"NetAddress lookup failed"
,
udp
,
udp2
)
}
}
func
TestStringMethodWithSmallId
(
t
*
testing
.
T
)
{
p
:=
WithID
([]
byte
(
string
(
0
)))
p1
,
ok
:=
p
.
(
*
peer
)
if
!
ok
{
t
.
Fatal
(
"WithID doesn't return a peer"
)
}
p1
.
String
()
}
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