forked from ByronAP/OtpSharp.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVerificationWindow.cs
49 lines (44 loc) · 1.63 KB
/
VerificationWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Collections.Generic;
namespace OtpSharp
{
/// <summary>
/// A verification window
/// </summary>
public class VerificationWindow
{
private readonly int previous;
private readonly int future;
/// <summary>
/// Create an instance of a verification window
/// </summary>
/// <param name="previous">The number of previous frames to accept</param>
/// <param name="future">The number of future frames to accept</param>
public VerificationWindow(int previous = 0, int future = 0)
{
this.previous = previous;
this.future = future;
}
/// <summary>
/// Gets an enumberable of all the possible validation candidates
/// </summary>
/// <param name="initialFrame">The initial frame to validate</param>
/// <returns>Enumberable of all possible frames that need to be validated</returns>
public IEnumerable<long> ValidationCandidates(long initialFrame)
{
yield return initialFrame;
for (int i = 1; i <= previous; i++)
{
var val = initialFrame - i;
if (val < 0)
break;
yield return val;
}
for (int i = 1; i <= future; i++)
yield return initialFrame + i;
}
/// <summary>
/// The verification window that accomodates network delay that is recommended in the RFC
/// </summary>
public static readonly VerificationWindow RfcSpecifiedNetworkDelay = new VerificationWindow(previous: 1, future: 1);
}
}