Documentation ¶
Index ¶
- Variables
- func NetPipe() (net.Conn, net.Conn)
- 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 *slog.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") )
var Package = amino.RegisterPackage(amino.NewPackage( "github.com/gnolang/gno/tm2/pkg/p2p/conn", "p2p", amino.GetCallersDirname(), ). WithDependencies(). WithTypes( pkg.Type{ Type: reflect.TypeOf(PacketPing{}), Name: "Ping", }, pkg.Type{ Type: reflect.TypeOf(PacketPong{}), Name: "Pong", }, pkg.Type{ Type: reflect.TypeOf(PacketMsg{}), Name: "Msg", }, ))
Functions ¶
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 `toml:"send_rate"` RecvRate int64 `toml:"recv_rate"` // Maximum payload size MaxPacketMsgPayloadSize int `toml:"max_packet_msg_payload_size"` // Interval to flush writes (throttled) FlushThrottle time.Duration `toml:"flush_throttle"` // Interval to send pings PingInterval time.Duration `toml:"ping_interval"` // Maximum wait time for pongs PongTimeout time.Duration `toml:"pong_timeout"` }
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 {} 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 ¶
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 *slog.Logger)
func (*MConnection) Status ¶
func (c *MConnection) Status() ConnectionStatus
func (*MConnection) String ¶
func (c *MConnection) String() string
type PacketMsg ¶
func (PacketMsg) AssertPacket ¶
func (PacketMsg) AssertPacket()
type PacketPing ¶
type PacketPing struct{}
func (PacketPing) AssertPacket ¶
func (PacketPing) AssertPacket()
type PacketPong ¶
type PacketPong struct{}
func (PacketPong) AssertPacket ¶
func (PacketPong) AssertPacket()
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/classic/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/classic/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) 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