gossip

package
v0.7.7 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2021 License: Apache-2.0, BSD-2-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

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 Events

type Events struct {
	// 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 added in v0.2.0

type LoadMessageFunc func(messageId tangle.MessageID) ([]byte, error)

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

func NewManager(local *peer.Local, f LoadMessageFunc, log *logger.Logger) *Manager

NewManager creates a new Manager.

func (*Manager) AddInbound

func (m *Manager) AddInbound(ctx context.Context, p *peer.Peer, group NeighborsGroup,
	connectOpts ...server.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 ...server.ConnectPeerOption) error

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

func (*Manager) AllNeighbors added in v0.2.0

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

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) Events added in v0.2.0

func (m *Manager) Events() Events

Events returns the events related to the gossip protocol.

func (*Manager) MessageRequestWorkerPoolStatus added in v0.2.2

func (m *Manager) MessageRequestWorkerPoolStatus() (name string, load int)

MessageRequestWorkerPoolStatus returns the name and the load of the workerpool.

func (*Manager) MessageWorkerPoolStatus added in v0.2.2

func (m *Manager) MessageWorkerPoolStatus() (name string, load int)

MessageWorkerPoolStatus returns the name and the load of the workerpool.

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

func (m *Manager) RequestMessage(messageID []byte, to ...identity.ID)

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

func (m *Manager) SendMessage(msgData []byte, to ...identity.ID)

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.

func (*Manager) Start

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

Start starts the manager for the given TCP server.

func (*Manager) Stop added in v0.6.2

func (m *Manager) Stop()

Stop stops the manager and closes all established connections.

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
	*buffconn.BufferedConnection

	Group NeighborsGroup
	// contains filtered or unexported fields
}

Neighbor describes the established gossip connection to another peer.

func NewNeighbor

func NewNeighbor(p *peer.Peer, group NeighborsGroup, 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) ConnectionEstablished added in v0.2.0

func (n *Neighbor) ConnectionEstablished() time.Time

ConnectionEstablished returns the connection established.

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 NeighborsEvents added in v0.5.8

type NeighborsEvents 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
}

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() 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
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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