swarm.go 1.24 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"

8
	ma "gx/ipfs/QmYmsdtJ3HsodkePE3eU3TsCaP2YvPZJ4LoXnNkDE5Tpt7/go-multiaddr"
9 10 11
	"gx/ipfs/QmZNkThpqfVXs9GNbexPrfBbXSLNYeKrE7jwFM2oqHbyqN/go-libp2p-protocol"
	"gx/ipfs/QmbNepETomvmXfz1X5pHNFD2QuPqnqi47dTd94QJWSorQ3/go-libp2p-peer"
	pstore "gx/ipfs/QmfAQMFpgDU2U4BXG64qVr8HSiictfWvkSBz7Y2oDj65st/go-libp2p-peerstore"
Łukasz Magiera's avatar
Łukasz Magiera committed
12 13
)

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

// ConnectionInfo contains information about a peer
type ConnectionInfo interface {
Łukasz Magiera's avatar
Łukasz Magiera committed
21 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

	// Latency returns last known round trip time to the peer
Łukasz Magiera's avatar
Łukasz Magiera committed
28
	Latency(context.Context) (time.Duration, error)
Łukasz Magiera's avatar
Łukasz Magiera committed
29 30

	// Streams returns list of streams established with the peer
31
	Streams(context.Context) ([]protocol.ID, error)
Łukasz Magiera's avatar
Łukasz Magiera committed
32 33 34 35
}

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

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

	// Peers returns the list of peers we are connected to
43
	Peers(context.Context) ([]ConnectionInfo, error)
Łukasz Magiera's avatar
Łukasz Magiera committed
44
}