conn

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0, UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSmallOrderRemotePubKey = errors.New("detected low order point from remote peer")
View Source
var Package = amino.RegisterPackage(amino.NewPackage(
	"github.com/gnolang/gno/tm2/pkg/p2p/conn",
	"p2p",
	amino.GetCallersDirname(),
).
	WithDependencies().
	WithTypes(

		pkg.Type{
			Type: reflect.TypeFor[PacketPing](),
			Name: "Ping",
		},
		pkg.Type{
			Type: reflect.TypeFor[PacketPong](),
			Name: "Pong",
		},
		pkg.Type{
			Type: reflect.TypeFor[PacketMsg](),
			Name: "Msg",
		},
	))

Functions

func NetPipe

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

Types

type Channel

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

TODO: lowercase. NOTE: not goroutine-safe.

func (*Channel) SetLogger

func (ch *Channel) SetLogger(l *slog.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 `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"`

	// RecvAssemblyTimeout bounds how long a single incomplete message may be
	// assembled from partial PacketMsgs in a channel's recving buffer. The
	// deadline is anchored to the first partial packet of a message and is not
	// extended by later packets, but time spent inside a reactor callback is
	// credited back. When <= 0 no assembly deadline is enforced.
	RecvAssemblyTimeout time.Duration `toml:"recv_assembly_timeout"`

	// MaxRecvBufferBytes caps the total bytes buffered across all of the
	// connection's channels' recving buffers at any instant. When <= 0 no total
	// budget is enforced (only the per-channel RecvMessageCapacity applies).
	MaxRecvBufferBytes int `toml:"max_recv_buffer_bytes"`

	// MaxSendBufferBytes caps total admitted bytes waiting, queued, or sending
	// across all channels. When <= 0 only each channel's queue capacity applies.
	MaxSendBufferBytes int `toml:"max_send_buffer_bytes"`
}

MConnConfig is a MConnection configuration.

func DefaultMConnConfig

func DefaultMConnConfig() MConnConfig

DefaultMConnConfig returns the default config.

func MConfigFromP2P

func MConfigFromP2P(cfg *config.P2PConfig) MConnConfig

MConfigFromP2P returns a multiplex connection configuration with fields updated from the P2PConfig

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 or the connection's byte budget 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) 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 *slog.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 {
	AssertPacket()
}

type PacketMsg

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

func (PacketMsg) AssertPacket

func (PacketMsg) AssertPacket()

func (PacketMsg) MarshalBinary2

func (goo PacketMsg) MarshalBinary2(cdc *amino.Codec, buf []byte, offset int) (int, error)

func (PacketMsg) SizeBinary2

func (goo PacketMsg) SizeBinary2(cdc *amino.Codec) (int, error)

func (PacketMsg) String

func (mp PacketMsg) String() string

func (*PacketMsg) UnmarshalBinary2

func (goo *PacketMsg) UnmarshalBinary2(cdc *amino.Codec, bz []byte, anyDepth int) error

type PacketPing

type PacketPing struct{}

func (PacketPing) AssertPacket

func (PacketPing) AssertPacket()

func (PacketPing) MarshalBinary2

func (goo PacketPing) MarshalBinary2(cdc *amino.Codec, buf []byte, offset int) (int, error)

func (PacketPing) SizeBinary2

func (goo PacketPing) SizeBinary2(cdc *amino.Codec) (int, error)

func (*PacketPing) UnmarshalBinary2

func (goo *PacketPing) UnmarshalBinary2(cdc *amino.Codec, bz []byte, anyDepth int) error

type PacketPong

type PacketPong struct{}

func (PacketPong) AssertPacket

func (PacketPong) AssertPacket()

func (PacketPong) MarshalBinary2

func (goo PacketPong) MarshalBinary2(cdc *amino.Codec, buf []byte, offset int) (int, error)

func (PacketPong) SizeBinary2

func (goo PacketPong) SizeBinary2(cdc *amino.Codec) (int, error)

func (*PacketPong) UnmarshalBinary2

func (goo *PacketPong) UnmarshalBinary2(cdc *amino.Codec, bz []byte, anyDepth int) error

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 ed25519.PrivKeyEd25519) (*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() ed25519.PubKeyEd25519

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