From 88168ff5c57b1a9c944d02e93e6e49368ccc968f Mon Sep 17 00:00:00 2001 From: holisticode Date: Fri, 11 Jan 2019 09:08:09 -0500 Subject: Stream subscriptions (#18355) * swarm/network: eachBin now starts at kaddepth for nn * swarm/network: fix Kademlia.EachBin * swarm/network: fix kademlia.EachBin * swarm/network: correct EachBin implementation according to requirements * swarm/network: less addresses simplified tests * swarm: calc kad depth outside loop in EachBin test * swarm/network: removed printResults * swarm/network: cleanup imports * swarm/network: remove kademlia.EachBin; fix RequestSubscriptions and add unit test * swarm/network/stream: address PR comments * swarm/network/stream: package-wide subscriptionFunc * swarm/network/stream: refactor to kad.EachConn --- swarm/network/kademlia.go | 31 ------------------------------- 1 file changed, 31 deletions(-) (limited to 'swarm/network/kademlia.go') diff --git a/swarm/network/kademlia.go b/swarm/network/kademlia.go index 341ed20b2..ec53f70a3 100644 --- a/swarm/network/kademlia.go +++ b/swarm/network/kademlia.go @@ -356,37 +356,6 @@ func (k *Kademlia) Off(p *Peer) { } } -// EachBin is a two level nested iterator -// The outer iterator returns all bins that have known peers, in order from shallowest to deepest -// The inner iterator returns all peers per bin returned by the outer iterator, in no defined order -// TODO the po returned by the inner iterator is not reliable. However, it is not being used in this method -func (k *Kademlia) EachBin(base []byte, pof pot.Pof, o int, eachBinFunc func(conn *Peer, po int) bool) { - k.lock.RLock() - defer k.lock.RUnlock() - - var startPo int - var endPo int - kadDepth := depthForPot(k.conns, k.NeighbourhoodSize, k.base) - - k.conns.EachBin(base, Pof, o, func(po, size int, f func(func(val pot.Val, i int) bool) bool) bool { - if startPo > 0 && endPo != k.MaxProxDisplay { - startPo = endPo + 1 - } - if po < kadDepth { - endPo = po - } else { - endPo = k.MaxProxDisplay - } - - for bin := startPo; bin <= endPo; bin++ { - f(func(val pot.Val, _ int) bool { - return eachBinFunc(val.(*Peer), bin) - }) - } - return true - }) -} - // EachConn is an iterator with args (base, po, f) applies f to each live peer // that has proximity order po or less as measured from the base // if base is nil, kademlia base address is used -- cgit