peer.Peer is now an interface

![](http://m.memegen.com/77n7dk.jpg)
This commit is contained in:
Juan Batiz-Benet
2014-10-20 03:26:44 -07:00
parent e98bb76b0f
commit 28e083b902
11 changed files with 123 additions and 129 deletions

14
util.go
View File

@ -52,15 +52,15 @@ func newPeerSet() *peerSet {
return ps
}
func (ps *peerSet) Add(p *peer.Peer) {
func (ps *peerSet) Add(p peer.Peer) {
ps.lk.Lock()
ps.ps[string(p.ID)] = true
ps.ps[string(p.ID())] = true
ps.lk.Unlock()
}
func (ps *peerSet) Contains(p *peer.Peer) bool {
func (ps *peerSet) Contains(p peer.Peer) bool {
ps.lk.RLock()
_, ok := ps.ps[string(p.ID)]
_, ok := ps.ps[string(p.ID())]
ps.lk.RUnlock()
return ok
}
@ -71,12 +71,12 @@ func (ps *peerSet) Size() int {
return len(ps.ps)
}
func (ps *peerSet) AddIfSmallerThan(p *peer.Peer, maxsize int) bool {
func (ps *peerSet) AddIfSmallerThan(p peer.Peer, maxsize int) bool {
var success bool
ps.lk.Lock()
if _, ok := ps.ps[string(p.ID)]; !ok && len(ps.ps) < maxsize {
if _, ok := ps.ps[string(p.ID())]; !ok && len(ps.ps) < maxsize {
success = true
ps.ps[string(p.ID)] = true
ps.ps[string(p.ID())] = true
}
ps.lk.Unlock()
return success