coreapi: swarm interface
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Mar 10, 2018 at 18:54 UTC
1373218519ab9d8ed7ae2229438e3470e019ce83
1 file changed
+37
core/coreapi/interface/swarm.go
new
+37
@@ -0,0 +1,37 @@
1
+package iface
2
+
3
+import (
4
+ "time"
5
+
6
+ "context"
7
+ ma "gx/ipfs/QmWWQ2Txc2c6tqjsBpzg5Ar652cHPGNsQQp2SejkNmkUMb/go-multiaddr"
8
+ peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
9
+)
10
+
11
+// PeerInfo contains information about a peer
12
+type PeerInfo interface {
13
+ // ID returns PeerID
14
+ ID() peer.ID
15
+
16
+ // Address returns the multiaddress via which we are connected with the peer
17
+ Address() ma.Multiaddr
18
+
19
+ // Latency returns last known round trip time to the peer
20
+ Latency() time.Duration
21
+
22
+ // Streams returns list of streams established with the peer
23
+ // TODO: should this return multicodecs?
24
+ Streams() []string
25
+}
26
+
27
+// SwarmAPI specifies the interface to libp2p swarm
28
+type SwarmAPI interface {
29
+ // Connect to a given address
30
+ Connect(context.Context, ma.Multiaddr) error
31
+
32
+ // Disconnect from a given address
33
+ Disconnect(context.Context, ma.Multiaddr) error
34
+
35
+ // Peers returns the list of peers we are connected to
36
+ Peers(context.Context) ([]PeerInfo, error)
37
+}