discovery

package
v1.2.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: Apache-2.0, MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadGenesis = fmt.Errorf("bad genesis block")

ErrBadGenesis is the error returned when a mismatch in genesis blocks happens.

Functions

This section is empty.

Types

type Bootstrapper

type Bootstrapper struct {
	// Config
	// MinPeerThreshold is the number of connections it attempts to maintain.
	MinPeerThreshold int

	// Period is the interval at which it periodically checks to see
	// if the threshold is maintained.
	Period time.Duration
	// ConnectionTimeout is how long to wait before timing out a connection attempt.
	ConnectionTimeout time.Duration

	// Does the work. Usually Bootstrapper.bootstrap. Argument is a slice of
	// currently-connected peers (so it won't attempt to reconnect).
	Bootstrap func([]peer.ID)
	// contains filtered or unexported fields
}

Bootstrapper attempts to keep the p2p host connected to the filecoin network by keeping a minimum threshold of connections. If the threshold isn't met it connects to a random subset of the bootstrap peers. It does not use peer routing to discover new peers. To stop a Bootstrapper cancel the context passed in Start() or call Stop().

func NewBootstrapper

func NewBootstrapper(bootstrapPeers []peer.AddrInfo, h host.Host, d inet.Dialer, r routing.Routing, minPeer int, period time.Duration) *Bootstrapper

NewBootstrapper returns a new Bootstrapper that will attempt to keep connected to the filecoin network by connecting to the given bootstrap peers.

func (*Bootstrapper) Start

func (b *Bootstrapper) Start(ctx context.Context)

Start starts the Bootstrapper bootstrapping. Cancel `ctx` or call Stop() to stop it.

func (*Bootstrapper) Stop

func (b *Bootstrapper) Stop()

Stop stops the Bootstrapper.

type GetTipSetFunc

type GetTipSetFunc func() (*types.TipSet, error)

type HelloMessage

type HelloMessage struct {
	HeaviestTipSetCids   types.TipSetKey
	HeaviestTipSetHeight abi.ChainEpoch
	HeaviestTipSetWeight fbig.Int
	GenesisHash          cid.Cid
}

HelloMessage is the data structure of a single message in the hello protocol.

func (*HelloMessage) MarshalCBOR

func (t *HelloMessage) MarshalCBOR(w io.Writer) error

func (*HelloMessage) UnmarshalCBOR

func (t *HelloMessage) UnmarshalCBOR(r io.Reader) error

type HelloProtocolHandler

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

HelloProtocolHandler implements the 'Hello' protocol handler.

Upon connecting to a new node, we send them a message containing some information about the state of our chain, and receive the same information from them. This is used to initiate a chainsync and detect connections to forks.

func NewHelloProtocolHandler

func NewHelloProtocolHandler(h host.Host,
	peerMgr fnet.IPeerMgr,
	exchange exchange.Client,
	chainStore *chain.Store,
	messageStore *chain.MessageStore,
	gen cid.Cid,
	helloTimeOut time.Duration,
) *HelloProtocolHandler

NewHelloProtocolHandler creates a new instance of the hello protocol `Handler` and registers it to the given `host.Host`.

func (*HelloProtocolHandler) Register

func (h *HelloProtocolHandler) Register(peerDiscoveredCallback PeerDiscoveredCallback, getHeaviestTipSet GetTipSetFunc)

Register registers the handler with the network.

type LatencyMessage

type LatencyMessage struct {
	TArrival int64
	TSent    int64
}

LatencyMessage is written in response to a hello message for measuring peer latency.

func (*LatencyMessage) MarshalCBOR

func (t *LatencyMessage) MarshalCBOR(w io.Writer) error

func (*LatencyMessage) UnmarshalCBOR

func (t *LatencyMessage) UnmarshalCBOR(r io.Reader) error

type NoopDiscovery

type NoopDiscovery struct{}

NoopDiscovery satisfies the discovery interface without doing anything

func (*NoopDiscovery) Advertise

func (sd *NoopDiscovery) Advertise(ctx context.Context, ns string, opts ...libp2pdisc.Option) (time.Duration, error)

Advertise does nothing and returns 1 hour.

func (*NoopDiscovery) FindPeers

func (sd *NoopDiscovery) FindPeers(ctx context.Context, ns string, opts ...libp2pdisc.Option) (<-chan peer.AddrInfo, error)

FindPeers returns a dead channel that is always closed

type PeerDiscoveredCallback

type PeerDiscoveredCallback func(ci *types.ChainInfo)

type PeerTracker

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

PeerTracker is used to record a subset of peers. Its methods are thread safe. It is designed to plug directly into libp2p disconnect notifications to automatically register dropped connections.

func NewPeerTracker

func NewPeerTracker(self peer.ID, trust ...peer.ID) *PeerTracker

NewPeerTracker creates a peer tracker.

func (*PeerTracker) List

func (tracker *PeerTracker) List() []*types.ChainInfo

List returns the chain info of the currently tracked peers (both trusted and untrusted). The info tracked by the tracker can change arbitrarily after this is called -- there is no guarantee that the peers returned will be tracked when they are used by the caller and no guarantee that the chain info is up to date.

func (*PeerTracker) RegisterDisconnect

func (tracker *PeerTracker) RegisterDisconnect(ntwk network.Network)

RegisterDisconnect registers a tracker remove operation as a libp2p "Disconnected" network event callback.

func (*PeerTracker) Remove

func (tracker *PeerTracker) Remove(pid peer.ID)

Remove removes a peer ID from the tracker.

func (*PeerTracker) SelectHead

func (tracker *PeerTracker) SelectHead() (*types.ChainInfo, error)

SelectHead returns the chain info from trusted peers with the greatest height. An error is returned if no peers are in the tracker.

func (*PeerTracker) Self

func (tracker *PeerTracker) Self() peer.ID

Self returns the peer tracker's owner ID

func (*PeerTracker) Track

func (tracker *PeerTracker) Track(ci *types.ChainInfo)

Track adds information about a given peer.ID

Jump to

Keyboard shortcuts

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