YTSFlix_Go/vendor/github.com/anacrolix/dht/bucket.go

38 lines
570 B
Go
Raw Normal View History

2018-11-04 14:58:15 +00:00
package dht
type bucket struct {
nodes map[*node]struct{}
}
func (b *bucket) Len() int {
return len(b.nodes)
}
func (b *bucket) EachNode(f func(*node) bool) bool {
for n := range b.nodes {
if !f(n) {
return false
}
}
return true
}
func (b *bucket) AddNode(n *node, k int) {
if _, ok := b.nodes[n]; ok {
return
}
if b.nodes == nil {
b.nodes = make(map[*node]struct{}, k)
}
b.nodes[n] = struct{}{}
}
func (b *bucket) GetNode(addr Addr, id int160) *node {
for n := range b.nodes {
if n.hasAddrAndID(addr, id) {
return n
}
}
return nil
}