mirror of
https://github.com/soypat/lneto.git
synced 2026-09-04 05:49:02 +00:00
add loss.go (#168)
This commit is contained in:
+15
@@ -76,6 +76,16 @@ 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
|
||||
}
|
||||
|
||||
// Configure should be called on any newly created connection before usage. See [ConnConfig].
|
||||
@@ -83,6 +93,10 @@ 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)
|
||||
@@ -91,6 +105,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)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user