Documentation
¶
Overview ¶
Package mplex provides an explicit /mplex/6.7.0 transport for consensus peers.
Dial opens one TCP connection to Target.ConsensusP2P. It runs multistream-select and Noise with the case identity. It then negotiates /mplex/6.7.0 and returns the connection to the caller.
The caller owns the framing. Open, Data, Close, Reset, and Frame send one frame each, with a caller-chosen stream ID and payload. Drain is the only read path. The package starts no goroutine and reads nothing on its own. Between Drain calls the caller withholds its reads, which applies TCP backpressure to the peer.
A connection has one identity and a cap on outbound bytes (MaxSend). Each frame is reported to the session observer with Protocol "mplex" and Raw set.
conn, err := mplex.Dial(ctx, target, 0)
if err != nil {
return err
}
defer conn.Shut()
if err := conn.Open(1, "stream"); err != nil {
return err
}
frames, err := conn.Drain(time.Second)
Index ¶
- Constants
- type Conn
- func (c *Conn) Close(id uint64) error
- func (c *Conn) Data(id uint64, payload []byte) error
- func (c *Conn) Drain(d time.Duration) ([]Frame, error)
- func (c *Conn) Frame(id, flag uint64, payload []byte) error
- func (c *Conn) Negotiated() string
- func (c *Conn) Open(id uint64, name string) error
- func (c *Conn) Received() uint64
- func (c *Conn) Reset(id uint64) error
- func (c *Conn) Sent() uint64
- func (c *Conn) Shut() error
- type Frame
Constants ¶
const ( // MaxSend caps the bytes the connection writes after the multiplexer is negotiated. MaxSend = 64 << 20 // MaxFrame is the largest frame payload (the mplex limit, 1 MiB). MaxFrame = 1 << 20 )
const ( FlagOpen = 0 FlagDataReceiver = 1 FlagDataInitiator = 2 FlagCloseReceiver = 3 FlagCloseInit = 4 FlagResetReceiver = 5 FlagResetInit = 6 )
Frame flags. The mplex header is (stream ID << 3) | flag.
const ProtocolID = "/mplex/6.7.0"
ProtocolID is the only stream multiplexer this package negotiates.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is the negotiated mplex connection to the peer.
func Dial ¶
Dial connects to t.ConsensusP2P with the current case identity. It returns once /mplex/6.7.0 is negotiated. Any other outcome is an error. The peer can select another multiplexer or refuse mplex. maxSend bounds the outbound bytes after negotiation (0 means MaxSend).
func DialWithIdentity ¶
func DialWithIdentity(ctx context.Context, t target.Target, key libp2pcrypto.PrivKey, maxSend uint64) (*Conn, error)
DialWithIdentity is Dial with an explicit local identity. Multi-identity cases must opt in explicitly through this path.
func (*Conn) Drain ¶
Drain reads the peer's frames for up to d and returns them. If the peer closes the connection, the read ends with its error after the frames already read. Between Drain calls nothing is read, which is the backpressure.
func (*Conn) Frame ¶
Frame sends one frame with a caller-chosen flag (0 to 6). Use it for a flag that the helpers above do not cover.
func (*Conn) Negotiated ¶
Negotiated is the multiplexer the connection runs; it is always ProtocolID, since Dial fails otherwise.