From 398a8ffdf544dac64be994ce4a34ef3013d9d584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sat, 10 Mar 2018 18:54:58 +0100 Subject: [PATCH] coreapi: swarm interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit License: MIT Signed-off-by: Ɓukasz Magiera This commit was moved from ipfs/interface-go-ipfs-core@bc2ae0a441ed2da875bf2d815766e90b2c2a4d9f --- coreiface/swarm.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 coreiface/swarm.go diff --git a/coreiface/swarm.go b/coreiface/swarm.go new file mode 100644 index 000000000..1ec260e07 --- /dev/null +++ b/coreiface/swarm.go @@ -0,0 +1,37 @@ +package iface + +import ( + "time" + + "context" + ma "gx/ipfs/QmWWQ2Txc2c6tqjsBpzg5Ar652cHPGNsQQp2SejkNmkUMb/go-multiaddr" + peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer" +) + +// PeerInfo contains information about a peer +type PeerInfo interface { + // ID returns PeerID + ID() peer.ID + + // Address returns the multiaddress via which we are connected with the peer + Address() ma.Multiaddr + + // Latency returns last known round trip time to the peer + Latency() time.Duration + + // Streams returns list of streams established with the peer + // TODO: should this return multicodecs? + Streams() []string +} + +// SwarmAPI specifies the interface to libp2p swarm +type SwarmAPI interface { + // Connect to a given address + Connect(context.Context, ma.Multiaddr) error + + // Disconnect from a given address + Disconnect(context.Context, ma.Multiaddr) error + + // Peers returns the list of peers we are connected to + Peers(context.Context) ([]PeerInfo, error) +}