@cryptotaxi247 / kubo / commits / 9b24cf0aa

Use cids in DHT calls

This commit was moved from ipfs/go-ipfs-http-client@163b25f8b88eb98ddae50978440e3940070fabc0

Łukasz Magiera committed Jan 15, 2019 at 18:49 UTC 9b24cf0aafa94a7b4cb4401b6fbb9c959bde09b5
2 files changed +19 -4
client/httpapi/dht.go
+18 -2
@@ -42,7 +42,13 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caop
42 if err != nil {
43 return nil, err
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()).
52 Option("num-providers", options.NumProviders).
53 Send(ctx)
54 if err != nil {
@@ -60,6 +66,7 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caop
66
67 for {
68 var out struct {
69 + Extra string
70 Type notif.QueryEventType
71 Responses []peerstore.PeerInfo
72 }
@@ -67,6 +74,10 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caop
74 if err := dec.Decode(&out); err != nil {
75 return // todo: handle this somehow
76 }
77 + if out.Type == notif.QueryError {
78 + return // usually a 'not found' error
79 + // todo: handle other errors
80 + }
81 if out.Type == notif.Provider {
82 for _, pi := range out.Responses {
83 select {
@@ -88,7 +99,12 @@ func (api *DhtAPI) Provide(ctx context.Context, p iface.Path, opts ...caopts.Dht
99 return err
100 }
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()).
108 Option("recursive", options.Recursive).
109 Exec(ctx, nil)
110 }
client/httpapi/pubsub.go
+1 -2
@@ -119,11 +119,10 @@ func (api *PubsubAPI) Subscribe(ctx context.Context, topic string, opts ...caopt
119
120 return &pubsubSub{
121 Closer: resp,
122 - dec: json.NewDecoder(resp.Output),
122 + dec: json.NewDecoder(resp.Output),
123 }, nil
124 }
125
126 func (api *PubsubAPI) core() *HttpApi {
127 return (*HttpApi)(api)
128 }
129 -