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

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

Steven Allen's avatar
Steven Allen committed
8
	ma "gx/ipfs/QmNTCey11oxhb1AxDnQBRHtdhap6Ctud872NjAYPYYXPuc/go-multiaddr"
Steven Allen's avatar
Steven Allen committed
9 10 11
	"gx/ipfs/QmPJxxDsX2UbchSHobbYuvz7qnyJTFKvaKMzE2rZWJ4x5B/go-libp2p-peer"
	pstore "gx/ipfs/QmQFFp4ntkd4C14sP3FaH9WJyBuetuGUVo6dShNHvnoEvC/go-libp2p-peerstore"
	net "gx/ipfs/QmZ7cBWUXkyWTMN4qH6NGoyMVs7JugyFChBNP4ZUp5rJHH/go-libp2p-net"
12
	"gx/ipfs/QmZNkThpqfVXs9GNbexPrfBbXSLNYeKrE7jwFM2oqHbyqN/go-libp2p-protocol"
Łukasz Magiera's avatar
Łukasz Magiera committed
13 14
)

15 16 17
var (
	ErrNotConnected = errors.New("not connected")
	ErrConnNotFound = errors.New("conn not found")
18
)
19 20 21

// ConnectionInfo contains information about a peer
type ConnectionInfo interface {
Łukasz Magiera's avatar
Łukasz Magiera committed
22 23 24 25 26 27
	// ID returns PeerID
	ID() peer.ID

	// Address returns the multiaddress via which we are connected with the peer
	Address() ma.Multiaddr

28 29 30
	// Direction returns which way the connection was established
	Direction() net.Direction

Łukasz Magiera's avatar
Łukasz Magiera committed
31
	// Latency returns last known round trip time to the peer
32
	Latency() (time.Duration, error)
Łukasz Magiera's avatar
Łukasz Magiera committed
33 34

	// Streams returns list of streams established with the peer
35
	Streams() ([]protocol.ID, error)
Łukasz Magiera's avatar
Łukasz Magiera committed
36 37 38 39
}

// SwarmAPI specifies the interface to libp2p swarm
type SwarmAPI interface {
40 41
	// Connect to a given peer
	Connect(context.Context, pstore.PeerInfo) error
Łukasz Magiera's avatar
Łukasz Magiera committed
42 43 44 45 46

	// Disconnect from a given address
	Disconnect(context.Context, ma.Multiaddr) error

	// 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)
Łukasz Magiera's avatar
Łukasz Magiera committed
57
}