Merge pull request #167 from mrd0ll4r/peer-equal

make peer Equal work on values
This commit is contained in:
Jimmy Zelinskie 2016-04-16 21:57:20 -04:00
commit a081e5195b
5 changed files with 10 additions and 13 deletions

View file

@ -77,9 +77,6 @@ type Params interface {
}
// Equal reports whether peer and x are the same.
func (peer *Peer) Equal(x *Peer) bool {
if peer.ID == x.ID && peer.Port == x.Port && peer.IP.Equal(x.IP) {
return true
}
return false
func (peer Peer) Equal(x Peer) bool {
return peer.ID == x.ID && peer.Port == x.Port && peer.IP.Equal(x.IP)
}

View file

@ -27,9 +27,9 @@ var (
func TestPeerEquality(t *testing.T) {
// Build peers from test data.
var builtPeers []*Peer
var builtPeers []Peer
for _, peer := range peers {
builtPeers = append(builtPeers, &Peer{
builtPeers = append(builtPeers, Peer{
ID: PeerID(peer.peerID),
IP: net.ParseIP(peer.ip),
Port: peer.port,

View file

@ -271,12 +271,12 @@ func (s *peerStore) AnnouncePeers(infoHash chihaya.InfoHash, seeder bool, numWan
}
if p.IP.To4() == nil {
if p.Equal(&peer6) {
if p.Equal(peer6) {
continue
}
peers6 = append(peers6, p.Peer)
} else {
if p.Equal(&peer4) {
if p.Equal(peer4) {
continue
}
peers = append(peers, p.Peer)

View file

@ -16,7 +16,7 @@ import (
func peerInSlice(peer chihaya.Peer, peers []chihaya.Peer) bool {
for _, v := range peers {
if v.Equal(&peer) {
if v.Equal(peer) {
return true
}
}
@ -147,7 +147,7 @@ func TestPeerStoreAPI(t *testing.T) {
assert.Equal(t, 7, s.NumSeeders(hash))
assert.Equal(t, 3, s.NumLeechers(hash))
peers1, peers61, err := s.AnnouncePeers(hash, true, 5,peer,chihaya.Peer{})
peers1, peers61, err := s.AnnouncePeers(hash, true, 5, peer, chihaya.Peer{})
assert.Nil(t, err)
assert.NotNil(t, peers1)
assert.NotNil(t, peers61)