Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
Use cids in DHT calls
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Jan 15, 2019
1 parent 7abddda commit 163b25f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 18 additions & 2 deletions dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caop
if err != nil {
return nil, err
}
resp, err := api.core().request("dht/findprovs", p.String()).

rp, err := api.core().ResolvePath(ctx, p)
if err != nil {
return nil, err
}

resp, err := api.core().request("dht/findprovs", rp.Cid().String()).
Option("num-providers", options.NumProviders).
Send(ctx)
if err != nil {
Expand All @@ -60,13 +66,18 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caop

for {
var out struct {
Extra string
Type notif.QueryEventType
Responses []peerstore.PeerInfo
}

if err := dec.Decode(&out); err != nil {
return // todo: handle this somehow
}
if out.Type == notif.QueryError {
return // usually a 'not found' error
// todo: handle other errors
}
if out.Type == notif.Provider {
for _, pi := range out.Responses {
select {
Expand All @@ -88,7 +99,12 @@ func (api *DhtAPI) Provide(ctx context.Context, p iface.Path, opts ...caopts.Dht
return err
}

return api.core().request("dht/provide", p.String()).
rp, err := api.core().ResolvePath(ctx, p)
if err != nil {
return err
}

return api.core().request("dht/provide", rp.Cid().String()).
Option("recursive", options.Recursive).
Exec(ctx, nil)
}
Expand Down
3 changes: 1 addition & 2 deletions pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,10 @@ func (api *PubsubAPI) Subscribe(ctx context.Context, topic string, opts ...caopt

return &pubsubSub{
Closer: resp,
dec: json.NewDecoder(resp.Output),
dec: json.NewDecoder(resp.Output),
}, nil
}

func (api *PubsubAPI) core() *HttpApi {
return (*HttpApi)(api)
}

0 comments on commit 163b25f

Please sign in to comment.