coreapi swarm: missing docs, review
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Oct 2, 2018 at 12:31 UTC
b2f6c3e3ed145725c7c9a1e9b6cdb705c8c87bc6
3 files changed
+13
-12
core/commands/swarm.go
+2
-2
@@ -94,7 +94,7 @@ var swarmPeersCmd = &cmds.Command{
94
}
95
96
if verbose || latency {
97
- lat, err := c.Latency(req.Context)
97
+ lat, err := c.Latency()
98
if err != nil {
99
return err
100
}
@@ -106,7 +106,7 @@ var swarmPeersCmd = &cmds.Command{
106
}
107
}
108
if verbose || streams {
109
- strs, err := c.Streams(req.Context)
109
+ strs, err := c.Streams()
110
if err != nil {
111
return err
112
}
core/coreapi/interface/swarm.go
+7
-2
@@ -29,10 +29,10 @@ type ConnectionInfo interface {
29
Direction() net.Direction
30
31
// Latency returns last known round trip time to the peer
32
- Latency(context.Context) (time.Duration, error)
32
+ Latency() (time.Duration, error)
33
34
// Streams returns list of streams established with the peer
35
- Streams(context.Context) ([]protocol.ID, error)
35
+ Streams() ([]protocol.ID, error)
36
}
37
38
// SwarmAPI specifies the interface to libp2p swarm
@@ -46,7 +46,12 @@ type SwarmAPI interface {
46
// Peers returns the list of peers we are connected to
47
Peers(context.Context) ([]ConnectionInfo, error)
48
49
+ // KnownAddrs returns the list of all addresses this node is aware of
50
KnownAddrs(context.Context) (map[peer.ID][]ma.Multiaddr, error)
51
+
52
+ // LocalAddrs returns the list of announced listening addresses
53
LocalAddrs(context.Context) ([]ma.Multiaddr, error)
54
+
55
+ // ListenAddrs returns the list of all listening addresses
56
ListenAddrs(context.Context) ([]ma.Multiaddr, error)
57
}
core/coreapi/swarm.go
+4
-8
@@ -2,7 +2,6 @@ package coreapi
2
3
import (
4
"context"
5
- "fmt"
5
"sort"
6
"time"
7
@@ -37,13 +36,10 @@ func (api *SwarmAPI) Connect(ctx context.Context, pi pstore.PeerInfo) error {
36
return coreiface.ErrOffline
37
}
38
40
- swrm, ok := api.node.PeerHost.Network().(*swarm.Swarm)
41
- if !ok {
42
- return fmt.Errorf("peerhost network was not swarm")
39
+ if swrm, ok := api.node.PeerHost.Network().(*swarm.Swarm); ok {
40
+ swrm.Backoff().Clear(pi.ID)
41
}
42
45
- swrm.Backoff().Clear(pi.ID)
46
-
43
return api.node.PeerHost.Connect(ctx, pi)
44
}
45
@@ -164,11 +160,11 @@ func (ci *connInfo) Direction() net.Direction {
160
return ci.dir
161
}
162
167
-func (ci *connInfo) Latency(context.Context) (time.Duration, error) {
163
+func (ci *connInfo) Latency() (time.Duration, error) {
164
return ci.api.node.Peerstore.LatencyEWMA(peer.ID(ci.ID())), nil
165
}
166
171
-func (ci *connInfo) Streams(context.Context) ([]protocol.ID, error) {
167
+func (ci *connInfo) Streams() ([]protocol.ID, error) {
168
streams := ci.conn.GetStreams()
169
170
out := make([]protocol.ID, len(streams))