Commit 71e411e5 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet Committed by Brian Tiger Chow

Peer: only add addresses once.

parent 34a0580e
......@@ -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)
}
......
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 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment