Skip to content
Permalink
Browse files

Strengthening TurnClient's fault tolerance

  • Loading branch information...
longfin committed Apr 23, 2019
1 parent fed5858 commit b35d29a309bdfe9139f9d1f823355152bf8fe9e6
Showing with 18 additions and 10 deletions.
  1. +18 −10 Libplanet.Stun/Stun/TurnClient.cs
@@ -213,19 +213,27 @@ private async Task ProcessMessage()
NetworkStream stream = _control.GetStream();
while (true)
{
StunMessage message = await StunMessage.Parse(stream);

if (_connectAttempted != null &&
message is ConnectionAttempt attempt)
try
{
_connectAttempted.SetResult(attempt);
StunMessage message = await StunMessage.Parse(stream);

if (_connectAttempted != null &&
message is ConnectionAttempt attempt)
{
_connectAttempted.SetResult(attempt);
}
else if (_responses.TryGetValue(
message.TransactionId,
out TaskCompletionSource<StunMessage> tcs))
{
tcs.SetResult(message);
_responses.Remove(message.TransactionId);
}
}
else if (_responses.TryGetValue(
message.TransactionId,
out TaskCompletionSource<StunMessage> tcs))
catch (Exception)
{
tcs.SetResult(message);
_responses.Remove(message.TransactionId);
// Ignore the exception and retry.
// FIXME add logging framework and a proper log message.
}
}
}

0 comments on commit b35d29a

Please sign in to comment.
You can’t perform that action at this time.