swarm.go 1015 Bytes
Newer Older
Łukasz Magiera's avatar
Łukasz Magiera committed
1 2 3
package iface

import (
Łukasz Magiera's avatar
Łukasz Magiera committed
4
	"context"
Łukasz Magiera's avatar
Łukasz Magiera committed
5 6
	"time"

7 8
	peer "gx/ipfs/QmQsErDt8Qgw1XrsXf2BpEzDgGWtB1YLsTAARBup5b6B9W/go-libp2p-peer"
	ma "gx/ipfs/QmYmsdtJ3HsodkePE3eU3TsCaP2YvPZJ4LoXnNkDE5Tpt7/go-multiaddr"
Łukasz Magiera's avatar
Łukasz Magiera committed
9 10 11 12 13 14 15 16 17 18 19
)

// 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
Łukasz Magiera's avatar
Łukasz Magiera committed
20
	Latency(context.Context) (time.Duration, error)
Łukasz Magiera's avatar
Łukasz Magiera committed
21 22 23

	// Streams returns list of streams established with the peer
	// TODO: should this return multicodecs?
Łukasz Magiera's avatar
Łukasz Magiera committed
24
	Streams(context.Context) ([]string, error)
Łukasz Magiera's avatar
Łukasz Magiera committed
25 26 27 28 29 30 31 32 33 34 35 36 37
}

// 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)
}