Skip to content

Commit 64102a5

Browse files
committedAug 12, 2015
use correct context for dht notifs
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent ace06b4 commit 64102a5

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed
 

‎routing/dht/lookup.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ func (dht *IpfsDHT) GetClosestPeers(ctx context.Context, key key.Key) (<-chan pe
4040
peerset.Add(p)
4141
}
4242

43+
// since the query doesnt actually pass our context down
44+
// we have to hack this here. whyrusleeping isnt a huge fan of goprocess
45+
parent := ctx
4346
query := dht.newQuery(key, func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) {
4447
// For DHT query command
45-
notif.PublishQueryEvent(ctx, &notif.QueryEvent{
48+
notif.PublishQueryEvent(parent, &notif.QueryEvent{
4649
Type: notif.SendingQuery,
4750
ID: p,
4851
})
@@ -66,7 +69,7 @@ func (dht *IpfsDHT) GetClosestPeers(ctx context.Context, key key.Key) (<-chan pe
6669
}
6770

6871
// For DHT query command
69-
notif.PublishQueryEvent(ctx, &notif.QueryEvent{
72+
notif.PublishQueryEvent(parent, &notif.QueryEvent{
7073
Type: notif.PeerResponse,
7174
ID: p,
7275
Responses: pointerizePeerInfos(filtered),

‎routing/dht/routing.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key key.Key) ([]byte, error) {
9797
}
9898

9999
// setup the Query
100+
parent := ctx
100101
query := dht.newQuery(key, func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) {
101-
notif.PublishQueryEvent(ctx, &notif.QueryEvent{
102+
notif.PublishQueryEvent(parent, &notif.QueryEvent{
102103
Type: notif.SendingQuery,
103104
ID: p,
104105
})
@@ -113,7 +114,7 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key key.Key) ([]byte, error) {
113114
res.success = true
114115
}
115116

116-
notif.PublishQueryEvent(ctx, &notif.QueryEvent{
117+
notif.PublishQueryEvent(parent, &notif.QueryEvent{
117118
Type: notif.PeerResponse,
118119
ID: p,
119120
Responses: pointerizePeerInfos(peers),
@@ -209,8 +210,9 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key key.Key,
209210
}
210211

211212
// setup the Query
213+
parent := ctx
212214
query := dht.newQuery(key, func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) {
213-
notif.PublishQueryEvent(ctx, &notif.QueryEvent{
215+
notif.PublishQueryEvent(parent, &notif.QueryEvent{
214216
Type: notif.SendingQuery,
215217
ID: p,
216218
})
@@ -246,7 +248,7 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key key.Key,
246248
clpeers := pb.PBPeersToPeerInfos(closer)
247249
log.Debugf("got closer peers: %d %s", len(clpeers), clpeers)
248250

249-
notif.PublishQueryEvent(ctx, &notif.QueryEvent{
251+
notif.PublishQueryEvent(parent, &notif.QueryEvent{
250252
Type: notif.PeerResponse,
251253
ID: p,
252254
Responses: pointerizePeerInfos(clpeers),
@@ -288,8 +290,9 @@ func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (peer.PeerInfo, er
288290
}
289291

290292
// setup the Query
293+
parent := ctx
291294
query := dht.newQuery(key.Key(id), func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) {
292-
notif.PublishQueryEvent(ctx, &notif.QueryEvent{
295+
notif.PublishQueryEvent(parent, &notif.QueryEvent{
293296
Type: notif.SendingQuery,
294297
ID: p,
295298
})
@@ -312,7 +315,7 @@ func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (peer.PeerInfo, er
312315
}
313316
}
314317

315-
notif.PublishQueryEvent(ctx, &notif.QueryEvent{
318+
notif.PublishQueryEvent(parent, &notif.QueryEvent{
316319
Type: notif.PeerResponse,
317320
Responses: pointerizePeerInfos(clpeerInfos),
318321
})

0 commit comments

Comments
 (0)
Please sign in to comment.