Skip to content

Commit

Permalink
Redial if no response longer than 1 min
Browse files Browse the repository at this point in the history
  • Loading branch information
hez2010 committed May 28, 2021
1 parent 78b699b commit 24d089a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Eap/EapAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public sealed class EapAuth : IDisposable
private readonly ReadOnlyMemory<byte> paddedPassword;
private readonly LibPcapLiveDevice device;
private readonly EapOptions options;
private DateTime lastRequest;
private bool disposed = false;
private bool hasLogOff = false;

Expand Down Expand Up @@ -149,20 +150,11 @@ private void EapWorker(EapWorkerState state)
Console.WriteLine("Got EAP Failure.");
switch (state)
{
case { Succeeded: false, FailureCount: < 2 }:
case { Succeeded: false, FailureCount: < 3 }:
state.FailureCount++;
SendStartRequest();
break;
case { Succeeded: false }:
ThreadPool.UnsafeQueueUserWorkItem(EapWorker, new EapWorkerState(), false);
break;
case { Succeeded: true, FailureCount: 0 }:
state.LastId--;
state.FailureCount++;
SendIdResponse(state.LastId);
break;
case { Succeeded: true, FailureCount: < 10 }:
if (state.FailureCount % 2 == 0) state.LastId++;
case { Succeeded: true, FailureCount: < 3 }:
state.FailureCount++;
SendIdResponse(state.LastId);
break;
Expand Down Expand Up @@ -208,6 +200,8 @@ private void EapWorker(EapWorkerState state)
default:
break;
}

lastRequest = DateTime.Now;
break;
case EapCode.LoginMessage when id == 5 && buffer.Length >= 12:
Console.WriteLine("Got Message: " + Encoding.Default.GetString(buffer[12..]));
Expand All @@ -222,6 +216,12 @@ private void EapWorker(EapWorkerState state)
}
}
}

if (DateTime.Now - lastRequest > TimeSpan.FromMinutes(1))
{
ThreadPool.UnsafeQueueUserWorkItem(EapWorker, new EapWorkerState(), false);
return;
}
}
}
}
Expand Down

0 comments on commit 24d089a

Please sign in to comment.