Commit 352eec31 authored by Jeromy's avatar Jeromy Committed by Juan Batiz-Benet

refactor peerSet

parent e838fd78
......@@ -141,11 +141,11 @@ func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key u.Key, count int
func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key u.Key, count int, peerOut chan peer.Peer) {
defer close(peerOut)
ps := pset.NewPeerSet()
ps := pset.NewLimitedPeerSet(count)
provs := dht.providers.GetProviders(ctx, key)
for _, p := range provs {
// NOTE: assuming that this list of peers is unique
if ps.AddIfSmallerThan(p, count) {
if ps.TryAdd(p) {
select {
case peerOut <- p:
case <-ctx.Done():
......@@ -176,7 +176,7 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key u.Key, co
// Add unique providers from request, up to 'count'
for _, prov := range provs {
if ps.AddIfSmallerThan(prov, count) {
if ps.TryAdd(prov) {
select {
case peerOut <- prov:
case <-ctx.Done():
......@@ -226,7 +226,7 @@ func (dht *IpfsDHT) addPeerListAsync(ctx context.Context, k u.Key, peers []*pb.M
}
dht.providers.AddProvider(k, p)
if ps.AddIfSmallerThan(p, count) {
if ps.TryAdd(p) {
select {
case out <- p:
case <-ctx.Done():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment