use correct context for dht notifs
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Aug 12, 2015 at 16:08 UTC
64102a5810377a590f19f2300995a342d9a16caf
2 files changed
+14
-8
routing/dht/lookup.go
+5
-2
@@ -40,9 +40,12 @@ func (dht *IpfsDHT) GetClosestPeers(ctx context.Context, key key.Key) (<-chan pe
40
peerset.Add(p)
41
}
42
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
46
query := dht.newQuery(key, func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) {
47
// For DHT query command
45
- notif.PublishQueryEvent(ctx, ¬if.QueryEvent{
48
+ notif.PublishQueryEvent(parent, ¬if.QueryEvent{
49
Type: notif.SendingQuery,
50
ID: p,
51
})
@@ -66,7 +69,7 @@ func (dht *IpfsDHT) GetClosestPeers(ctx context.Context, key key.Key) (<-chan pe
69
}
70
71
// For DHT query command
69
- notif.PublishQueryEvent(ctx, ¬if.QueryEvent{
72
+ notif.PublishQueryEvent(parent, ¬if.QueryEvent{
73
Type: notif.PeerResponse,
74
ID: p,
75
Responses: pointerizePeerInfos(filtered),
routing/dht/routing.go
+9
-6
@@ -97,8 +97,9 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key key.Key) ([]byte, error) {
97
}
98
99
// setup the Query
100
+ parent := ctx
101
query := dht.newQuery(key, func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) {
101
- notif.PublishQueryEvent(ctx, ¬if.QueryEvent{
102
+ notif.PublishQueryEvent(parent, ¬if.QueryEvent{
103
Type: notif.SendingQuery,
104
ID: p,
105
})
@@ -113,7 +114,7 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key key.Key) ([]byte, error) {
114
res.success = true
115
}
116
116
- notif.PublishQueryEvent(ctx, ¬if.QueryEvent{
117
+ notif.PublishQueryEvent(parent, ¬if.QueryEvent{
118
Type: notif.PeerResponse,
119
ID: p,
120
Responses: pointerizePeerInfos(peers),
@@ -209,8 +210,9 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key key.Key,
210
}
211
212
// setup the Query
213
+ parent := ctx
214
query := dht.newQuery(key, func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) {
213
- notif.PublishQueryEvent(ctx, ¬if.QueryEvent{
215
+ notif.PublishQueryEvent(parent, ¬if.QueryEvent{
216
Type: notif.SendingQuery,
217
ID: p,
218
})
@@ -246,7 +248,7 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key key.Key,
248
clpeers := pb.PBPeersToPeerInfos(closer)
249
log.Debugf("got closer peers: %d %s", len(clpeers), clpeers)
250
249
- notif.PublishQueryEvent(ctx, ¬if.QueryEvent{
251
+ notif.PublishQueryEvent(parent, ¬if.QueryEvent{
252
Type: notif.PeerResponse,
253
ID: p,
254
Responses: pointerizePeerInfos(clpeers),
@@ -288,8 +290,9 @@ func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (peer.PeerInfo, er
290
}
291
292
// setup the Query
293
+ parent := ctx
294
query := dht.newQuery(key.Key(id), func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) {
292
- notif.PublishQueryEvent(ctx, ¬if.QueryEvent{
295
+ notif.PublishQueryEvent(parent, ¬if.QueryEvent{
296
Type: notif.SendingQuery,
297
ID: p,
298
})
@@ -312,7 +315,7 @@ func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (peer.PeerInfo, er
315
}
316
}
317
315
- notif.PublishQueryEvent(ctx, ¬if.QueryEvent{
318
+ notif.PublishQueryEvent(parent, ¬if.QueryEvent{
319
Type: notif.PeerResponse,
320
Responses: pointerizePeerInfos(clpeerInfos),
321
})