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. // Equal reports whether peer and x are the same.
func (peer *Peer) Equal(x *Peer) bool { func (peer Peer) Equal(x Peer) bool {
if peer.ID == x.ID && peer.Port == x.Port && peer.IP.Equal(x.IP) { return peer.ID == x.ID && peer.Port == x.Port && peer.IP.Equal(x.IP)
return true
}
return false
} }

View file

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

View file

@ -43,8 +43,8 @@ func TestConstructor(t *testing.T) {
func TestModifyResponse(t *testing.T) { func TestModifyResponse(t *testing.T) {
var ( var (
achain tracker.AnnounceChain achain tracker.AnnounceChain
req chihaya.AnnounceRequest req chihaya.AnnounceRequest
resp chihaya.AnnounceResponse resp chihaya.AnnounceResponse
) )
mw, err := constructor(chihaya.MiddlewareConfig{ mw, err := constructor(chihaya.MiddlewareConfig{

View file

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

View file

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