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-unixfs
Commits
71e411e5
Commit
71e411e5
authored
Sep 16, 2014
by
Juan Batiz-Benet
Committed by
Brian Tiger Chow
Sep 22, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Peer: only add addresses once.
parent
34a0580e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletion
+12
-1
peer/peer.go
peer/peer.go
+5
-0
peer/peer_test.go
peer/peer_test.go
+7
-1
No files found.
peer/peer.go
View file @
71e411e5
...
...
@@ -48,6 +48,11 @@ func (p *Peer) Key() u.Key {
// AddAddress adds the given Multiaddr address to Peer's addresses.
func
(
p
*
Peer
)
AddAddress
(
a
*
ma
.
Multiaddr
)
{
for
_
,
addr
:=
range
p
.
Addresses
{
if
addr
.
Equal
(
a
)
{
return
}
}
p
.
Addresses
=
append
(
p
.
Addresses
,
a
)
}
...
...
peer/peer_test.go
View file @
71e411e5
package
peer
import
(
"testing"
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
mh
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
"testing"
)
func
TestNetAddress
(
t
*
testing
.
T
)
{
...
...
@@ -29,6 +30,11 @@ func TestNetAddress(t *testing.T) {
p
:=
Peer
{
ID
:
ID
(
mh
)}
p
.
AddAddress
(
tcp
)
p
.
AddAddress
(
udp
)
p
.
AddAddress
(
tcp
)
if
len
(
p
.
Addresses
)
==
3
{
t
.
Error
(
"added same address twice"
)
}
tcp2
:=
p
.
NetAddress
(
"tcp"
)
if
tcp2
!=
tcp
{
...
...
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