Documentation ¶
Index ¶
- Variables
- func NetPipe() (net.Conn, net.Conn)
- func RegisterPacket(cdc *amino.Codec)
- type Channel
- type ChannelDescriptor
- type ChannelStatus
- type ConnectionStatus
- type MConnConfig
- type MConnection
- func (c *MConnection) CanSend(chID byte) bool
- func (c *MConnection) FlushStop()
- func (c *MConnection) OnStart() error
- func (c *MConnection) OnStop()
- func (c *MConnection) Send(chID byte, msgBytes []byte) bool
- func (c *MConnection) SetLogger(l log.Logger)
- func (c *MConnection) Status() ConnectionStatus
- func (c *MConnection) String() string
- func (c *MConnection) TrySend(chID byte, msgBytes []byte) bool
- type Packet
- type PacketMsg
- type PacketPing
- type PacketPong
- type SecretConnection
- func (sc *SecretConnection) Close() error
- func (sc *SecretConnection) LocalAddr() net.Addr
- func (sc *SecretConnection) Read(data []byte) (n int, err error)
- func (sc *SecretConnection) RemoteAddr() net.Addr
- func (sc *SecretConnection) RemotePubKey() crypto.PubKey
- func (sc *SecretConnection) SetDeadline(t time.Time) error
- func (sc *SecretConnection) SetReadDeadline(t time.Time) error
- func (sc *SecretConnection) SetWriteDeadline(t time.Time) error
- func (sc *SecretConnection) Write(data []byte) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
var (
ErrSmallOrderRemotePubKey = errors.New("detected low order point from remote peer")
)
Functions ¶
func RegisterPacket ¶
Types ¶
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 ConnectionStatus ¶
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的配置类.
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) 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
type PacketMsg ¶
func (PacketMsg) AssertIsPacket ¶
func (PacketMsg) AssertIsPacket()
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