gossip

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2020 License: Apache-2.0, BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotStarted        = errors.New("manager not started")
	ErrClosed            = errors.New("manager closed")
	ErrNotANeighbor      = errors.New("peer is not a neighbor")
	ErrLoopback          = errors.New("loopback connection not allowed")
	ErrDuplicateNeighbor = errors.New("peer already connected")
	ErrInvalidPacket     = errors.New("invalid packet")
)
View Source
var (
	// ErrNeighborQueueFull is returned when the send queue is already full.
	ErrNeighborQueueFull = errors.New("send queue is full")
)
View Source
var Events = struct {
	// A ConnectionFailed event is triggered when a neighbor connection to a peer could not be established.
	ConnectionFailed *events.Event
	// A NeighborAdded event is triggered when a connection to a new neighbor has been established.
	NeighborAdded *events.Event
	// A NeighborRemoved event is triggered when a neighbor has been dropped.
	NeighborRemoved *events.Event
	// A TransactionReceived event is triggered when a new transaction is received by the gossip protocol.
	TransactionReceived *events.Event
}{
	ConnectionFailed:    events.NewEvent(peerCaller),
	NeighborAdded:       events.NewEvent(neighborCaller),
	NeighborRemoved:     events.NewEvent(peerCaller),
	TransactionReceived: events.NewEvent(transactionReceived),
}

Events contains all the events related to the gossip protocol.

Functions

func GetAddress

func GetAddress(p *peer.Peer) string

GetAddress returns the address of the gossip service.

func IsSupported

func IsSupported(p *peer.Peer) bool

IsSupported returns whether the peer supports the gossip service.

Types

type GetTransaction

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

GetTransaction defines a function that returns the transaction data with the given hash.

type Manager

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

func NewManager

func NewManager(local *peer.Local, f GetTransaction, log *zap.SugaredLogger) *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

NeighborRemoved disconnects the neighbor with the given ID.

func (*Manager) GetAllNeighbors

func (m *Manager) GetAllNeighbors() []*Neighbor

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 adds the given transaction data to the send queue of the neighbors. The actual send then happens asynchronously. If no peer is provided, it is send to all neighbors.

func (*Manager) Start

func (m *Manager) Start(srv *server.TCP)

type Neighbor

type Neighbor struct {
	*peer.Peer
	*buffconn.BufferedConnection
	// contains filtered or unexported fields
}

func NewNeighbor

func NewNeighbor(peer *peer.Peer, conn net.Conn, log *logger.Logger) *Neighbor

NewNeighbor creates a new neighbor from the provided peer and connection.

func (*Neighbor) Close

func (n *Neighbor) Close() error

Close closes the connection to the neighbor and stops all communication.

func (*Neighbor) IsOutbound

func (n *Neighbor) IsOutbound() bool

IsOutbound returns true if the neighbor is an outbound neighbor.

func (*Neighbor) Listen

func (n *Neighbor) Listen()

Listen starts the communication to the neighbor.

func (*Neighbor) Write

func (n *Neighbor) Write(b []byte) (int, error)

type TransactionReceivedEvent

type TransactionReceivedEvent struct {
	Data []byte     // transaction data
	Peer *peer.Peer // peer that send the transaction
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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