@@ -42,7 +42,13 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caop
42
42
if err != nil {
43
43
return nil , err
44
44
}
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 ()).
46
52
Option ("num-providers" , options .NumProviders ).
47
53
Send (ctx )
48
54
if err != nil {
@@ -60,13 +66,18 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caop
60
66
61
67
for {
62
68
var out struct {
69
+ Extra string
63
70
Type notif.QueryEventType
64
71
Responses []peerstore.PeerInfo
65
72
}
66
73
67
74
if err := dec .Decode (& out ); err != nil {
68
75
return // todo: handle this somehow
69
76
}
77
+ if out .Type == notif .QueryError {
78
+ return // usually a 'not found' error
79
+ // todo: handle other errors
80
+ }
70
81
if out .Type == notif .Provider {
71
82
for _ , pi := range out .Responses {
72
83
select {
@@ -88,7 +99,12 @@ func (api *DhtAPI) Provide(ctx context.Context, p iface.Path, opts ...caopts.Dht
88
99
return err
89
100
}
90
101
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 ()).
92
108
Option ("recursive" , options .Recursive ).
93
109
Exec (ctx , nil )
94
110
}
0 commit comments