conn

package
v0.26.4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2018 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NetPipe

func NetPipe() (net.Conn, net.Conn)

func RegisterPacket added in v0.19.0

func RegisterPacket(cdc *amino.Codec)

Types

type Channel

type Channel struct {
	Logger log.Logger
	// contains filtered or unexported fields
}

TODO: lowercase. NOTE: not goroutine-safe.

func (*Channel) SetLogger

func (ch *Channel) SetLogger(l log.Logger)

type ChannelDescriptor

type ChannelDescriptor struct {
	ID                  byte
	Priority            int
	SendQueueCapacity   int
	RecvBufferCapacity  int
	RecvMessageCapacity int
}

func (ChannelDescriptor) FillDefaults

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

type ChannelStatus

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

type ConnectionStatus

type ConnectionStatus struct {
	Duration    time.Duration
	SendMonitor flow.Status
	RecvMonitor flow.Status
	Channels    []ChannelStatus
}

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"`
}

MConnConfig is a MConnection configuration.

func DefaultMConnConfig

func DefaultMConnConfig() MConnConfig

DefaultMConnConfig returns the default config.

type MConnection

type MConnection struct {
	cmn.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 {}
func (m MConnection) TrySend(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 Go-Amino.

`TrySend(chID, msgBytes)` is a nonblocking call that returns false if the channel's queue is full.

Inbound message bytes are handled with an onReceive callback function.

func NewMConnection

func NewMConnection(conn net.Conn, chDescs []*ChannelDescriptor, onReceive receiveCbFunc, onError errorCbFunc) *MConnection

NewMConnection wraps net.Conn and creates multiplex connection

func NewMConnectionWithConfig

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

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

func (*MConnection) CanSend

func (c *MConnection) CanSend(chID byte) bool

CanSend returns true if you can send more data onto the chID, false otherwise. Use only as a heuristic.

func (*MConnection) FlushStop added in v0.26.3

func (c *MConnection) FlushStop()

FlushStop replicates the logic of OnStop. It additionally ensures that all successful .Send() calls will get flushed before closing the connection. NOTE: it is not safe to call this method more than once.

func (*MConnection) OnStart

func (c *MConnection) OnStart() error

OnStart implements BaseService

func (*MConnection) OnStop

func (c *MConnection) OnStop()

OnStop implements BaseService

func (*MConnection) Send

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

Queues a message to be sent to channel.

func (*MConnection) SetLogger

func (c *MConnection) SetLogger(l log.Logger)

func (*MConnection) Status

func (c *MConnection) Status() ConnectionStatus

func (*MConnection) String

func (c *MConnection) String() string

func (*MConnection) TrySend

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

Queues a message to be sent to channel. Nonblocking, returns true if successful.

type Packet added in v0.19.0

type Packet interface {
	AssertIsPacket()
}

type PacketMsg added in v0.19.0

type PacketMsg struct {
	ChannelID byte
	EOF       byte // 1 means message ends here.
	Bytes     []byte
}

func (PacketMsg) AssertIsPacket added in v0.19.0

func (_ PacketMsg) AssertIsPacket()

func (PacketMsg) String added in v0.19.0

func (mp PacketMsg) String() string

type PacketPing added in v0.19.0

type PacketPing struct {
}

func (PacketPing) AssertIsPacket added in v0.19.0

func (_ PacketPing) AssertIsPacket()

type PacketPong added in v0.19.0

type PacketPong struct {
}

func (PacketPong) AssertIsPacket added in v0.19.0

func (_ PacketPong) AssertIsPacket()

type SecretConnection

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

SecretConnection implements net.conn. It is an implementation of the STS protocol. Note we do not (yet) assume that a remote peer's pubkey is known ahead of time, and thus we are technically still vulnerable to MITM. (TODO!) See docs/sts-final.pdf for more info

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 nolint

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 `sealedFrameSize` CONTRACT: data smaller than dataMaxSize is read atomically.

Jump to

Keyboard shortcuts

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