Documentation ¶
Index ¶
- Variables
- func GetAddress(p *peer.Peer) string
- func IsSupported(p *peer.Peer) bool
- type GetTransaction
- type Manager
- func (m *Manager) AddInbound(p *peer.Peer) error
- func (m *Manager) AddOutbound(p *peer.Peer) error
- func (m *Manager) Close()
- func (m *Manager) DropNeighbor(id peer.ID) error
- func (m *Manager) GetAllNeighbors() []*Neighbor
- func (m *Manager) RequestTransaction(txHash []byte, to ...peer.ID)
- func (m *Manager) SendTransaction(txData []byte, to ...peer.ID)
- func (m *Manager) Start(srv *server.TCP)
- type Neighbor
- type TransactionReceivedEvent
Constants ¶
This section is empty.
Variables ¶
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") )
var ( // ErrNeighborQueueFull is returned when the send queue is already full. ErrNeighborQueueFull = errors.New("send queue is full") )
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 ¶
GetAddress returns the address of the gossip service.
func IsSupported ¶
IsSupported returns whether the peer supports the gossip service.
Types ¶
type GetTransaction ¶
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 ¶
AddInbound tries to add a neighbor by accepting an incoming connection from that peer.
func (*Manager) AddOutbound ¶
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 ¶
NeighborRemoved disconnects the neighbor with the given ID.
func (*Manager) GetAllNeighbors ¶
func (*Manager) RequestTransaction ¶
RequestTransaction requests the transaction with the given hash from the neighbors. If no peer is provided, all neighbors are queried.
func (*Manager) SendTransaction ¶
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.
type Neighbor ¶
type Neighbor struct { *peer.Peer *buffconn.BufferedConnection // contains filtered or unexported fields }
func NewNeighbor ¶
NewNeighbor creates a new neighbor from the provided peer and connection.
func (*Neighbor) IsOutbound ¶
IsOutbound returns true if the neighbor is an outbound neighbor.