this.CanHandleApplicationData = false;
this.QueuedApplicationDataMessage.Clear();
- this.CurrentEpoch = new CurrentEpoch();
this.CurrentEpoch.NextOutgoingSequence = 2; // Account for our ClientHelloVerify
this.CurrentEpoch.NextExpectedSequence = nextExpectedSequenceNumber;
this.CurrentEpoch.PreviousSequenceWindowBitmask = 0;
this.CurrentEpoch.ServerFinishedVerification.SecureClear();
this.CurrentEpoch.ExpectedClientFinishedVerification.SecureClear();
- this.NextEpoch = new NextEpoch();
this.NextEpoch.State = HandshakeState.ExpectingHello;
this.NextEpoch.RecordProtection = null;
this.NextEpoch.ClientRandom = new byte[Random.Size];
--- /dev/null
+using Hazel.Udp;
+using System.Net;
+using System.Security.Cryptography;
+
+namespace Hazel.Dtls
+{
+ /// <summary>
+ /// Connects to a UDP-DTLS server
+ /// </summary>
+ /// <inheritdoc />
+ public abstract class DtlsUnityConnection : UnityUdpClientConnection
+ {
+ private RSA[] serverPublicKeys;
+
+ /// <summary>
+ /// Create a new instance of the DTLS connection
+ /// </summary>
+ /// <inheritdoc />
+ public DtlsUnityConnection(IPEndPoint remoteEndPoint, IPMode ipMode = IPMode.IPv4)
+ : base(remoteEndPoint, ipMode)
+ {
+ }
+
+ /// <inheritdoc />
+ protected override void Dispose(bool disposing)
+ {
+ base.Dispose(disposing);
+ }
+
+ /// <summary>
+ /// Set the list of server public keys
+ /// </summary>
+ /// <param name="serverPublicKeys">
+ /// List of public keys of authentic servers
+ /// </param>
+ public void SetPublicKeys(RSA[] serverPublicKeys)
+ {
+ if (this.serverPublicKeys != null)
+ {
+ foreach (RSA publicKey in this.serverPublicKeys)
+ {
+ publicKey?.Dispose();
+ }
+ }
+
+ this.serverPublicKeys = serverPublicKeys;
+ }
+
+ /// <summary>
+ /// Abort the existing connection and restart the process
+ /// </summary>
+ protected override void RestartConnection()
+ {
+ throw new System.NotImplementedException();
+ base.RestartConnection();
+ }
+
+ /// <inheritdoc />
+ protected override void WriteBytesToConnection(byte[] bytes, int length)
+ {
+ throw new System.NotImplementedException();
+ }
+
+ /// <inheritdoc />
+ protected internal override void HandleReceive(MessageReader message, int bytesReceived)
+ {
+ throw new System.NotImplementedException();
+ }
+ }
+}
<Compile Include="DataReceivedEventArgs.cs" />
<Compile Include="DisconnectedEventArgs.cs" />
<Compile Include="Dtls\AesGcmRecordProtection.cs" />
+ <Compile Include="Dtls\DtlsUnityConnection.cs" />
<Compile Include="Dtls\DtlsConnectionListener.cs" />
<Compile Include="Dtls\Handshake.cs" />
<Compile Include="Dtls\IHandshakeCipherSuite.cs" />
-using System;
+using System;
using System.Net.Sockets;
namespace Hazel.Udp
/// Handles the receiving of data.
/// </summary>
/// <param name="message">The buffer containing the bytes received.</param>
- protected internal void HandleReceive(MessageReader message, int bytesReceived)
+ protected internal virtual void HandleReceive(MessageReader message, int bytesReceived)
{
ushort id;
switch (message.Buffer[0])
-using System;
+using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
}
public void FixedUpdate()
+ {
+ this.ResendPacketsIfNeeded();
+ }
+
+ protected virtual void RestartConnection()
+ {
+ }
+
+ protected virtual void ResendPacketsIfNeeded()
{
base.ManageReliablePackets();
}
throw new HazelException("A SocketException occurred while binding to the port.", e);
}
+ this.RestartConnection();
+
try
{
StartListeningForData();
base.Dispose(disposing);
}
}
-}
\ No newline at end of file
+}