Documentation
      ¶
    
    
  
    
  
    Index ¶
- type Channel
 - type ChannelConfig
 - type ChannelGroup
 - type ChannelGroupConfig
 - type ChannelSelector
 - type Connection
 - func (conn *Connection) AttemptToEnqueueMessage(channelID common.ChannelIDEnum, message interface{}) bool
 - func (conn *Connection) CanEnqueueMessage(channelID common.ChannelIDEnum) bool
 - func (conn *Connection) CancelConnection()
 - func (conn *Connection) DoEncHandshake(prv *ecdsa.PrivateKey, dial *ecdsa.PublicKey) (*crypto.PublicKey, error)
 - func (conn *Connection) EnqueueMessage(channelID common.ChannelIDEnum, message interface{}) bool
 - func (conn *Connection) GetBufNetconn() io.ReadWriter
 - func (conn *Connection) GetBufReader() *bufio.Reader
 - func (conn *Connection) GetNetconn() net.Conn
 - func (conn *Connection) SetErrorHandler(errorHandler ErrorHandler)
 - func (conn *Connection) SetMessageEncoder(messageEncoder MessageEncoder)
 - func (conn *Connection) SetMessageParser(messageParser MessageParser)
 - func (conn *Connection) SetPingTimer(seconds time.Duration)
 - func (conn *Connection) SetReceiveHandler(receiveHandler ReceiveHandler)
 - func (conn *Connection) Start(ctx context.Context) bool
 - func (conn *Connection) Stop()
 - func (conn *Connection) Wait()
 
- type ConnectionConfig
 - type ErrorHandler
 - type MessageEncoder
 - type MessageParser
 - type Packet
 - type ReceiveHandler
 - type RecvBuffer
 - type RecvBufferConfig
 - type RoundRobinChannelSelector
 - type SendBuffer
 - type SendBufferConfig
 
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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) DoEncHandshake ¶ added in v1.0.4
func (conn *Connection) DoEncHandshake(prv *ecdsa.PrivateKey, dial *ecdsa.PublicKey) (*crypto.PublicKey, error)
DoEncHandshake runs the protocol handshake using authenticated messages. the protocol handshake is the first authenticated message and also verifies whether the encryption handshake 'worked' and the remote side actually provided the right public key.
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) GetBufNetconn ¶ added in v1.0.4
func (conn *Connection) GetBufNetconn() io.ReadWriter
GetBufNetconn returns buffered network connection
func (*Connection) GetBufReader ¶ added in v1.0.4
func (conn *Connection) GetBufReader() *bufio.Reader
GetBufReader returns buffered reader for network connection
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
type ConnectionConfig ¶
type ConnectionConfig struct {
	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
}
    type ReceiveHandler ¶
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
}