streamconn

package
v0.28.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const MaxFrame = 65535

MaxFrame is the largest payload that fits the 2-byte length prefix.

Variables

This section is empty.

Functions

func ReadFrame

func ReadFrame(r io.Reader) ([]byte, error)

ReadFrame reads one length-prefixed frame. A zero-length frame returns (nil, nil); the caller should skip it.

func WriteFrame

func WriteFrame(w io.Writer, p []byte) error

WriteFrame writes p as one length-prefixed frame.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func New

func New(s Stream, abort func(), network string, local, remote net.Addr) *Conn

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

func (c *Conn) Close() error

Close marks the conn closed and aborts the stream when possible. It is idempotent and never blocks on the pump.

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

type Stream

type Stream interface {
	Send(*proto.Chunk) error
	Recv() (*proto.Chunk, error)
	Context() context.Context
}

Stream is the data-carrying half of the P2P Tunnel RPC; it is satisfied by both proto.P2P_TunnelClient and proto.P2P_TunnelServer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL