p2p

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: MIT Imports: 27 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 BlockApplicator added in v0.4.0

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

BlockApplicator manages block application to avoid duplicate application and premature application

func NewBlockApplicator added in v0.4.0

func NewBlockApplicator(ctx context.Context, rpc rpc.LocalRPC, opts options.BlockApplicatorOptions) (*BlockApplicator, error)

func (*BlockApplicator) ApplyBlock added in v0.4.0

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

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

func (*BlockApplicator) HandleBlockBroadcast added in v0.4.0

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

HandleBlockBroadcast handles a block broadcast

func (*BlockApplicator) HandleForkHeads added in v0.4.0

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

HandleForkHeads handles a fork heads broadcast

func (*BlockApplicator) Start added in v0.4.0

func (b *BlockApplicator) 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) *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) 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 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, rpc rpc.LocalRPC, 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,
	blockApplicator *BlockApplicator) *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 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) *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) InterceptAccept

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

InterceptAccept implements the libp2p ConnectionGater interface

func (*PeerErrorHandler) InterceptAddrDial

func (p *PeerErrorHandler) InterceptAddrDial(peer.ID, multiaddr.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, pid peer.ID, _ 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) 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