conn

package
v0.0.0-...-f47aca1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: Apache-2.0 Imports: 32 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

func NetPipe

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

func RegisterPacket

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 // channel状态
}

type MConnConfig

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

	// 最大有效载荷大小
	MaxPacketMsgPayloadSize int `mapstructure:"max_packet_msg_payload_size"`

	// 刷新写入的间隔(有限制)
	FlushThrottle time.Duration `mapstructure:"flush_throttle"`

	// 发送ping的间隔
	PingInterval time.Duration `mapstructure:"ping_interval"`

	// 最大等待pong的时间
	PongTimeout time.Duration `mapstructure:"pong_timeout"`
}

MConnConfig 是MConnection的配置类.

func DefaultMConnConfig

func DefaultMConnConfig() MConnConfig

DefaultMConnConfig 返回默认配置

type MConnection

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

每个peer都有一个`MConnection`(multiplex connection)实例。 __multiple__ *名词* 一个系统或信号,涉及沿单个通信通道同时传输多个消息。

每个`MConnection`处理多个抽象通信`Channel`上的消息传输。 每个通道都有一个全局唯一的字节ID 在连接初始化时配置每个“通道”的字节ID和相对优先级。

有两种方式来发送信息:

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

"Send(chID,msgBytes)" 是一个阻塞调用,等待直到“ msg”成功排队进入具有给定id字节"chID"的通道, 或者直到请求超时。 消息“ msg”是使用Go-Amino序列化的。

"TrySend(chID, msgBytes)" 是一个非阻塞调用,如果队列已满,返回false。

入站消息字节使用onReceive回调函数处理。

func NewMConnection

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

NewMConnection wraps net.Conn and creates multiplex connection NewMConnection 封装net.Conn并创建多重连接

func NewMConnectionWithConfig

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

NewMConnectionWithConfig 封装net.Conn并创建多重连接,有配置

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

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.

func (*MConnection) OnStart

func (c *MConnection) OnStart() error

OnStart 重写了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

type Packet interface {
	AssertIsPacket()
}

type PacketMsg

type PacketMsg struct {
	ChannelID byte
	EOF       byte // 1 表示消息再次结束
	Bytes     []byte
}

func (PacketMsg) AssertIsPacket

func (PacketMsg) AssertIsPacket()

func (PacketMsg) String

func (mp PacketMsg) String() string

type PacketPing

type PacketPing struct {
}

func (PacketPing) AssertIsPacket

func (PacketPing) AssertIsPacket()

type PacketPong

type PacketPong struct {
}

func (PacketPong) AssertIsPacket

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. See https://github.com/wjbbig/candy/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/wjbbig/candy/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 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 `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