|
| 1 | +package iface |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "errors" |
| 6 | + "time" |
| 7 | + |
| 8 | + ma "gx/ipfs/QmYmsdtJ3HsodkePE3eU3TsCaP2YvPZJ4LoXnNkDE5Tpt7/go-multiaddr" |
| 9 | + "gx/ipfs/QmZNkThpqfVXs9GNbexPrfBbXSLNYeKrE7jwFM2oqHbyqN/go-libp2p-protocol" |
| 10 | + "gx/ipfs/QmbNepETomvmXfz1X5pHNFD2QuPqnqi47dTd94QJWSorQ3/go-libp2p-peer" |
| 11 | + pstore "gx/ipfs/QmfAQMFpgDU2U4BXG64qVr8HSiictfWvkSBz7Y2oDj65st/go-libp2p-peerstore" |
| 12 | + net "gx/ipfs/QmfDPh144WGBqRxZb1TGDHerbMnZATrHZggAPw7putNnBq/go-libp2p-net" |
| 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() net.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, pstore.PeerInfo) 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 | +} |
0 commit comments