Documentation
¶
Overview ¶
Package forward 实现 P2P 失败时的应用层加密字节转发数据面(执行计划 §6.8): 按 sessionId 维护独立的有界控制/数据队列,控制先行且跨会话公平;终局 控制排空后才移除会话。队列满只断该会话,绝不让单个慢端停读共享 WS。 不解析内层帧,对密文零知识。
Index ¶
- Constants
- Variables
- type EnqueueResult
- type Options
- type Pump
- func (p *Pump) Close()
- func (p *Pump) CloseSession(id protocol.SessionID) EnqueueResult
- func (p *Pump) Done() <-chan struct{}
- func (p *Pump) EnqueueConnection(binary bool, data []byte) EnqueueResult
- func (p *Pump) EnqueueConnectionBorrowed(binary bool, data []byte) (EnqueueResult, <-chan error)
- func (p *Pump) EnqueueForward(id protocol.SessionID, frame []byte) EnqueueResult
- func (p *Pump) EnqueueForwardContext(ctx context.Context, id protocol.SessionID, frame []byte) EnqueueResult
- func (p *Pump) EnqueueSessionControl(id protocol.SessionID, binary bool, data []byte) EnqueueResult
- func (p *Pump) EnqueueSessionTerminal(id protocol.SessionID, binary bool, data []byte) (EnqueueResult, <-chan error)
- func (p *Pump) Err() error
- func (p *Pump) OpenSession(id protocol.SessionID) EnqueueResult
- func (p *Pump) WaitIdle(ctx context.Context) bool
- type Writer
Constants ¶
const ( DefaultConnectionQueueMessages = 256 DefaultSessionControlMessages = 32 )
const DefaultSessionQueueFrames = session.InFlightWindow * (NominalBlockBytes / session.MaxFrameSize)
const NominalBlockBytes = 1024 * 1024
Variables ¶
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 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 (*Pump) CloseSession ¶
func (p *Pump) CloseSession(id protocol.SessionID) EnqueueResult
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 (*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) OpenSession ¶
func (p *Pump) OpenSession(id protocol.SessionID) EnqueueResult