make peer Equal work on values
This commit is contained in:
parent
1c3e0432d8
commit
373d3c4c31
5 changed files with 10 additions and 13 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -43,8 +43,8 @@ func TestConstructor(t *testing.T) {
|
|||
func TestModifyResponse(t *testing.T) {
|
||||
var (
|
||||
achain tracker.AnnounceChain
|
||||
req chihaya.AnnounceRequest
|
||||
resp chihaya.AnnounceResponse
|
||||
req chihaya.AnnounceRequest
|
||||
resp chihaya.AnnounceResponse
|
||||
)
|
||||
|
||||
mw, err := constructor(chihaya.MiddlewareConfig{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue