peer

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create added in v0.4.0

func Create(ctx context.Context, reader *Reader, writer *Writer, writeQueueChan <-chan bytes.Buffer) error

Create two-way communication with a peer. This function will allow both goroutines to run as long as no errors are encountered. Once the first error comes through, the context is canceled, and both goroutines are cleaned up.

Types

type Connection

type Connection struct {
	net.Conn
	// contains filtered or unexported fields
}

Connection holds the TCP connection to another node, and it's known protocol magic. The `net.Conn` is guarded by a mutex, to allow both multicast and one-to-one communication between peers.

func (*Connection) Addr

func (c *Connection) Addr() string

Addr returns the peer's address as a string.

func (*Connection) ReadMessage

func (c *Connection) ReadMessage() ([]byte, error)

ReadMessage reads from the connection.

func (*Connection) Write

func (c *Connection) Write(b []byte) (int, error)

Write a message to the connection. Conn needs to be locked, as this function can be called both by the WriteLoop, and by the writer on the ring buffer.

type GossipConnector added in v0.3.0

type GossipConnector struct {
	*Connection
	// contains filtered or unexported fields
}

GossipConnector calls Gossip.Process on the message stream incoming from the ringbuffer. It absolves the function previously carried over by the Gossip preprocessor.

func (*GossipConnector) Write added in v0.3.0

func (g *GossipConnector) Write(b []byte) (int, error)

type MessageProcessor added in v0.4.0

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

MessageProcessor is connected to all of the processing units that are tied to the peer. It sends an incoming message in the right direction, according to its topic.

func NewMessageProcessor added in v0.4.0

func NewMessageProcessor(bus eventbus.Broker) *MessageProcessor

NewMessageProcessor returns an initialized MessageProcessor.

func (*MessageProcessor) CanRoute added in v0.4.0

func (m *MessageProcessor) CanRoute(topic topics.Topic) bool

CanRoute determines whether or not a message needs to be filtered by the dupemap. TODO: rename.

func (*MessageProcessor) Collect added in v0.4.0

func (m *MessageProcessor) Collect(srcPeerID string, packet []byte, respChan chan<- bytes.Buffer) error

Collect a message from the network. The message is unmarshaled and passed down to the processing function.

func (*MessageProcessor) Register added in v0.4.0

func (m *MessageProcessor) Register(topic topics.Topic, fn ProcessorFunc)

Register a method to a certain topic. This method will be called when a message of the given topic is received.

type ProcessorFunc added in v0.4.0

type ProcessorFunc func(srcPeerID string, m message.Message) ([]bytes.Buffer, error)

ProcessorFunc defines an interface for callbacks which can be registered to the MessageProcessor, in order to process messages from the network.

type Reader

type Reader struct {
	*Connection
	// contains filtered or unexported fields
}

Reader abstracts all of the logic and fields needed to receive messages from other network nodes.

func (*Reader) Accept

func (p *Reader) Accept() error

Accept will perform the protocol handshake with the peer.

func (*Reader) Handshake

func (p *Reader) Handshake() error

Handshake with another peer.

func (*Reader) ReadLoop

func (p *Reader) ReadLoop(ctx context.Context, errChan chan error)

ReadLoop will block on the read until a message is read, or until the deadline is reached. Should be called in a go-routine, after a successful handshake with a peer. Eventual duplicated messages are silently discarded.

type ReaderFactory added in v0.4.0

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

ReaderFactory is responsible for spawning peers. It provides them with the reference to the message processor, which will process the received messages.

func NewReaderFactory added in v0.4.0

func NewReaderFactory(processor *MessageProcessor) *ReaderFactory

NewReaderFactory returns an initialized ReaderFactory.

func (*ReaderFactory) SpawnReader added in v0.4.0

func (f *ReaderFactory) SpawnReader(conn net.Conn, gossip *protocol.Gossip, responseChan chan<- bytes.Buffer) *Reader

SpawnReader returns a Reader. It will still need to be launched by running ReadLoop in a goroutine.

type VersionMessage

type VersionMessage struct {
	Version   *protocol.Version
	Timestamp int64
	Services  protocol.ServiceFlag
}

VersionMessage is a version message on the dusk wire protocol.

type Writer

type Writer struct {
	*Connection
	// contains filtered or unexported fields
}

Writer abstracts all of the logic and fields needed to write messages to other network nodes.

func NewWriter

func NewWriter(conn net.Conn, gossip *protocol.Gossip, subscriber eventbus.Subscriber, keepAlive ...time.Duration) *Writer

NewWriter returns a Writer. It will still need to be initialized by subscribing to the gossip topic with a stream handler, and by running the WriteLoop in a goroutine.

func (*Writer) Connect

func (w *Writer) Connect() error

Connect will perform the protocol handshake with the peer. If successful...

func (*Writer) Handshake

func (w *Writer) Handshake() error

Handshake with another peer.

func (*Writer) Serve

func (w *Writer) Serve(ctx context.Context, writeQueueChan <-chan bytes.Buffer, errChan chan error)

Serve utilizes two different methods for writing to the open connection.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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