forward

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 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 forward 实现 P2P 失败时的应用层加密字节转发数据面(执行计划 §6.8): 按 sessionId 维护独立的有界控制/数据队列,控制先行且跨会话公平;终局 控制排空后才移除会话。队列满只断该会话,绝不让单个慢端停读共享 WS。 不解析内层帧,对密文零知识。

Index

Constants

View Source
const (
	DefaultConnectionQueueMessages = 256
	DefaultSessionControlMessages  = 32
)
View Source
const DefaultSessionQueueFrames = session.InFlightWindow * (NominalBlockBytes / session.MaxFrameSize)
View Source
const NominalBlockBytes = 1024 * 1024

Variables

View Source
var (
	ErrPumpClosed    = errors.New("forward: pump closed")
	ErrSessionClosed = errors.New("forward: session closed before terminal delivery")
)

Functions

This section is empty.

Types

type EnqueueResult

type EnqueueResult int
const (
	Enqueued EnqueueResult = iota
	Overflow
	UnknownSession
	SessionTerminated
	PumpClosed
	ContextDone
)

type Options

type Options struct {
	ConnectionQueueMessages int
	SessionControlMessages  int
	SessionQueueFrames      int
}

type Pump

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

Pump owns one connection writer. Connection-scoped messages have their own bounded lane. Every session has separate control and data queues; scheduling is round-robin by session, with that session's control always preceding data.

A terminal is a state transition, not an ordinary high-priority item. Once accepted it atomically discards queued signals/data, rejects later traffic, and removes the queue only after the writer reports the terminal delivered.

func NewPump

func NewPump(w Writer, opts Options) *Pump

func (*Pump) Close

func (p *Pump) Close()

func (*Pump) CloseSession

func (p *Pump) CloseSession(id protocol.SessionID) EnqueueResult

func (*Pump) Done

func (p *Pump) Done() <-chan struct{}

func (*Pump) EnqueueConnection

func (p *Pump) EnqueueConnection(binary bool, data []byte) EnqueueResult

func (*Pump) EnqueueConnectionBorrowed

func (p *Pump) EnqueueConnectionBorrowed(binary bool, data []byte) (EnqueueResult, <-chan error)

EnqueueConnectionBorrowed transfers an immutable payload into the connection lane without copying it. The caller must retain the payload's owner until the receipt completes; non-Enqueued results do not transfer ownership.

func (*Pump) EnqueueForward

func (p *Pump) EnqueueForward(id protocol.SessionID, frame []byte) EnqueueResult

func (*Pump) EnqueueForwardContext

func (p *Pump) EnqueueForwardContext(ctx context.Context, id protocol.SessionID, frame []byte) EnqueueResult

EnqueueForwardContext applies producer backpressure until the session has capacity. Relay-server callers use EnqueueForward to isolate a slow session; local transport producers use this method because queue saturation is normal flow control, not a session failure.

func (*Pump) EnqueueSessionControl

func (p *Pump) EnqueueSessionControl(id protocol.SessionID, binary bool, data []byte) EnqueueResult

func (*Pump) EnqueueSessionTerminal

func (p *Pump) EnqueueSessionTerminal(id protocol.SessionID, binary bool, data []byte) (EnqueueResult, <-chan error)

EnqueueSessionTerminal returns a receipt closed with the writer result. The terminal owns a reserved slot: even a signal flood cannot prevent the relay from explaining why that session was terminated.

func (*Pump) Err

func (p *Pump) Err() error

func (*Pump) OpenSession

func (p *Pump) OpenSession(id protocol.SessionID) EnqueueResult

func (*Pump) WaitIdle

func (p *Pump) WaitIdle(ctx context.Context) bool

type Writer

type Writer interface {
	WriteText(data []byte) error
	WriteBinary(data []byte) error
}

Jump to

Keyboard shortcuts

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