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

Commit 163b25f

Browse files
committed
Use cids in DHT calls
1 parent 7abddda commit 163b25f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

dht.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caop
4242
if err != nil {
4343
return nil, err
4444
}
45-
resp, err := api.core().request("dht/findprovs", p.String()).
45+
46+
rp, err := api.core().ResolvePath(ctx, p)
47+
if err != nil {
48+
return nil, err
49+
}
50+
51+
resp, err := api.core().request("dht/findprovs", rp.Cid().String()).
4652
Option("num-providers", options.NumProviders).
4753
Send(ctx)
4854
if err != nil {
@@ -60,13 +66,18 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caop
6066

6167
for {
6268
var out struct {
69+
Extra string
6370
Type notif.QueryEventType
6471
Responses []peerstore.PeerInfo
6572
}
6673

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

91-
return api.core().request("dht/provide", p.String()).
102+
rp, err := api.core().ResolvePath(ctx, p)
103+
if err != nil {
104+
return err
105+
}
106+
107+
return api.core().request("dht/provide", rp.Cid().String()).
92108
Option("recursive", options.Recursive).
93109
Exec(ctx, nil)
94110
}

pubsub.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,10 @@ func (api *PubsubAPI) Subscribe(ctx context.Context, topic string, opts ...caopt
119119

120120
return &pubsubSub{
121121
Closer: resp,
122-
dec: json.NewDecoder(resp.Output),
122+
dec: json.NewDecoder(resp.Output),
123123
}, nil
124124
}
125125

126126
func (api *PubsubAPI) core() *HttpApi {
127127
return (*HttpApi)(api)
128128
}
129-

0 commit comments

Comments
 (0)