From: Matthew Endsley Date: Wed, 3 Feb 2021 11:38:34 +0000 (-0800) Subject: Acquire lock when resending DTLS packets X-Git-Tag: 1.0.0~20^2~6 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=a94306da3efdcdb43956d94486d7a11eb16f06d6;p=rhonda%2Fimpostor.hazel.git Acquire lock when resending DTLS packets --- diff --git a/Hazel/Dtls/DtlsUnityConnection.cs b/Hazel/Dtls/DtlsUnityConnection.cs index 9800c88..79af8fd 100644 --- a/Hazel/Dtls/DtlsUnityConnection.cs +++ b/Hazel/Dtls/DtlsUnityConnection.cs @@ -208,29 +208,32 @@ namespace Hazel.Dtls /// protected override void ResendPacketsIfNeeded() { - // Check if we need to resend handshake message - if (this.nextEpoch.State != HandshakeState.Established) + lock (this.syncRoot) { - DateTime now = DateTime.UtcNow; - if (now >= this.nextEpoch.NextPacketResendTime) + // Check if we need to resend handshake message + if (this.nextEpoch.State != HandshakeState.Established) { - switch (this.nextEpoch.State) + DateTime now = DateTime.UtcNow; + if (now >= this.nextEpoch.NextPacketResendTime) { - case HandshakeState.ExpectingServerHello: - case HandshakeState.ExpectingCertificate: - case HandshakeState.ExpectingServerKeyExchange: - case HandshakeState.ExpectingServerHelloDone: - this.SendClientHello(); - break; + switch (this.nextEpoch.State) + { + case HandshakeState.ExpectingServerHello: + case HandshakeState.ExpectingCertificate: + case HandshakeState.ExpectingServerKeyExchange: + case HandshakeState.ExpectingServerHelloDone: + this.SendClientHello(); + break; - case HandshakeState.ExpectingChangeCipherSpec: - case HandshakeState.ExpectingFinished: - this.SendClientKeyExchangeFlight(true); - break; + case HandshakeState.ExpectingChangeCipherSpec: + case HandshakeState.ExpectingFinished: + this.SendClientKeyExchangeFlight(true); + break; - case HandshakeState.Established: - default: - break; + case HandshakeState.Established: + default: + break; + } } } }