Prevent force tcp when client left between ice and dtls (#1414)

This commit is contained in:
cnderrauber
2023-02-13 13:57:50 +08:00
committed by GitHub
parent 2006359a97
commit e6eabb3a03
+14 -10
View File
@@ -39,10 +39,10 @@ const (
negotiationFailedTimeout = 15 * time.Second negotiationFailedTimeout = 15 * time.Second
dtlsRetransmissionInterval = 100 * time.Millisecond dtlsRetransmissionInterval = 100 * time.Millisecond
iceDisconnectedTimeout = 10 * time.Second // compatible for ice-lite with firefox client iceDisconnectedTimeout = 10 * time.Second // compatible for ice-lite with firefox client
iceFailedTimeout = 25 * time.Second // pion's default iceFailedTimeout = 25 * time.Second // pion's default
iceKeepaliveInterval = 2 * time.Second // pion's default iceKeepaliveInterval = 2 * time.Second // pion's default
minConnectTimeoutAfterICE = 5 * time.Second // min duration for waiting pc to connect after ICE is connected
maxConnectTimeoutAfterICE = 20 * time.Second // max duration for waiting pc to connect after ICE is connected maxConnectTimeoutAfterICE = 20 * time.Second // max duration for waiting pc to connect after ICE is connected
shortConnectionThreshold = 90 * time.Second shortConnectionThreshold = 90 * time.Second
@@ -422,17 +422,21 @@ func (t *PCTransport) setICEConnectedAt(at time.Time) {
// set failure timer for dtls handshake // set failure timer for dtls handshake
iceDuration := at.Sub(t.iceStartedAt) iceDuration := at.Sub(t.iceStartedAt)
connTimeoutAfterICE := 3 * iceDuration // let ice has chance to become disconnected if user close/refresh client app before transport full connected.
if connTimeoutAfterICE < minConnectTimeoutAfterICE { connTimeoutAfterICE := iceDisconnectedTimeout + time.Second + iceDuration
connTimeoutAfterICE = minConnectTimeoutAfterICE if connTimeoutAfterICE < 3*iceDuration {
} else if connTimeoutAfterICE > maxConnectTimeoutAfterICE { connTimeoutAfterICE = 3 * iceDuration
}
if connTimeoutAfterICE > maxConnectTimeoutAfterICE {
connTimeoutAfterICE = maxConnectTimeoutAfterICE connTimeoutAfterICE = maxConnectTimeoutAfterICE
} }
t.params.Logger.Debugw("setting connection timer after ice connected", "timeout", connTimeoutAfterICE, "iceDuration", iceDuration) t.params.Logger.Debugw("setting connection timer after ice connected", "timeout", connTimeoutAfterICE, "iceDuration", iceDuration)
t.connectAfterICETimer = time.AfterFunc(connTimeoutAfterICE, func() { t.connectAfterICETimer = time.AfterFunc(connTimeoutAfterICE, func() {
state := t.pc.ConnectionState() state := t.pc.ConnectionState()
// if pc is still checking or connected but not fully established after timeout, then fire connection fail iceState := t.pc.ICEConnectionState()
if state != webrtc.PeerConnectionStateClosed && state != webrtc.PeerConnectionStateFailed && !t.isFullyEstablished() { // if ice connected, pc is still checking or connected but not fully established after timeout, then fire connection fail
if iceState == webrtc.ICEConnectionStateConnected && state != webrtc.PeerConnectionStateClosed &&
state != webrtc.PeerConnectionStateFailed && !t.isFullyEstablished() {
t.params.Logger.Infow("connect timeout after ICE connected", "timeout", connTimeoutAfterICE, "iceDuration", iceDuration) t.params.Logger.Infow("connect timeout after ICE connected", "timeout", connTimeoutAfterICE, "iceDuration", iceDuration)
t.handleConnectionFailed() t.handleConnectionFailed()
} }