connection

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 9, 2019 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fuzz added in v1.0.2

func Fuzz(data []byte) int

Types

type Channel

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

Channel models a bi-directional channel for messsaging between two peers

type ChannelConfig

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

ChannelConfig specifies the configuration of a Channel

type ChannelGroup

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

ChannelGroup contains multiple channels to facilitate fair scheduling

type ChannelGroupConfig

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

ChannelGroupConfig specifies the configuration of the ChannelGroup

type ChannelSelector

type ChannelSelector interface {
	// contains filtered or unexported methods
}

ChannelSelector defines the interface of a Channel selector

type Connection

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

Connection models the connection between the current node and a peer node. A connection has a ChannelGroup which can contain multiple Channels

func CreateConnection

func CreateConnection(netconn net.Conn, config ConnectionConfig) *Connection

CreateConnection creates a Connection instance

func (*Connection) AttemptToEnqueueMessage

func (conn *Connection) AttemptToEnqueueMessage(channelID common.ChannelIDEnum, message interface{}) bool

AttemptToEnqueueMessage attempts to enqueue the given message to the target channel. The message will be sent out later (non-blocking)

func (*Connection) CanEnqueueMessage

func (conn *Connection) CanEnqueueMessage(channelID common.ChannelIDEnum) bool

CanEnqueueMessage returns whether more messages can still be enqueued into the connection at the moment

func (*Connection) CancelConnection

func (conn *Connection) CancelConnection()

CancelConnection for testing purpose only

func (*Connection) EnqueueMessage

func (conn *Connection) EnqueueMessage(channelID common.ChannelIDEnum, message interface{}) bool

EnqueueMessage enqueues the given message to the target channel. The message will be sent out later

func (*Connection) GetNetconn

func (conn *Connection) GetNetconn() net.Conn

GetNetconn returns the attached network connection

func (*Connection) SetErrorHandler

func (conn *Connection) SetErrorHandler(errorHandler ErrorHandler)

SetErrorHandler sets the error handler for the connection

func (*Connection) SetMessageEncoder

func (conn *Connection) SetMessageEncoder(messageEncoder MessageEncoder)

SetMessageEncoder sets the message encoder for the connection

func (*Connection) SetMessageParser

func (conn *Connection) SetMessageParser(messageParser MessageParser)

SetMessageParser sets the message parser for the connection

func (*Connection) SetPingTimer

func (conn *Connection) SetPingTimer(seconds time.Duration)

SetPingTimer for testing purpose

func (*Connection) SetReceiveHandler

func (conn *Connection) SetReceiveHandler(receiveHandler ReceiveHandler)

SetReceiveHandler sets the receive handler for the connection

func (*Connection) Start

func (conn *Connection) Start(ctx context.Context) bool

Start is called when the connection starts

func (*Connection) Stop

func (conn *Connection) Stop()

Stop is called whten the connection stops

func (*Connection) Wait

func (conn *Connection) Wait()

Wait suspends the caller goroutine

type ConnectionConfig

type ConnectionConfig struct {
	MinWriteBufferSize int
	MinReadBufferSize  int
	SendRate           int64
	RecvRate           int64
	PacketBatchSize    int64
	FlushThrottle      time.Duration
	PingTimeout        time.Duration
	MaxPendingPings    uint32
}

ConnectionConfig specifies the configurations of the Connection

func GetDefaultConnectionConfig

func GetDefaultConnectionConfig() ConnectionConfig

GetDefaultConnectionConfig returns the default ConnectionConfig

type ErrorHandler

type ErrorHandler func(interface{})

ErrorHandler is the callback function to handle channel read errors

type MessageEncoder

type MessageEncoder func(channelID common.ChannelIDEnum, message interface{}) (common.Bytes, error)

MessageEncoder encodes type p2ptypes.Message to raw message bytes

type MessageParser

type MessageParser func(channelID common.ChannelIDEnum, rawMessageBytes common.Bytes) (p2ptypes.Message, error)

MessageParser parses the raw message bytes to type p2ptypes.Message

type Packet

type Packet struct {
	ChannelID common.ChannelIDEnum
	Bytes     []byte
	IsEOF     byte // 1 means message ends here.
	SeqID     uint
}

func (Packet) String

func (p Packet) String() string

type ReceiveHandler

type ReceiveHandler func(message p2ptypes.Message) error

ReceiveHandler is the callback function to handle received bytes from the given channel

type RecvBuffer

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

type RecvBufferConfig

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

type RoundRobinChannelSelector

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

RoundRobinChannelSelector implments the ChannelSelector interface with the round robin strategy

type SendBuffer

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

type SendBufferConfig

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

Directories

Path Synopsis
Package flowrate provides the tools for monitoring and limiting the flow rate of an arbitrary data stream.
Package flowrate provides the tools for monitoring and limiting the flow rate of an arbitrary data stream.

Jump to

Keyboard shortcuts

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