Documentation ¶
Index ¶
- Variables
- func GetAddress(p *peer.Peer) string
- type ConnectPeerOption
- type Events
- type LoadMessageFunc
- type Manager
- func (m *Manager) AddInbound(ctx context.Context, p *peer.Peer, group NeighborsGroup, ...) error
- func (m *Manager) AddOutbound(ctx context.Context, p *peer.Peer, group NeighborsGroup, ...) error
- func (m *Manager) AllNeighbors() []*Neighbor
- func (m *Manager) DropNeighbor(id identity.ID, group NeighborsGroup) error
- func (m *Manager) GetNeighbor(id identity.ID) (*Neighbor, error)
- func (m *Manager) MessageRequestWorkerPoolStatus() (name string, load uint64)
- func (m *Manager) MessageRequestsRateLimiter() *ratelimiter.PeerRateLimiter
- func (m *Manager) MessageWorkerPoolStatus() (name string, load uint64)
- func (m *Manager) MessagesRateLimiter() *ratelimiter.PeerRateLimiter
- func (m *Manager) NeighborsEvents(group NeighborsGroup) *NeighborsEvents
- func (m *Manager) RequestMessage(messageID []byte, to ...identity.ID)
- func (m *Manager) SendMessage(msgData []byte, to ...identity.ID)
- func (m *Manager) Stop()
- type ManagerOption
- type MessageReceivedEvent
- type Neighbor
- type NeighborAddedEvent
- type NeighborDisconnectedEvent
- type NeighborEvents
- type NeighborPacketReceivedEvent
- type NeighborRemovedEvent
- type NeighborsEvents
- type NeighborsGroup
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") // ErrNeighborQueueFull is returned when the send queue is already full. ErrNeighborQueueFull = errors.New("send queue is full") )
var ( // ErrTimeout is returned when an expected incoming connection was not received in time. ErrTimeout = errors.New("accept timeout") // ErrDuplicateAccept is returned when the server already registered an accept request for that peer ID. ErrDuplicateAccept = errors.New("accept request for that peer already exists") // ErrNoGossip means that the given peer does not support the gossip service. ErrNoGossip = errors.New("peer does not have a gossip service") )
Functions ¶
func GetAddress ¶
GetAddress returns the address of the gossip service.
Types ¶
type ConnectPeerOption ¶ added in v0.8.2
type ConnectPeerOption func(conf *connectPeerConfig)
ConnectPeerOption defines an option for the DialPeer and AcceptPeer methods.
func WithNoDefaultTimeout ¶ added in v0.8.2
func WithNoDefaultTimeout() ConnectPeerOption
WithNoDefaultTimeout returns a ConnectPeerOption that disables the default timeout for dial or accept.
type Events ¶
type Events struct { // Fired when a new message was received via the gossip protocol. MessageReceived *event.Event[*MessageReceivedEvent] }
Events defines all the events related to the gossip protocol.
type LoadMessageFunc ¶ added in v0.2.0
LoadMessageFunc defines a function that returns the message for the given id.
type Manager ¶
type Manager struct { Libp2pHost host.Host Events *Events // contains filtered or unexported fields }
The Manager handles the connected neighbors.
func NewManager ¶
func NewManager(libp2pHost host.Host, local *peer.Local, f LoadMessageFunc, log *logger.Logger, opts ...ManagerOption, ) *Manager
NewManager creates a new Manager.
func (*Manager) AddInbound ¶
func (m *Manager) AddInbound(ctx context.Context, p *peer.Peer, group NeighborsGroup, connectOpts ...ConnectPeerOption) error
AddInbound tries to add a neighbor by accepting an incoming connection from that peer.
func (*Manager) AddOutbound ¶
func (m *Manager) AddOutbound(ctx context.Context, p *peer.Peer, group NeighborsGroup, connectOpts ...ConnectPeerOption) error
AddOutbound tries to add a neighbor by connecting to that peer.
func (*Manager) AllNeighbors ¶ added in v0.2.0
AllNeighbors returns all the neighbors that are currently connected.
func (*Manager) DropNeighbor ¶
func (m *Manager) DropNeighbor(id identity.ID, group NeighborsGroup) error
DropNeighbor disconnects the neighbor with the given ID and the group.
func (*Manager) GetNeighbor ¶ added in v0.8.6
GetNeighbor returns the neighbor by its id.
func (*Manager) MessageRequestWorkerPoolStatus ¶ added in v0.2.2
MessageRequestWorkerPoolStatus returns the name and the load of the workerpool.
func (*Manager) MessageRequestsRateLimiter ¶ added in v0.8.6
func (m *Manager) MessageRequestsRateLimiter() *ratelimiter.PeerRateLimiter
MessageRequestsRateLimiter returns the message requests rate limiter instance used in the gossip manager.
func (*Manager) MessageWorkerPoolStatus ¶ added in v0.2.2
MessageWorkerPoolStatus returns the name and the load of the workerpool.
func (*Manager) MessagesRateLimiter ¶ added in v0.8.6
func (m *Manager) MessagesRateLimiter() *ratelimiter.PeerRateLimiter
MessagesRateLimiter returns the messages rate limiter instance used in the gossip manager.
func (*Manager) NeighborsEvents ¶ added in v0.5.8
func (m *Manager) NeighborsEvents(group NeighborsGroup) *NeighborsEvents
NeighborsEvents returns the events related to the gossip protocol.
func (*Manager) RequestMessage ¶ added in v0.2.0
RequestMessage requests the message with the given id from the neighbors. If no peer is provided, all neighbors are queried.
func (*Manager) SendMessage ¶ added in v0.2.0
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 ManagerOption ¶ added in v0.8.6
type ManagerOption func(m *Manager)
ManagerOption configures the Manager instance.
func WithMessageRequestsRateLimiter ¶ added in v0.8.6
func WithMessageRequestsRateLimiter(prl *ratelimiter.PeerRateLimiter) ManagerOption
WithMessageRequestsRateLimiter allows to set a PeerRateLimiter instance to be used as messages requests rate limiter in the gossip manager.
func WithMessagesRateLimiter ¶ added in v0.8.6
func WithMessagesRateLimiter(prl *ratelimiter.PeerRateLimiter) ManagerOption
WithMessagesRateLimiter allows to set a PeerRateLimiter instance to be used as messages rate limiter in the gossip manager.
type MessageReceivedEvent ¶ added in v0.2.0
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 Group NeighborsGroup Events *NeighborEvents // contains filtered or unexported fields }
Neighbor describes the established gossip connection to another peer.
func NewNeighbor ¶
func NewNeighbor(p *peer.Peer, group NeighborsGroup, ps *packetsStream, log *logger.Logger) *Neighbor
NewNeighbor creates a new neighbor from the provided peer and connection.
func (*Neighbor) ConnectionEstablished ¶ added in v0.2.0
ConnectionEstablished returns the connection established.
func (*Neighbor) PacketsRead ¶ added in v0.8.2
PacketsRead returns number of packets this neighbor has received.
func (*Neighbor) PacketsWritten ¶ added in v0.8.2
PacketsWritten returns number of packets this neighbor has sent.
type NeighborAddedEvent ¶ added in v0.9.0
type NeighborAddedEvent struct {
Neighbor *Neighbor
}
NeighborAddedEvent holds data about the added neighbor.
type NeighborDisconnectedEvent ¶ added in v0.9.0
type NeighborDisconnectedEvent struct{}
NeighborDisconnectedEvent holds data about the disconnected neighbor.
type NeighborEvents ¶ added in v0.9.0
type NeighborEvents struct { // Fired when a neighbor disconnects. Disconnected *event.Event[*NeighborDisconnectedEvent] // Fired when a packet is received from a neighbor. PacketReceived *event.Event[*NeighborPacketReceivedEvent] }
NeighborEvents is a collection of events specific to a neighbor.
func NewNeighborEvents ¶ added in v0.9.0
func NewNeighborEvents() (new *NeighborEvents)
NewNeighborsEvents returns a new instance of NeighborsEvents.
type NeighborPacketReceivedEvent ¶ added in v0.9.0
NeighborDisconnectedEvent holds data about the disconnected neighbor.
type NeighborRemovedEvent ¶ added in v0.9.0
type NeighborRemovedEvent struct {
Neighbor *Neighbor
}
NeighborAddedEvent holds data about the removed neighbor.
type NeighborsEvents ¶ added in v0.5.8
type NeighborsEvents struct { // Fired when a neighbor connection has been established. NeighborAdded *event.Event[*NeighborAddedEvent] // Fired when a neighbor has been removed. NeighborRemoved *event.Event[*NeighborRemovedEvent] }
NeighborsEvents is a collection of events specific for a particular neighbors group, e.g "manual" or "auto".
func NewNeighborsEvents ¶ added in v0.5.8
func NewNeighborsEvents() (new *NeighborsEvents)
NewNeighborsEvents returns a new instance of NeighborsEvents.
type NeighborsGroup ¶ added in v0.5.8
type NeighborsGroup int8
NeighborsGroup is an enum type for various neighbors groups like auto/manual.
const ( // NeighborsGroupAuto represents a neighbors group that is managed automatically. NeighborsGroupAuto NeighborsGroup = iota // NeighborsGroupManual represents a neighbors group that is managed manually. NeighborsGroupManual )