Commit d98d6cdf authored by Jeromy Johnson's avatar Jeromy Johnson

Merge pull request #834 from jbenet/fix/815

make the providers manager respect contexts
parents cb6d161b 3b2bd9bf
...@@ -223,7 +223,7 @@ func (dht *IpfsDHT) handleAddProvider(ctx context.Context, p peer.ID, pmes *pb.M ...@@ -223,7 +223,7 @@ func (dht *IpfsDHT) handleAddProvider(ctx context.Context, p peer.ID, pmes *pb.M
// add the received addresses to our peerstore. // add the received addresses to our peerstore.
dht.peerstore.AddAddrs(pi.ID, pi.Addrs, peer.ProviderAddrTTL) dht.peerstore.AddAddrs(pi.ID, pi.Addrs, peer.ProviderAddrTTL)
} }
dht.providers.AddProvider(key, p) dht.providers.AddProvider(ctx, key, p)
} }
return pmes, nil // send back same msg as confirmation. return pmes, nil // send back same msg as confirmation.
......
...@@ -99,11 +99,15 @@ func (pm *ProviderManager) run() { ...@@ -99,11 +99,15 @@ func (pm *ProviderManager) run() {
} }
} }
func (pm *ProviderManager) AddProvider(k u.Key, val peer.ID) { func (pm *ProviderManager) AddProvider(ctx context.Context, k u.Key, val peer.ID) {
pm.newprovs <- &addProv{ prov := &addProv{
k: k, k: k,
val: val, val: val,
} }
select {
case pm.newprovs <- prov:
case <-ctx.Done():
}
} }
func (pm *ProviderManager) GetProviders(ctx context.Context, k u.Key) []peer.ID { func (pm *ProviderManager) GetProviders(ctx context.Context, k u.Key) []peer.ID {
......
...@@ -14,7 +14,7 @@ func TestProviderManager(t *testing.T) { ...@@ -14,7 +14,7 @@ func TestProviderManager(t *testing.T) {
mid := peer.ID("testing") mid := peer.ID("testing")
p := NewProviderManager(ctx, mid) p := NewProviderManager(ctx, mid)
a := u.Key("test") a := u.Key("test")
p.AddProvider(a, peer.ID("testingprovider")) p.AddProvider(ctx, a, peer.ID("testingprovider"))
resp := p.GetProviders(ctx, a) resp := p.GetProviders(ctx, a)
if len(resp) != 1 { if len(resp) != 1 {
t.Fatal("Could not retrieve provider.") t.Fatal("Could not retrieve provider.")
......
...@@ -141,7 +141,7 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key u.Key) error { ...@@ -141,7 +141,7 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key u.Key) error {
defer log.EventBegin(ctx, "provide", &key).Done() defer log.EventBegin(ctx, "provide", &key).Done()
// add self locally // add self locally
dht.providers.AddProvider(key, dht.self) dht.providers.AddProvider(ctx, key, dht.self)
peers, err := dht.GetClosestPeers(ctx, key) peers, err := dht.GetClosestPeers(ctx, key)
if err != nil { if err != nil {
......
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