conn

package
v0.0.0-...-be384fd Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSmallOrderRemotePubKey = errors.New("detected low order point from remote peer")
)

Functions

This section is empty.

Types

type ChannelDescriptor

type ChannelDescriptor struct {
	ID       ChannelID
	Priority int

	// TODO: Remove once p2p refactor is complete.
	SendQueueCapacity   int
	RecvMessageCapacity int

	// RecvBufferCapacity defines the max buffer size of inbound messages for a
	// given p2p Channel queue.
	RecvBufferCapacity int

	// Human readable name of the channel, used in logging and
	// diagnostics.
	Name string
}

func (ChannelDescriptor) FillDefaults

func (chDesc ChannelDescriptor) FillDefaults() (filled ChannelDescriptor)

type ChannelID

type ChannelID uint16

----------------------------------------------------------------------------- ChannelID is an arbitrary channel ID.

type ChannelStatus

type ChannelStatus struct {
	ID                byte
	SendQueueCapacity int
	SendQueueSize     int
	Priority          int
	RecentlySent      int64
}

type MConnConfig

type MConnConfig struct {
	SendRate int64 `mapstructure:"send_rate"`
	RecvRate int64 `mapstructure:"recv_rate"`

	// Maximum payload size
	MaxPacketMsgPayloadSize int `mapstructure:"max_packet_msg_payload_size"`

	// Interval to flush writes (throttled)
	FlushThrottle time.Duration `mapstructure:"flush_throttle"`

	// Interval to send pings
	PingInterval time.Duration `mapstructure:"ping_interval"`

	// Maximum wait time for pongs
	PongTimeout time.Duration `mapstructure:"pong_timeout"`

	// Process/Transport Start time
	StartTime time.Time `mapstructure:",omitempty"`
}

MConnConfig is a MConnection configuration.

func DefaultMConnConfig

func DefaultMConnConfig() MConnConfig

DefaultMConnConfig returns the default config.

type MConnection

type MConnection struct {
	service.BaseService
	// contains filtered or unexported fields
}

Each peer has one `MConnection` (multiplex connection) instance.

__multiplex__ *noun* a system or signal involving simultaneous transmission of several messages along a single channel of communication.

Each `MConnection` handles message transmission on multiple abstract communication `Channel`s. Each channel has a globally unique byte id. The byte id and the relative priorities of each `Channel` are configured upon initialization of the connection.

There are two methods for sending messages:

func (m MConnection) Send(chID byte, msgBytes []byte) bool {}

`Send(chID, msgBytes)` is a blocking call that waits until `msg` is successfully queued for the channel with the given id byte `chID`, or until the request times out. The message `msg` is serialized using Protobuf.

Inbound message bytes are handled with an onReceive callback function.

func NewMConnection

func NewMConnection(
	logger log.Logger,
	conn net.Conn,
	chDescs []*ChannelDescriptor,
	onReceive receiveCbFunc,
	onError errorCbFunc,
	config MConnConfig,
) *MConnection

NewMConnection wraps net.Conn and creates multiplex connection with a config

func (*MConnection) OnStart

func (c *MConnection) OnStart(ctx context.Context) error

OnStart implements BaseService

func (*MConnection) OnStop

func (c *MConnection) OnStop()

OnStop implements BaseService

func (*MConnection) Send

func (c *MConnection) Send(chID ChannelID, msgBytes []byte) bool

Queues a message to be sent to channel.

func (*MConnection) String

func (c *MConnection) String() string

type SecretConnection

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

SecretConnection implements net.Conn. It is an implementation of the STS protocol. See https://github.com/tendermint/tendermint/blob/0.1/docs/sts-final.pdf for details on the protocol.

Consumers of the SecretConnection are responsible for authenticating the remote peer's pubkey against known information, like a nodeID. Otherwise they are vulnerable to MITM. (TODO(ismail): see also https://github.com/tendermint/tendermint/issues/3010)

func MakeSecretConnection

func MakeSecretConnection(conn io.ReadWriteCloser, locPrivKey crypto.PrivKey) (*SecretConnection, error)

MakeSecretConnection performs handshake and returns a new authenticated SecretConnection. Returns nil if there is an error in handshake. Caller should call conn.Close() See docs/sts-final.pdf for more information.

func (*SecretConnection) Close

func (sc *SecretConnection) Close() error

Implements net.Conn

func (*SecretConnection) LocalAddr

func (sc *SecretConnection) LocalAddr() net.Addr

func (*SecretConnection) Read

func (sc *SecretConnection) Read(data []byte) (n int, err error)

CONTRACT: data smaller than dataMaxSize is read atomically.

func (*SecretConnection) RemoteAddr

func (sc *SecretConnection) RemoteAddr() net.Addr

func (*SecretConnection) RemotePubKey

func (sc *SecretConnection) RemotePubKey() crypto.PubKey

RemotePubKey returns authenticated remote pubkey

func (*SecretConnection) SetDeadline

func (sc *SecretConnection) SetDeadline(t time.Time) error

func (*SecretConnection) SetReadDeadline

func (sc *SecretConnection) SetReadDeadline(t time.Time) error

func (*SecretConnection) SetWriteDeadline

func (sc *SecretConnection) SetWriteDeadline(t time.Time) error

func (*SecretConnection) Write

func (sc *SecretConnection) Write(data []byte) (n int, err error)

Writes encrypted frames of `totalFrameSize + aeadSizeOverhead`. CONTRACT: data smaller than dataMaxSize is written atomically.

Jump to

Keyboard shortcuts

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