stop trying to interpret TCP, reorder via message counter and hostinfo-creation-order

This commit is contained in:
JackDoan
2026-08-03 14:42:25 -05:00
parent cdfba18ea5
commit 5ea48c1677
10 changed files with 534 additions and 819 deletions
+13
View File
@@ -14,6 +14,16 @@ import (
const ReplayWindow = 8192
// sessionEpoch hands out a receiver-local ordinal to every ConnectionState as
// it is created. The RX staging sort (overlay/batch) orders packets by
// (epoch, message counter). A re-handshake never rekeys an existing tunnel; it
// brings up a whole new hostinfo (and ConnectionState) with its own counter
// space starting near zero, while the old tunnel keeps decrypting in-flight
// packets until it is torn down. During that cutover one flush batch can hold
// packets from both tunnels, and the epoch is what keeps the old tunnel's
// packets sorted ahead of the new tunnel's.
var sessionEpoch atomic.Uint64
type ConnectionState struct {
eKey noiseutil.CipherState
dKey noiseutil.CipherState
@@ -24,6 +34,8 @@ type ConnectionState struct {
window *Bits
decryptLock sync.Mutex
writeLock sync.Mutex
// epoch is this session's sessionEpoch ordinal. Immutable after creation.
epoch uint64
}
// newConnectionStateFromResult builds a fully-populated ConnectionState from a
@@ -38,6 +50,7 @@ func newConnectionStateFromResult(r *handshake.Result) *ConnectionState {
eKey: noiseutil.NewCipherState(r.EKey, r.Cipher),
dKey: noiseutil.NewCipherState(r.DKey, r.Cipher),
window: NewBits(ReplayWindow),
epoch: sessionEpoch.Add(1),
}
ci.messageCounter.Add(r.MessageIndex)
for i := uint64(1); i <= r.MessageIndex; i++ {