net

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2021 License: Apache-2.0, MIT Imports: 21 Imported by: 2

Documentation

Index

Constants

View Source
const (
	MaxFilPeers = 320
	MinFilPeers = 128
)

Variables

This section is empty.

Functions

func AddrInfoToPeerIDs

func AddrInfoToPeerIDs(ai []peer.AddrInfo) []peer.ID

AddrInfoToPeerIDs converts a slice of AddrInfo to a slice of peerID's.

func FilecoinDHT

func FilecoinDHT(network string) protocol.ID

FilecoinDHT is creates a protocol for the filecoin DHT.

func ParseAddresses

func ParseAddresses(ctx context.Context, addrs []string) ([]peer.AddrInfo, error)

ParseAddresses is a function that takes in a slice of string peer addresses (multiaddr + peerid) and returns a slice of properly constructed peers

func PeerAddrsToAddrInfo

func PeerAddrsToAddrInfo(addrs []string) ([]peer.AddrInfo, error)

PeerAddrsToAddrInfo converts a slice of string peer addresses (multiaddr + ipfs peerid) to PeerInfos.

Types

type ConnectionResult

type ConnectionResult struct {
	PeerID peer.ID
	Err    error
}

ConnectionResult represents the result of an attempted connection from the Connect method.

type IPeerMgr

type IPeerMgr interface {
	AddFilecoinPeer(p peer.ID)
	GetPeerLatency(p peer.ID) (time.Duration, bool)
	SetPeerLatency(p peer.ID, latency time.Duration)
	Disconnect(p peer.ID)
	Stop(ctx context.Context) error
	Run(ctx context.Context)
}

type MockPeerMgr

type MockPeerMgr struct {
}

func (MockPeerMgr) AddFilecoinPeer

func (m MockPeerMgr) AddFilecoinPeer(p peer.ID)

func (MockPeerMgr) Disconnect

func (m MockPeerMgr) Disconnect(p peer.ID)

func (MockPeerMgr) GetPeerLatency

func (m MockPeerMgr) GetPeerLatency(p peer.ID) (time.Duration, bool)

func (MockPeerMgr) Run

func (m MockPeerMgr) Run(ctx context.Context)

func (MockPeerMgr) SetPeerLatency

func (m MockPeerMgr) SetPeerLatency(p peer.ID, latency time.Duration)

func (MockPeerMgr) Stop

func (m MockPeerMgr) Stop(ctx context.Context) error

type Network

type Network struct {
	metrics.Reporter
	*Router
	// contains filtered or unexported fields
}

Network is a unified interface for dealing with libp2p

func New

func New(
	host host.Host,
	router *Router,
	reporter metrics.Reporter,
) *Network

New returns a new Network

func (*Network) Connect

func (network *Network) Connect(ctx context.Context, addrs []string) (<-chan ConnectionResult, error)

Connect connects to peers at the given addresses. Does not retry.

func (*Network) GetBandwidthStats

func (network *Network) GetBandwidthStats() metrics.Stats

GetBandwidthStats gets stats on the current bandwidth usage of the network

func (*Network) GetPeerAddresses

func (network *Network) GetPeerAddresses() []ma.Multiaddr

GetPeerAddresses gets the current addresses of the node

func (*Network) GetPeerID

func (network *Network) GetPeerID() peer.ID

GetPeerID gets the current peer id from libp2p-host

func (*Network) Peers

func (network *Network) Peers(ctx context.Context, verbose, latency, streams bool) (*SwarmConnInfos, error)

Peers lists peers currently available on the network

type NewFilPeer

type NewFilPeer struct {
	Id peer.ID //nolint
}

type PeerMgr

type PeerMgr struct {
	// contains filtered or unexported fields
}

func NewPeerMgr

func NewPeerMgr(h host.Host, dht *dht.IpfsDHT, period time.Duration, bootstrap []peer.AddrInfo) (*PeerMgr, error)

func (*PeerMgr) AddFilecoinPeer

func (pmgr *PeerMgr) AddFilecoinPeer(p peer.ID)

func (*PeerMgr) Disconnect

func (pmgr *PeerMgr) Disconnect(p peer.ID)

func (*PeerMgr) GetPeerLatency

func (pmgr *PeerMgr) GetPeerLatency(p peer.ID) (time.Duration, bool)

func (*PeerMgr) Run

func (pmgr *PeerMgr) Run(ctx context.Context)

func (*PeerMgr) SetPeerLatency

func (pmgr *PeerMgr) SetPeerLatency(p peer.ID, latency time.Duration)

func (*PeerMgr) Stop

func (pmgr *PeerMgr) Stop(ctx context.Context) error

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router exposes the methods on the internal filecoin router that are needed by the system plumbing API.

func NewRouter

func NewRouter(r routing.Routing) *Router

NewRouter builds a new router.

func (*Router) FindPeer

func (r *Router) FindPeer(ctx context.Context, peerID peer.ID) (peer.AddrInfo, error)

FindPeer searches the libp2p router for a given peer id

func (*Router) FindProvidersAsync

func (r *Router) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo

FindProvidersAsync searches for and returns peers who are able to provide a given key.

func (*Router) GetClosestPeers

func (r *Router) GetClosestPeers(ctx context.Context, key string) (<-chan peer.ID, error)

GetClosestPeers returns a channel of the K closest peers to the given key, K is the 'K Bucket' parameter of the Kademlia DHT protocol.

type SwarmConnInfo

type SwarmConnInfo struct {
	Addr    string
	Peer    string
	Latency string
	Muxer   string
	Streams []SwarmStreamInfo
}

SwarmConnInfo represents details about a single swarm connection.

func (*SwarmConnInfo) Len

func (ci *SwarmConnInfo) Len() int

func (*SwarmConnInfo) Less

func (ci *SwarmConnInfo) Less(i, j int) bool

func (*SwarmConnInfo) Swap

func (ci *SwarmConnInfo) Swap(i, j int)

type SwarmConnInfos

type SwarmConnInfos struct {
	Peers []SwarmConnInfo
}

SwarmConnInfos represent details about a list of swarm connections.

func (SwarmConnInfos) Len

func (ci SwarmConnInfos) Len() int

func (SwarmConnInfos) Less

func (ci SwarmConnInfos) Less(i, j int) bool

func (SwarmConnInfos) Swap

func (ci SwarmConnInfos) Swap(i, j int)

type SwarmStreamInfo

type SwarmStreamInfo struct {
	Protocol string
}

SwarmStreamInfo represents details about a single swarm stream.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL