p2p

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// BlockTopicName is the block topic string
	BlockTopicName string = "koinos.blocks"

	// TransactionTopicName is the transaction topic string
	TransactionTopicName string = "koinos.transactions"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Applicator added in v0.4.1

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

Applicator manages block application to avoid duplicate application and premature application

func NewApplicator added in v0.4.1

func NewApplicator(ctx context.Context, rpc rpc.LocalRPC, opts options.ApplicatorOptions) (*Applicator, error)

func (*Applicator) ApplyBlock added in v0.4.1

func (b *Applicator) ApplyBlock(ctx context.Context, block *protocol.Block) error

ApplyBlock will apply the block to the chain at the appropriate time

func (*Applicator) ApplyTransaction added in v0.4.1

func (b *Applicator) ApplyTransaction(ctx context.Context, trx *protocol.Transaction) error

func (*Applicator) HandleBlockBroadcast added in v0.4.1

func (b *Applicator) HandleBlockBroadcast(blockAccept *broadcast.BlockAccepted)

HandleBlockBroadcast handles a block broadcast

func (*Applicator) HandleForkHeads added in v0.4.1

func (b *Applicator) HandleForkHeads(forkHeads *broadcast.ForkHeads)

HandleForkHeads handles a fork heads broadcast

func (*Applicator) Start added in v0.4.1

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

type ConnectionManager

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

ConnectionManager attempts to reconnect to peers using the network.Notifiee interface.

func NewConnectionManager

func NewConnectionManager(
	host host.Host,
	localRPC rpc.LocalRPC,
	peerOpts *options.PeerConnectionOptions,
	libProvider LastIrreversibleBlockProvider,
	initialPeers []string,
	peerErrorChan chan<- PeerError,
	gossipVoteChan chan<- GossipVote,
	signalPeerDisconnectChan chan<- peer.ID,
	applicator *Applicator) *ConnectionManager

NewConnectionManager creates a new PeerReconnectManager object

func (*ConnectionManager) ClosedStream

func (c *ConnectionManager) ClosedStream(n network.Network, s network.Stream)

ClosedStream is part of the libp2p network.Notifiee interface

func (*ConnectionManager) Connected

func (c *ConnectionManager) Connected(net network.Network, conn network.Conn)

Connected is part of the libp2p network.Notifiee interface

func (*ConnectionManager) Disconnected

func (c *ConnectionManager) Disconnected(net network.Network, conn network.Conn)

Disconnected is part of the libp2p network.Notifiee interface

func (*ConnectionManager) GetPeerAddress added in v0.4.1

func (c *ConnectionManager) GetPeerAddress(ctx context.Context, id peer.ID) multiaddr.Multiaddr

func (*ConnectionManager) Listen

Listen is part of the libp2p network.Notifiee interface

func (*ConnectionManager) ListenClose

func (c *ConnectionManager) ListenClose(n network.Network, _ multiaddr.Multiaddr)

ListenClose is part of the libp2p network.Notifiee interface

func (*ConnectionManager) OpenedStream

func (c *ConnectionManager) OpenedStream(n network.Network, s network.Stream)

OpenedStream is part of the libp2p network.Notifiee interface

func (*ConnectionManager) Start

func (c *ConnectionManager) Start(ctx context.Context)

Start the connection manager

type ForkWatchdog added in v0.4.1

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

func NewForkWatchdog added in v0.4.1

func NewForkWatchdog() *ForkWatchdog

func (*ForkWatchdog) Add added in v0.4.1

func (f *ForkWatchdog) Add(block *protocol.Block) error

Add a block to the fork watchdog

func (*ForkWatchdog) Purge added in v0.4.1

func (f *ForkWatchdog) Purge(lib uint64)

Purge a set of fork records from fork watchdog

type GossipEnableHandler

type GossipEnableHandler interface {
	EnableGossip(context.Context, bool)
}

GossipEnableHandler is an interface for handling enable/disable gossip requests

type GossipManager

type GossipManager struct {
	Enabled bool
	// contains filtered or unexported fields
}

GossipManager manages gossip on a given topic

func NewGossipManager

func NewGossipManager(ps *pubsub.PubSub, errChan chan<- PeerError, topicName string) *GossipManager

NewGossipManager creates and returns a new instance of gossipManager

func (*GossipManager) PublishMessage

func (gm *GossipManager) PublishMessage(ctx context.Context, bytes []byte) bool

PublishMessage publishes the given object to this manager's topic

func (*GossipManager) RegisterValidator

func (gm *GossipManager) RegisterValidator(val interface{}) error

RegisterValidator registers the validate function to be used for messages

func (*GossipManager) Start

func (gm *GossipManager) Start(ctx context.Context, ch chan<- []byte) error

Start starts gossiping on this topic

func (*GossipManager) Stop

func (gm *GossipManager) Stop()

Stop stops all gossiping on this topic

type GossipToggle

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

GossipToggle tracks peer gossip votes and toggles gossip accordingly

func NewGossipToggle

func NewGossipToggle(gossipEnabler GossipEnableHandler, voteChan <-chan GossipVote, peerDisconnectedChan <-chan peer.ID, opts options.GossipToggleOptions) *GossipToggle

NewGossipToggle creates a GossipToggle

func (*GossipToggle) IsEnabled added in v0.3.0

func (g *GossipToggle) IsEnabled() bool

IsEnabled returns whether gossip is enabled

func (*GossipToggle) Start

func (g *GossipToggle) Start(ctx context.Context)

Start begins gossip vote processing

type GossipVote

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

GossipVote is a vote from a peer to enable gossip or not

type KoinosGossip

type KoinosGossip struct {
	PubSub        *pubsub.PubSub
	PeerErrorChan chan<- PeerError
	// contains filtered or unexported fields
}

KoinosGossip handles gossip of blocks and transactions

func NewKoinosGossip

func NewKoinosGossip(
	ctx context.Context,
	rpc rpc.LocalRPC,
	ps *pubsub.PubSub,
	peerErrorChan chan<- PeerError,
	id peer.ID,
	libProvider LastIrreversibleBlockProvider,
	cache *TransactionCache,
	applicator *Applicator) *KoinosGossip

NewKoinosGossip constructs a new koinosGossip instance

func (*KoinosGossip) EnableGossip

func (kg *KoinosGossip) EnableGossip(ctx context.Context, enable bool)

EnableGossip satisfies GossipEnableHandler interface

func (*KoinosGossip) PublishBlock added in v0.4.0

func (kg *KoinosGossip) PublishBlock(ctx context.Context, block *protocol.Block) error

PublishBlock publishes a block to the block topic

func (*KoinosGossip) PublishTransaction added in v0.4.0

func (kg *KoinosGossip) PublishTransaction(ctx context.Context, transaction *protocol.Transaction) error

PublishTransaction publishes a transaction to the transaction topic

func (*KoinosGossip) StartGossip

func (kg *KoinosGossip) StartGossip(ctx context.Context)

StartGossip enables gossip of blocks and transactions

func (*KoinosGossip) StopGossip

func (kg *KoinosGossip) StopGossip()

StopGossip stops gossiping on both block and transaction topics

type LastIrreversibleBlockProvider

type LastIrreversibleBlockProvider interface {
	GetLastIrreversibleBlock() *koinos.BlockTopology
}

LastIrreversibleBlockProvider is an interface for providing the last irreversible block to PeerConnection

type PeerAddressProvider added in v0.4.1

type PeerAddressProvider interface {
	GetPeerAddress(ctx context.Context, id peer.ID) ma.Multiaddr
}

PeerAddressProvider return's the peers remote address given a peer ID

type PeerConnection

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

PeerConnection handles the sync portion of a connection to a peer

func NewPeerConnection

func NewPeerConnection(
	id peer.ID,
	libProvider LastIrreversibleBlockProvider,
	localRPC rpc.LocalRPC,
	peerRPC rpc.RemoteRPC,
	peerErrorChan chan<- PeerError,
	gossipVoteChan chan<- GossipVote,
	opts *options.PeerConnectionOptions,
	applicator *Applicator) *PeerConnection

