protocol

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// supports protocol messages/feature sets: 2+1
	SupportedFeatureSets = []byte{sting.FeatureSet | legacy.FeatureSet}
)

Functions

func Init

func Init(cooAddressBytes []byte, mwm int, gossipBindAddr string) error

Init initializes the protocol package with the given handshake information.

Types

type Events

type Events struct {
	// Fired when a handshake was fully completed.
	HandshakeCompleted *events.Event
	// Holds event instances to attach to for received messages.
	// Use a message's ID to get the corresponding event.
	Received []*events.Event
	// Holds event instances to attach to for sent messages.
	// Use a message's ID to get the corresponding event.
	Sent []*events.Event
	// Fired for generic protocol errors.
	// It is suggested to close the underlying ReadWriteCloser of the Protocol instance
	// if any error occurs.
	Error *events.Event
}

Events holds protocol related events.

type Protocol

type Protocol struct {
	// The protocol features this instance supports.
	// This variable is only usable after protocol handshake.
	FeatureSet byte
	// Holds events for sent and received messages, handshake completion and generic errors.
	Events Events
	// contains filtered or unexported fields
}

Protocol encapsulates the logic of parsing and sending protocol messages.

func New

func New(conn io.ReadWriteCloser) *Protocol

New generates a new protocol instance which is ready to read a first message header.

func (*Protocol) Handshaked

func (p *Protocol) Handshaked()

Handshaked has to be called when a handshake message was received (and finalized) and sent. If this function is called twice, it will trigger a HandshakeCompleted event.

func (*Protocol) Receive

func (p *Protocol) Receive(data []byte)

Receive acts as an event handler for received data.

func (*Protocol) Send

func (p *Protocol) Send(message []byte) error

Send sends the given message (including the message header) to the underlying writer. It fires the corresponding send event for the specific message type.

func (*Protocol) Start

func (p *Protocol) Start()

Start kicks off the protocol by sending a handshake message and starting to read from the connection.

func (*Protocol) SupportedFeatureSets

func (p *Protocol) SupportedFeatureSets() []string

SupportedFeatureSets returns a slice of named supported feature sets.

func (*Protocol) Supports

func (p *Protocol) Supports(featureSet byte) bool

Supports tells whether the protocol supports the given feature set.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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