提交 b2f6c3e3 作者: Łukasz Magiera

coreapi swarm: missing docs, review

License: MIT
Signed-off-by: 's avatarŁukasz Magiera <magik6k@gmail.com>
上级 6fa2ab0d
......@@ -94,7 +94,7 @@ var swarmPeersCmd = &cmds.Command{
}
if verbose || latency {
lat, err := c.Latency(req.Context)
lat, err := c.Latency()
if err != nil {
return err
}
......@@ -106,7 +106,7 @@ var swarmPeersCmd = &cmds.Command{
}
}
if verbose || streams {
strs, err := c.Streams(req.Context)
strs, err := c.Streams()
if err != nil {
return err
}
......
......@@ -29,10 +29,10 @@ type ConnectionInfo interface {
Direction() net.Direction
// Latency returns last known round trip time to the peer
Latency(context.Context) (time.Duration, error)
Latency() (time.Duration, error)
// Streams returns list of streams established with the peer
Streams(context.Context) ([]protocol.ID, error)
Streams() ([]protocol.ID, error)
}
// SwarmAPI specifies the interface to libp2p swarm
......@@ -46,7 +46,12 @@ type SwarmAPI interface {
// Peers returns the list of peers we are connected to
Peers(context.Context) ([]ConnectionInfo, error)
// KnownAddrs returns the list of all addresses this node is aware of
KnownAddrs(context.Context) (map[peer.ID][]ma.Multiaddr, error)
// LocalAddrs returns the list of announced listening addresses
LocalAddrs(context.Context) ([]ma.Multiaddr, error)
// ListenAddrs returns the list of all listening addresses
ListenAddrs(context.Context) ([]ma.Multiaddr, error)
}
......@@ -2,7 +2,6 @@ package coreapi
import (
"context"
"fmt"
"sort"
"time"
......@@ -37,13 +36,10 @@ func (api *SwarmAPI) Connect(ctx context.Context, pi pstore.PeerInfo) error {
return coreiface.ErrOffline
}
swrm, ok := api.node.PeerHost.Network().(*swarm.Swarm)
if !ok {
return fmt.Errorf("peerhost network was not swarm")
if swrm, ok := api.node.PeerHost.Network().(*swarm.Swarm); ok {
swrm.Backoff().Clear(pi.ID)
}
swrm.Backoff().Clear(pi.ID)
return api.node.PeerHost.Connect(ctx, pi)
}
......@@ -164,11 +160,11 @@ func (ci *connInfo) Direction() net.Direction {
return ci.dir
}
func (ci *connInfo) Latency(context.Context) (time.Duration, error) {
func (ci *connInfo) Latency() (time.Duration, error) {
return ci.api.node.Peerstore.LatencyEWMA(peer.ID(ci.ID())), nil
}
func (ci *connInfo) Streams(context.Context) ([]protocol.ID, error) {
func (ci *connInfo) Streams() ([]protocol.ID, error) {
streams := ci.conn.GetStreams()
out := make([]protocol.ID, len(streams))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论