NewPeerConnection creates a PeerConnection

func (*PeerConnection) Start

func (p *PeerConnection) Start(ctx context.Context)

Start syncing to the peer

type PeerError

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

PeerError represents an error originating from a peer

type PeerErrorHandler

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

PeerErrorHandler handles PeerErrors and tracks errors over time to determine if a peer should be disconnected from

func NewPeerErrorHandler

func NewPeerErrorHandler(
	disconnectPeerChan chan<- peer.ID,
	peerErrorChan <-chan PeerError,
	opts options.PeerErrorHandlerOptions) *PeerErrorHandler

NewPeerErrorHandler creates a new PeerErrorHandler

func (*PeerErrorHandler) CanConnect

func (p *PeerErrorHandler) CanConnect(ctx context.Context, id peer.ID) bool

CanConnect to peer if the peer's error score is below the error score threshold

func (*PeerErrorHandler) CanConnectAddr added in v0.4.1

func (p *PeerErrorHandler) CanConnectAddr(ctx context.Context, addr ma.Multiaddr) bool

CanConnectAddr to peer if the peer's error score is below the error score threshold

func (*PeerErrorHandler) GetOptions added in v0.4.2

func (*PeerErrorHandler) GetPeerErrorScore added in v0.4.2

func (p *PeerErrorHandler) GetPeerErrorScore(ctx context.Context, id peer.ID) uint64

GetPeerErrorScore returns the current error score for a given peer ID

func (*PeerErrorHandler) InterceptAccept

func (p *PeerErrorHandler) InterceptAccept(conn network.ConnMultiaddrs) bool

InterceptAccept implements the libp2p ConnectionGater interface

func (*PeerErrorHandler) InterceptAddrDial

func (p *PeerErrorHandler) InterceptAddrDial(_ peer.ID, addr ma.Multiaddr) bool

InterceptAddrDial implements the libp2p ConnectionGater interface

func (*PeerErrorHandler) InterceptPeerDial

func (p *PeerErrorHandler) InterceptPeerDial(pid peer.ID) bool

InterceptPeerDial implements the libp2p ConnectionGater interface

func (*PeerErrorHandler) InterceptSecured

func (p *PeerErrorHandler) InterceptSecured(_ network.Direction, _ peer.ID, conn network.ConnMultiaddrs) bool

InterceptSecured implements the libp2p ConnectionGater interface

func (*PeerErrorHandler) InterceptUpgraded

func (p *PeerErrorHandler) InterceptUpgraded(network.Conn) (bool, control.DisconnectReason)

InterceptUpgraded implements the libp2p ConnectionGater interface

func (*PeerErrorHandler) SetPeerAddressProvider added in v0.4.1

func (p *PeerErrorHandler) SetPeerAddressProvider(addrProvider PeerAddressProvider)

SetPeerStore of the PeerErrorHandler. This must be called before starting the error score and is a separate function because PeerErrorHandler can be passed in to a libp2p Host during construction as a ConnectionGater. But the Host to be created is the PeerStore the PeerErrorHandler requires.

func (*PeerErrorHandler) Start

func (p *PeerErrorHandler) Start(ctx context.Context)

Start processing peer errors

type TransactionCache added in v0.4.0

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

TransactionCache is a cache of recently received transactions

func NewTransactionCache added in v0.4.0

func NewTransactionCache(cacheDuration time.Duration) *TransactionCache

NewTransactionCache creates a new transaction cache

func (*TransactionCache) CheckBlock added in v0.4.0

func (txc *TransactionCache) CheckBlock(block *protocol.Block) int

CheckBlock is a helper function to check transactions in a block

func (*TransactionCache) CheckTransactions added in v0.4.0

func (txc *TransactionCache) CheckTransactions(transactions ...*protocol.Transaction) int

CheckTransactions returns the number of transactions that are in the cache

type TransactionCacheItem added in v0.4.0

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

TransactionCacheItem is a an item in the transaction cache

Jump to

Keyboard shortcuts

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