Documentation
¶
Overview ¶
Package streamconn adapts a gRPC bidirectional Tunnel byte stream (the p2p plugin's data plane) to a net.Conn for the TNET side. The p2p host keeps its own minimal raw conn (p2p/streamconn.go) instead of sharing this one: the plugin module holds contracts only, and the host cannot import the x module. The two sides couple through the proto (Chunk messages), not through code.
Two modes:
- raw ("tcp"): Read/Write move the stream's bytes; writes are split into chunks below gRPC's default message limit.
- framed ("udp"): Read returns exactly one length-prefixed datagram and Write sends one, preserving datagram boundaries through the byte stream (the same 2-byte BE prefix the p2p datagram channel uses — the framing helpers below are the single implementation).
Backpressure ¶
A single Recv pump goroutine hands chunks to Read through a one-chunk channel. A stalled consumer blocks the pump, which stops calling Recv and lets gRPC's per-stream flow control throttle the sender — memory stays bounded at about two chunks.
Deadlines ¶
Read deadlines are enforced by Read itself. A write deadline must interrupt a Send parked in flow control, and only the client side can do that (by cancelling the stream), so a Conn built without an abort func (i.e. from a server stream) rejects write deadlines. Close never blocks: on a server stream it only marks the conn closed — the parked Recv unblocks when the handler returns, which ends the RPC and cancels the stream (grpc-go finishStream calls the stream's cancel for exactly this reason).
Index ¶
- Constants
- func ReadFrame(r io.Reader) ([]byte, error)
- func WriteFrame(w io.Writer, p []byte) error
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(b []byte) (int, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) Write(b []byte) (int, error)
- type Stream
Constants ¶
const MaxFrame = 65535
MaxFrame is the largest payload that fits the 2-byte length prefix.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
func New ¶
Conn is a net.Conn over a Stream. abort, when non-nil, cancels the underlying stream (the client side's context.CancelFunc); the host side passes nil because a server handler cannot abort its stream.
func (*Conn) Close ¶
Close marks the conn closed and aborts the stream when possible. It is idempotent and never blocks on the pump.