tcp: simplified Policy implementation based on @MDr164 (#190)

* begin prepping policy refactor manually

* implement tcp.Policy and refactor rto to use it

* fix CI

* chatting with claude gave me idea to reformulate Policy

* tcp.Policy: add newTransmitLimit output

* merge with main and fix failing tests

* remove fix.patch

* answer my own comments
This commit is contained in:
Pat Whittingslow
2026-09-07 10:46:24 -03:00
committed by GitHub
parent d7f3924489
commit 07afcfd924
14 changed files with 1518 additions and 806 deletions
+5 -15
View File
@@ -76,16 +76,10 @@ type ConnConfig struct {
// Logger sets the [Conn] logger.
// Lower level logging available at [Handler.SetLoggers] via [Conn.InternalHandler].
Logger *slog.Logger
// LossRecovery is the optional packet-loss recovery algorithm (RTO,
// congestion control, ...) for the connection. If set, Nanotime must also be
// set (else Configure returns an error). Leaving it nil disables loss
// recovery. See [LossRecovery].
LossRecovery LossRecovery
// Nanotime is the monotonic time source in nanoseconds (the func() int64
// convention used across lneto) that drives LossRecovery. It is required when
// LossRecovery is set and unused otherwise. The tcp package reads it only to
// stamp the loss-recovery hooks; it holds no clock itself.
Nanotime func() int64
// Policy is the optional transmit-steering algorithm (RTO, congestion
// control, ...) for the connection. nil disables it. A Policy needing time
// carries its own clock. See [Policy].
Policy Policy
}
// Configure should be called on any newly created connection before usage. See [ConnConfig].
@@ -93,10 +87,6 @@ func (conn *Conn) Configure(config ConnConfig) (err error) {
if config.RWBackoff == nil {
return lneto.ErrMissingHALConfig
}
if config.LossRecovery != nil && config.Nanotime == nil {
// The tcp package holds no clock: a loss-recovery algorithm cannot run without it.
return lneto.ErrInvalidConfig
}
conn.mu.Lock()
defer conn.mu.Unlock()
err = conn.h.SetBuffers(config.TxBuf, config.RxBuf, config.TxPacketQueueSize)
@@ -105,7 +95,7 @@ func (conn *Conn) Configure(config ConnConfig) (err error) {
}
conn._backoff = config.RWBackoff
conn.logger.log = config.Logger
conn.h.SetLossRecovery(config.LossRecovery, config.Nanotime)
conn.h.SetPolicy(config.Policy)
return nil
}