Documentation
¶
Index ¶
- Variables
- func GetAddress(p *peer.Peer) string
- func IsSupported(p *peer.Peer) bool
- type Events
- type LoadMessageFunc
- type Manager
- func (m *Manager) AddInbound(p *peer.Peer) error
- func (m *Manager) AddOutbound(p *peer.Peer) error
- func (m *Manager) AllNeighbors() []*Neighbor
- func (m *Manager) Close()
- func (m *Manager) DropNeighbor(id identity.ID) error
- func (m *Manager) Events() Events
- func (m *Manager) MessageRequestWorkerPoolStatus() (name string, load int)
- func (m *Manager) MessageWorkerPoolStatus() (name string, load int)
- func (m *Manager) RequestMessage(messageID []byte, to ...identity.ID)
- func (m *Manager) SendMessage(msgData []byte, to ...identity.ID)
- func (m *Manager) Start(srv *server.TCP)
- type MessageReceivedEvent
- type Neighbor
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotRunning is returned when a neighbor is added to a stopped or not yet started gossip manager. ErrNotRunning = errors.New("manager not running") // ErrUnknownNeighbor is returned when the specified neighbor is not known to the gossip manager. ErrUnknownNeighbor = errors.New("unknown neighbor") // ErrLoopbackNeighbor is returned when the own peer is specified as a neighbor. ErrLoopbackNeighbor = errors.New("loopback connection not allowed") // ErrDuplicateNeighbor is returned when the same peer is added more than once as a neighbor. ErrDuplicateNeighbor = errors.New("already connected") // ErrInvalidPacket is returned when the gossip manager receives an invalid packet. ErrInvalidPacket = errors.New("invalid packet") // ErrNeighborQueueFull is returned when the send queue is already full. ErrNeighborQueueFull = errors.New("send queue is full") )
Functions ¶
func GetAddress ¶
GetAddress returns the address of the gossip service.
func IsSupported ¶
IsSupported returns whether the peer supports the gossip service.
Types ¶
type Events ¶
type Events struct { // Fired when an attempt to build a connection to a neighbor has failed. ConnectionFailed *events.Event // Fired when a neighbor connection has been established. NeighborAdded *events.Event // Fired when a neighbor has been removed. NeighborRemoved *events.Event // Fired when a new message was received via the gossip protocol. MessageReceived *events.Event }
Events defines all the events related to the gossip protocol.
type LoadMessageFunc ¶
LoadMessageFunc defines a function that returns the message for the given id.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
The Manager handles the connected neighbors.
func NewManager ¶
NewManager creates a new 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) AllNeighbors ¶
AllNeighbors returns all the neighbors that are currently connected.
func (*Manager) Close ¶
func (m *Manager) Close()
Close stops the manager and closes all established connections.
func (*Manager) DropNeighbor ¶
DropNeighbor disconnects the neighbor with the given ID.
func (*Manager) MessageRequestWorkerPoolStatus ¶
MessageRequestWorkerPoolStatus returns the name and the load of the workerpool.
func (*Manager) MessageWorkerPoolStatus ¶
MessageWorkerPoolStatus returns the name and the load of the workerpool.
func (*Manager) RequestMessage ¶
RequestMessage requests the message with the given id from the neighbors. If no peer is provided, all neighbors are queried.
func (*Manager) SendMessage ¶
SendMessage adds the given message the send queue of the neighbors. The actual send then happens asynchronously. If no peer is provided, it is send to all neighbors.
type MessageReceivedEvent ¶
type MessageReceivedEvent struct { // The raw message. Data []byte // The sender of the message. Peer *peer.Peer }
MessageReceivedEvent holds data about a message received event.
type Neighbor ¶
type Neighbor struct { *peer.Peer *buffconn.BufferedConnection // contains filtered or unexported fields }
Neighbor describes the established gossip connection to another peer.
func NewNeighbor ¶
NewNeighbor creates a new neighbor from the provided peer and connection.
func (*Neighbor) ConnectionEstablished ¶
ConnectionEstablished returns the connection established.
func (*Neighbor) IsOutbound ¶
IsOutbound returns true if the neighbor is an outbound neighbor.