@cryptotaxi247 / kubo / commits / 0a6ab3021

address CR feedback

License: MIT Signed-off-by: Jeromy <why@ipfs.io>

Jeromy committed Aug 24, 2016 at 10:32 UTC 0a6ab30212876dfdc35e1777d7585551ff4c33a2
1 file changed +18 -23
core/commands/dht.go
+18 -23
@@ -237,7 +237,7 @@ var provideRefDhtCmd = &cmds.Command{
237 },
238
239 Arguments: []cmds.Argument{
240 - cmds.StringArg("key", true, true, "The key to find providers for.").EnableStdin(),
240 + cmds.StringArg("key", true, true, "The key[s] to send provide records for.").EnableStdin(),
241 },
242 Options: []cmds.Option{
243 cmds.BoolOption("verbose", "v", "Print extra information.").Default(false),
@@ -294,10 +294,17 @@ var provideRefDhtCmd = &cmds.Command{
294
295 go func() {
296 defer close(events)
297 + var err error
298 if rec {
298 - provideKeysRec(ctx, n.Routing, n.DAG, keys)
299 + err = provideKeysRec(ctx, n.Routing, n.DAG, keys)
300 } else {
300 - provideKeys(ctx, n.Routing, keys)
301 + err = provideKeys(ctx, n.Routing, keys)
302 + }
303 + if err != nil {
304 + notif.PublishQueryEvent(ctx, &notif.QueryEvent{
305 + Type: notif.QueryError,
306 + Extra: err.Error(),
307 + })
308 }
309 }()
310 },
@@ -338,37 +345,28 @@ var provideRefDhtCmd = &cmds.Command{
345 Type: notif.QueryEvent{},
346 }
347
341 -func provideKeys(ctx context.Context, r routing.IpfsRouting, keys []key.Key) {
348 +func provideKeys(ctx context.Context, r routing.IpfsRouting, keys []key.Key) error {
349 for _, k := range keys {
350 err := r.Provide(ctx, k)
351 if err != nil {
345 - notif.PublishQueryEvent(ctx, &notif.QueryEvent{
346 - Type: notif.QueryError,
347 - Extra: err.Error(),
348 - })
349 - return
352 + return err
353 }
354 }
355 + return nil
356 }
357
354 -func provideKeysRec(ctx context.Context, r routing.IpfsRouting, dserv dag.DAGService, keys []key.Key) {
358 +func provideKeysRec(ctx context.Context, r routing.IpfsRouting, dserv dag.DAGService, keys []key.Key) error {
359 provided := make(map[key.Key]struct{})
360 for _, k := range keys {
361 kset := key.NewKeySet()
362 node, err := dserv.Get(ctx, k)
363 if err != nil {
360 - notif.PublishQueryEvent(ctx, &notif.QueryEvent{
361 - Type: notif.QueryError,
362 - Extra: err.Error(),
363 - })
364 + return err
365 }
366
367 err = dag.EnumerateChildrenAsync(ctx, dserv, node, kset)
368 if err != nil {
368 - notif.PublishQueryEvent(ctx, &notif.QueryEvent{
369 - Type: notif.QueryError,
370 - Extra: err.Error(),
371 - })
369 + return err
370 }
371
372 for _, k := range kset.Keys() {
@@ -378,16 +376,13 @@ func provideKeysRec(ctx context.Context, r routing.IpfsRouting, dserv dag.DAGSer
376
377 err = r.Provide(ctx, k)
378 if err != nil {
381 - notif.PublishQueryEvent(ctx, &notif.QueryEvent{
382 - Type: notif.QueryError,
383 - Extra: err.Error(),
384 - })
385 - return
379 + return err
380 }
381 provided[k] = struct{}{}
382 }
383 }
384
385 + return nil
386 }
387
388 var findPeerDhtCmd = &cmds.Command{