|
@@ -32,15 +32,33 @@ namespace UdPunching.Serv
|
|
|
var peerId = TransferCodec.ReadId(sae.Buffer);
|
|
|
Console.WriteLine($"Incoming packet#{packetSeq:0,000,000} peer id {peerId}");
|
|
|
|
|
|
+ byte[] msgData = null;
|
|
|
+
|
|
|
+ bool ValidateRequest()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ msgData = TransferCodec.DecodeData(_serverRsaCryptoServiceProvider, sae.Buffer);
|
|
|
+ Console.WriteLine($"Incoming packet#{packetSeq:0,000,000} MsgLength: {msgData.Length}");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
var rspMsg = new ExchangeMessage();
|
|
|
|
|
|
var isSessionCreateNew = false;
|
|
|
- var isSessionValidated = false;
|
|
|
+ var isRequestValidated = false;
|
|
|
+
|
|
|
if (OnlineSessions.TryGetValue(peerId, out var session)
|
|
|
&& session.RemoteEndPoint.IpEndPointEqualsTo(sae.RemoteEndPoint))
|
|
|
{
|
|
|
session.Actively();
|
|
|
- isSessionValidated = true;
|
|
|
+ isRequestValidated = ValidateRequest();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -52,29 +70,17 @@ namespace UdPunching.Serv
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- session = new OnlineSession(peerId, sae.RemoteEndPoint, peerRsa);
|
|
|
- OnlineSessions[peerId] = session;
|
|
|
- isSessionCreateNew = true;
|
|
|
- isSessionValidated = true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- byte[] msgData = null;
|
|
|
- if (isSessionValidated)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- msgData = TransferCodec.DecodeData(_serverRsaCryptoServiceProvider, sae.Buffer);
|
|
|
- Console.WriteLine($"Incoming packet#{packetSeq:0,000,000} MsgLength: {msgData.Length}");
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- Console.WriteLine(ex);
|
|
|
- isSessionValidated = false;
|
|
|
+ isRequestValidated = ValidateRequest();
|
|
|
+ if (isRequestValidated)
|
|
|
+ {
|
|
|
+ session = new OnlineSession(peerId, sae.RemoteEndPoint, peerRsa);
|
|
|
+ OnlineSessions[peerId] = session;
|
|
|
+ isSessionCreateNew = true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (isSessionValidated)
|
|
|
+ if (isRequestValidated)
|
|
|
{
|
|
|
var reqMsg = new ExchangeMessage(msgData);
|
|
|
Console.WriteLine($"Incoming packet#{packetSeq:0,000,000} Flags: {reqMsg.Flags}");
|