Skip to content

Commit

Permalink
address CR feedback
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <[email protected]>
  • Loading branch information
whyrusleeping committed Aug 24, 2016
1 parent 798569b commit 0a6ab30
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions core/commands/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ var provideRefDhtCmd = &cmds.Command{
},

Arguments: []cmds.Argument{
cmds.StringArg("key", true, true, "The key to find providers for.").EnableStdin(),
cmds.StringArg("key", true, true, "The key[s] to send provide records for.").EnableStdin(),
},
Options: []cmds.Option{
cmds.BoolOption("verbose", "v", "Print extra information.").Default(false),
Expand Down Expand Up @@ -294,10 +294,17 @@ var provideRefDhtCmd = &cmds.Command{

go func() {
defer close(events)
var err error
if rec {
provideKeysRec(ctx, n.Routing, n.DAG, keys)
err = provideKeysRec(ctx, n.Routing, n.DAG, keys)
} else {
provideKeys(ctx, n.Routing, keys)
err = provideKeys(ctx, n.Routing, keys)
}
if err != nil {
notif.PublishQueryEvent(ctx, &notif.QueryEvent{
Type: notif.QueryError,
Extra: err.Error(),
})
}
}()
},
Expand Down Expand Up @@ -338,37 +345,28 @@ var provideRefDhtCmd = &cmds.Command{
Type: notif.QueryEvent{},
}

func provideKeys(ctx context.Context, r routing.IpfsRouting, keys []key.Key) {
func provideKeys(ctx context.Context, r routing.IpfsRouting, keys []key.Key) error {
for _, k := range keys {
err := r.Provide(ctx, k)
if err != nil {
notif.PublishQueryEvent(ctx, &notif.QueryEvent{
Type: notif.QueryError,
Extra: err.Error(),
})
return
return err
}
}
return nil
}

func provideKeysRec(ctx context.Context, r routing.IpfsRouting, dserv dag.DAGService, keys []key.Key) {
func provideKeysRec(ctx context.Context, r routing.IpfsRouting, dserv dag.DAGService, keys []key.Key) error {
provided := make(map[key.Key]struct{})
for _, k := range keys {
kset := key.NewKeySet()
node, err := dserv.Get(ctx, k)
if err != nil {
notif.PublishQueryEvent(ctx, &notif.QueryEvent{
Type: notif.QueryError,
Extra: err.Error(),
})
return err
}

err = dag.EnumerateChildrenAsync(ctx, dserv, node, kset)
if err != nil {
notif.PublishQueryEvent(ctx, &notif.QueryEvent{
Type: notif.QueryError,
Extra: err.Error(),
})
return err
}

for _, k := range kset.Keys() {
Expand All @@ -378,16 +376,13 @@ func provideKeysRec(ctx context.Context, r routing.IpfsRouting, dserv dag.DAGSer

err = r.Provide(ctx, k)
if err != nil {
notif.PublishQueryEvent(ctx, &notif.QueryEvent{
Type: notif.QueryError,
Extra: err.Error(),
})
return
return err
}
provided[k] = struct{}{}
}
}

return nil
}

var findPeerDhtCmd = &cmds.Command{
Expand Down

0 comments on commit 0a6ab30

Please sign in to comment.