gossip

package module
v0.0.0-...-707b10e Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

README

gossip

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed            = errors.New("manager closed")
	ErrNotANeighbor      = errors.New("peer is not a neighbor")
	ErrDuplicateNeighbor = errors.New("peer already connected")
)
View Source
var Events = struct {
	// A TransactionReceived event is triggered when a new transaction is received by the gossip protocol.
	TransactionReceived *events.Event
	// A NeighborDropped event is triggered when a neighbor has been dropped.
	NeighborDropped *events.Event
	// A RequestTransaction should be triggered for a transaction to be requested through the gossip protocol.
	RequestTransaction *events.Event
}{
	TransactionReceived: events.NewEvent(transactionReceived),
	NeighborDropped:     events.NewEvent(neighborDropped),
	RequestTransaction:  events.NewEvent(requestTransaction),
}

Events contains all the events related to the gossip protocol.

Functions

This section is empty.

Types

type GetTransaction

type GetTransaction func(txHash []byte) ([]byte, error)

type Manager

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

func NewManager

func NewManager(t *transport.TCP, log *zap.SugaredLogger, f GetTransaction) *Manager

func (*Manager) AddInbound

func (m *Manager) AddInbound(p *peer.Peer) error

AddInbound tries to add a neighbor by accepting an incoming connection from that peer.

func (*Manager) AddOutbound

func (m *Manager) AddOutbound(p *peer.Peer) error

AddOutbound tries to add a neighbor by connecting to that peer.

func (*Manager) Close

func (m *Manager) Close()

Close stops the manager and closes all established connections.

func (*Manager) DropNeighbor

func (m *Manager) DropNeighbor(id peer.ID) error

NeighborDropped disconnects the neighbor with the given ID.

func (*Manager) RequestTransaction

func (m *Manager) RequestTransaction(txHash []byte, to ...peer.ID)

RequestTransaction requests the transaction with the given hash from the neighbors. If no peer is provided, all neighbors are queried.

func (*Manager) SendTransaction

func (m *Manager) SendTransaction(txData []byte, to ...peer.ID)

SendTransaction sends the given transaction data to the neighbors. If no peer is provided, it is send to all neighbors.

type NeighborDroppedEvent

type NeighborDroppedEvent struct {
	Peer *peer.Peer
}

type RequestTransactionEvent

type RequestTransactionEvent struct {
	Hash []byte // hash of the transaction to request
}

type TransactionReceivedEvent

type TransactionReceivedEvent struct {
	Body []byte
	Peer *peer.Peer
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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