mirror of
https://github.com/openlibrecommunity/olcrtc.git
synced 2026-05-26 07:08:11 +00:00
fix(vp8channel): reset peer state on KCP restart
This commit is contained in:
@@ -105,11 +105,16 @@ func runRealSoakOnce(t *testing.T, carrierName, transportName, roomURL, echoAddr
|
||||
carrierName, transportName, *realSoakDuration, *realSoakChunk,
|
||||
*realSoakVerify, *realSoakProgress)
|
||||
|
||||
expectation := realE2ECaseExpectation(carrierName, transportName)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), *realSoakDuration+setupBudget)
|
||||
defer cancel()
|
||||
|
||||
rt, err := startRealTunnel(ctx, t, carrierName, transportName, roomURL, testClientDeviceID, testClientDeviceID)
|
||||
if err != nil {
|
||||
if expectation == realE2EExpectUnstable || expectation == realE2EExpectFail {
|
||||
t.Skipf("start tunnel failed (expected %s): %v", realE2EExpectationLabel(expectation), err)
|
||||
}
|
||||
t.Fatalf("start tunnel: %v", err)
|
||||
}
|
||||
_ = rt
|
||||
|
||||
@@ -418,6 +418,8 @@ func (p *streamTransport) drainOutbound() {
|
||||
// this before rebuilding smux so replacement handshakes are not parsed behind
|
||||
// stale bytes from streams that were active when the old session died.
|
||||
func (p *streamTransport) ResetPeer() {
|
||||
p.peerConfirmed.Store(false)
|
||||
p.peerEpoch.Store(0)
|
||||
p.restartKCP(p.rotateEpochHeader())
|
||||
}
|
||||
|
||||
@@ -549,6 +551,8 @@ func appendBatchPacket(dst, packet []byte) []byte {
|
||||
}
|
||||
|
||||
func (p *streamTransport) resetKCP() {
|
||||
p.peerConfirmed.Store(false)
|
||||
p.peerEpoch.Store(0)
|
||||
p.restartKCP(p.epochHeader())
|
||||
}
|
||||
|
||||
|
||||
@@ -378,13 +378,16 @@ func TestHandleIncomingFrameEpochFilteringAndReconnect(t *testing.T) {
|
||||
t.Fatalf("stream reconnect did not reset/callback: reconnected=%v kcp=%v", reconnected, tr.kcp)
|
||||
}
|
||||
reconnected = false
|
||||
// Peer is already confirmed from the first frame above.
|
||||
// In single-peer mode, frames from a different epoch are ignored.
|
||||
tr.handleIncomingFrame(mkFrame(tr.bindingToken, 2, []byte("other-participant")))
|
||||
if reconnected {
|
||||
t.Fatal("epoch change from another participant should not trigger reconnect")
|
||||
// After reconnect, peerConfirmed is reset so the next frame re-latches
|
||||
// the peer epoch. This allows the server to restart with a new epoch.
|
||||
if tr.peerConfirmed.Load() {
|
||||
t.Fatal("reconnect should reset peerConfirmed")
|
||||
}
|
||||
if tr.peerEpoch.Load() != 1 {
|
||||
t.Fatalf("peer epoch changed unexpectedly: got %d want 1", tr.peerEpoch.Load())
|
||||
tr.handleIncomingFrame(mkFrame(tr.bindingToken, 2, []byte("new-peer-after-reconnect")))
|
||||
if !tr.peerConfirmed.Load() {
|
||||
t.Fatal("frame after reconnect should re-latch peer")
|
||||
}
|
||||
if tr.peerEpoch.Load() != 2 {
|
||||
t.Fatalf("peer epoch not re-latched: got %d want 2", tr.peerEpoch.Load())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user