| 1 | package iface |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "time" |
| 7 | |
| 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 | |
| 12 | ma "github.com/multiformats/go-multiaddr" |
| 13 | ) |
| 14 | |
| 15 | var ( |
| 16 | ErrNotConnected = errors.New("not connected") |
| 17 | ErrConnNotFound = errors.New("conn not found") |
| 18 | ) |
| 19 | |
| 20 | // ConnectionInfo contains information about a peer |
| 21 | type ConnectionInfo interface { |
| 22 | // ID returns PeerID |
| 23 | ID() peer.ID |
| 24 | |
| 25 | // Address returns the multiaddress via which we are connected with the peer |
| 26 | Address() ma.Multiaddr |
| 27 | |
| 28 | // Direction returns which way the connection was established |
| 29 | Direction() network.Direction |
| 30 | |
| 31 | // Latency returns last known round trip time to the peer |
| 32 | Latency() (time.Duration, error) |
| 33 | |
| 34 | // Streams returns list of streams established with the peer |
| 35 | Streams() ([]protocol.ID, error) |
| 36 | } |
| 37 | |
| 38 | // SwarmAPI specifies the interface to libp2p swarm |
| 39 | type SwarmAPI interface { |
| 40 | // Connect to a given peer |
| 41 | Connect(context.Context, peer.AddrInfo) error |
| 42 | |
| 43 | // Disconnect from a given address |
| 44 | Disconnect(context.Context, ma.Multiaddr) error |
| 45 | |
| 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 | } |