@cryptotaxi247 / kubo / commits / 75b6f45f7

chore: bumps for Kubo 0.18 and Routing API with stub for Put

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

Jorropo committed Feb 6, 2023 at 15:32 UTC 75b6f45f765237d611168a5e1c09915f380e7bd7
11 files changed +71 -12
client/httpapi/api.go
+4
@@ -195,3 +195,7 @@ func (api *HttpApi) Swarm() iface.SwarmAPI {
195 func (api *HttpApi) PubSub() iface.PubSubAPI {
196 return (*PubsubAPI)(api)
197 }
198 +
199 +func (api *HttpApi) Routing() iface.RoutingAPI {
200 + return (*RoutingAPI)(api)
201 +}
client/httpapi/apifile.go
+1 -1
@@ -7,7 +7,7 @@ import (
7 "io"
8
9 "github.com/ipfs/go-cid"
10 - files "github.com/ipfs/go-ipfs-files"
10 + "github.com/ipfs/go-libipfs/files"
11 unixfs "github.com/ipfs/go-unixfs"
12 "github.com/ipfs/interface-go-ipfs-core/path"
13 )
client/httpapi/dag.go
+1 -1
@@ -6,9 +6,9 @@ import (
6 "fmt"
7 "io"
8
9 - blocks "github.com/ipfs/go-block-format"
9 "github.com/ipfs/go-cid"
10 format "github.com/ipfs/go-ipld-format"
11 + "github.com/ipfs/go-libipfs/blocks"
12 "github.com/ipfs/interface-go-ipfs-core/options"
13 "github.com/ipfs/interface-go-ipfs-core/path"
14 multicodec "github.com/multiformats/go-multicodec"
client/httpapi/dht.go
+2 -2
@@ -6,8 +6,8 @@ import (
6
7 caopts "github.com/ipfs/interface-go-ipfs-core/options"
8 "github.com/ipfs/interface-go-ipfs-core/path"
9 - "github.com/libp2p/go-libp2p-core/peer"
10 - "github.com/libp2p/go-libp2p-core/routing"
9 + "github.com/libp2p/go-libp2p/core/peer"
10 + "github.com/libp2p/go-libp2p/core/routing"
11 )
12
13 type DhtAPI HttpApi
client/httpapi/key.go
+1 -1
@@ -7,7 +7,7 @@ import (
7 iface "github.com/ipfs/interface-go-ipfs-core"
8 caopts "github.com/ipfs/interface-go-ipfs-core/options"
9 "github.com/ipfs/interface-go-ipfs-core/path"
10 - "github.com/libp2p/go-libp2p-core/peer"
10 + "github.com/libp2p/go-libp2p/core/peer"
11 )
12
13 type KeyAPI HttpApi
client/httpapi/pubsub.go
+1 -1
@@ -8,7 +8,7 @@ import (
8
9 iface "github.com/ipfs/interface-go-ipfs-core"
10 caopts "github.com/ipfs/interface-go-ipfs-core/options"
11 - "github.com/libp2p/go-libp2p-core/peer"
11 + "github.com/libp2p/go-libp2p/core/peer"
12 mbase "github.com/multiformats/go-multibase"
13 )
14
client/httpapi/requestbuilder.go
+1 -1
@@ -8,7 +8,7 @@ import (
8 "strconv"
9 "strings"
10
11 - files "github.com/ipfs/go-ipfs-files"
11 + "github.com/ipfs/go-libipfs/files"
12 )
13
14 type RequestBuilder interface {
client/httpapi/response.go
+1 -1
@@ -12,7 +12,7 @@ import (
12
13 cmds "github.com/ipfs/go-ipfs-cmds"
14 cmdhttp "github.com/ipfs/go-ipfs-cmds/http"
15 - files "github.com/ipfs/go-ipfs-files"
15 + "github.com/ipfs/go-libipfs/files"
16 )
17
18 type Error = cmds.Error
client/httpapi/routing.go new
+55
@@ -0,0 +1,55 @@
1 +package httpapi
2 +
3 +import (
4 + "bytes"
5 + "context"
6 + "encoding/base64"
7 + "encoding/json"
8 +
9 + "github.com/libp2p/go-libp2p/core/routing"
10 +)
11 +
12 +type RoutingAPI HttpApi
13 +
14 +func (api *RoutingAPI) Get(ctx context.Context, key string) ([]byte, error) {
15 + resp, err := api.core().Request("routing/get", key).Send(ctx)
16 + if err != nil {
17 + return nil, err
18 + }
19 + if resp.Error != nil {
20 + return nil, resp.Error
21 + }
22 + defer resp.Close()
23 +
24 + var out routing.QueryEvent
25 +
26 + dec := json.NewDecoder(resp.Output)
27 + if err := dec.Decode(&out); err != nil {
28 + return nil, err
29 + }
30 +
31 + res, err := base64.StdEncoding.DecodeString(out.Extra)
32 + if err != nil {
33 + return nil, err
34 + }
35 +
36 + return res, nil
37 +}
38 +
39 +func (api *RoutingAPI) Put(ctx context.Context, key string, value []byte) error {
40 + resp, err := api.core().Request("routing/put", key).
41 + FileBody(bytes.NewReader(value)).
42 + Send(ctx)
43 +
44 + if err != nil {
45 + return err
46 + }
47 + if resp.Error != nil {
48 + return resp.Error
49 + }
50 + return nil
51 +}
52 +
53 +func (api *RoutingAPI) core() *HttpApi {
54 + return (*HttpApi)(api)
55 +}
client/httpapi/swarm.go
+3 -3
@@ -5,9 +5,9 @@ import (
5 "time"
6
7 iface "github.com/ipfs/interface-go-ipfs-core"
8 - "github.com/libp2p/go-libp2p-core/network"
9 - "github.com/libp2p/go-libp2p-core/peer"
10 - "github.com/libp2p/go-libp2p-core/protocol"
8 + "github.com/libp2p/go-libp2p/core/network"
9 + "github.com/libp2p/go-libp2p/core/peer"
10 + "github.com/libp2p/go-libp2p/core/protocol"
11 "github.com/multiformats/go-multiaddr"
12 )
13
client/httpapi/unixfs.go
+1 -1
@@ -8,7 +8,7 @@ import (
8 "io"
9
10 "github.com/ipfs/go-cid"
11 - files "github.com/ipfs/go-ipfs-files"
11 + "github.com/ipfs/go-libipfs/files"
12 unixfs "github.com/ipfs/go-unixfs"
13 unixfs_pb "github.com/ipfs/go-unixfs/pb"
14 iface "github.com/ipfs/interface-go-ipfs-core"