@cryptotaxi247 / kubo / commits / 9345cfa7b

update to consolidated libp2p interface package (#21)

and fix parsing of connection latencies This commit was moved from ipfs/go-ipfs-http-client@fd5cce4cbc9d95617ded33849c437a492f5e9d96

godcong committed Jul 21, 2019 at 12:33 UTC 9345cfa7b83d3fb2fb470fa1e77e7af89087452b
4 files changed +27 -28
client/httpapi/dht.go
+15 -16
@@ -6,38 +6,37 @@ 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-peer"
10 - "github.com/libp2p/go-libp2p-peerstore"
11 - notif "github.com/libp2p/go-libp2p-routing/notifications"
9 + "github.com/libp2p/go-libp2p-core/peer"
10 + "github.com/libp2p/go-libp2p-core/routing"
11 )
12
13 type DhtAPI HttpApi
14
16 -func (api *DhtAPI) FindPeer(ctx context.Context, p peer.ID) (peerstore.PeerInfo, error) {
15 +func (api *DhtAPI) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error) {
16 var out struct {
18 - Type notif.QueryEventType
19 - Responses []peerstore.PeerInfo
17 + Type routing.QueryEventType
18 + Responses []peer.AddrInfo
19 }
20 resp, err := api.core().Request("dht/findpeer", p.Pretty()).Send(ctx)
21 if err != nil {
23 - return peerstore.PeerInfo{}, err
22 + return peer.AddrInfo{}, err
23 }
24 if resp.Error != nil {
26 - return peerstore.PeerInfo{}, resp.Error
25 + return peer.AddrInfo{}, resp.Error
26 }
27 defer resp.Close()
28 dec := json.NewDecoder(resp.Output)
29 for {
30 if err := dec.Decode(&out); err != nil {
32 - return peerstore.PeerInfo{}, err
31 + return peer.AddrInfo{}, err
32 }
34 - if out.Type == notif.FinalPeer {
33 + if out.Type == routing.FinalPeer {
34 return out.Responses[0], nil
35 }
36 }
37 }
38
40 -func (api *DhtAPI) FindProviders(ctx context.Context, p path.Path, opts ...caopts.DhtFindProvidersOption) (<-chan peerstore.PeerInfo, error) {
39 +func (api *DhtAPI) FindProviders(ctx context.Context, p path.Path, opts ...caopts.DhtFindProvidersOption) (<-chan peer.AddrInfo, error) {
40 options, err := caopts.DhtFindProvidersOptions(opts...)
41 if err != nil {
42 return nil, err
@@ -57,7 +56,7 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p path.Path, opts ...caopt
56 if resp.Error != nil {
57 return nil, resp.Error
58 }
60 - res := make(chan peerstore.PeerInfo)
59 + res := make(chan peer.AddrInfo)
60
61 go func() {
62 defer resp.Close()
@@ -67,18 +66,18 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p path.Path, opts ...caopt
66 for {
67 var out struct {
68 Extra string
70 - Type notif.QueryEventType
71 - Responses []peerstore.PeerInfo
69 + Type routing.QueryEventType
70 + Responses []peer.AddrInfo
71 }
72
73 if err := dec.Decode(&out); err != nil {
74 return // todo: handle this somehow
75 }
77 - if out.Type == notif.QueryError {
76 + if out.Type == routing.QueryError {
77 return // usually a 'not found' error
78 // todo: handle other errors
79 }
81 - if out.Type == notif.Provider {
80 + if out.Type == routing.Provider {
81 for _, pi := range out.Responses {
82 select {
83 case res <- pi:
client/httpapi/key.go
+1 -1
@@ -7,7 +7,7 @@ import (
7 "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-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 "github.com/ipfs/interface-go-ipfs-core"
10 caopts "github.com/ipfs/interface-go-ipfs-core/options"
11 - "github.com/libp2p/go-libp2p-peer"
11 + "github.com/libp2p/go-libp2p-core/peer"
12 )
13
14 type PubsubAPI HttpApi
client/httpapi/swarm.go
+10 -10
@@ -5,16 +5,15 @@ import (
5 "time"
6
7 "github.com/ipfs/interface-go-ipfs-core"
8 - inet "github.com/libp2p/go-libp2p-net"
9 - "github.com/libp2p/go-libp2p-peer"
10 - "github.com/libp2p/go-libp2p-peerstore"
11 - "github.com/libp2p/go-libp2p-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
14 type SwarmAPI HttpApi
15
17 -func (api *SwarmAPI) Connect(ctx context.Context, pi peerstore.PeerInfo) error {
16 +func (api *SwarmAPI) Connect(ctx context.Context, pi peer.AddrInfo) error {
17 pidma, err := multiaddr.NewComponent("p2p", pi.ID.Pretty())
18 if err != nil {
19 return err
@@ -37,7 +36,7 @@ type connInfo struct {
36 peer peer.ID
37 latency time.Duration
38 muxer string
40 - direction inet.Direction
39 + direction network.Direction
40 streams []protocol.ID
41 }
42
@@ -49,7 +48,7 @@ func (c *connInfo) Address() multiaddr.Multiaddr {
48 return c.addr
49 }
50
52 -func (c *connInfo) Direction() inet.Direction {
51 +func (c *connInfo) Direction() network.Direction {
52 return c.direction
53 }
54
@@ -66,9 +65,9 @@ func (api *SwarmAPI) Peers(ctx context.Context) ([]iface.ConnectionInfo, error)
65 Peers []struct {
66 Addr string
67 Peer string
69 - Latency time.Duration
68 + Latency string
69 Muxer string
71 - Direction inet.Direction
70 + Direction network.Direction
71 Streams []struct {
72 Protocol string
73 }
@@ -85,8 +84,9 @@ func (api *SwarmAPI) Peers(ctx context.Context) ([]iface.ConnectionInfo, error)
84
85 res := make([]iface.ConnectionInfo, len(resp.Peers))
86 for i, conn := range resp.Peers {
87 + latency, _ := time.ParseDuration(conn.Latency)
88 out := &connInfo{
89 - latency: conn.Latency,
89 + latency: latency,
90 muxer: conn.Muxer,
91 direction: conn.Direction,
92 }