net

package
v1.3.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: Apache-2.0, MIT Imports: 22 Imported by: 4

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 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 types.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) (*types.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) ([]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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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