Skip to content

Commit 6985a27

Browse files
committed
Fix typos and remove old code
1 parent 5c04e62 commit 6985a27

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

WireguardAllowedIPs/Core/Calculator.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,16 @@ private static IPNetwork[] CleanAllowedIPs(IPNetwork[] values, IPNetwork[] allow
1919
{
2020
List<IPNetwork> result = new(values);
2121

22-
// Remove all entries which conflict with one ore more disallowed ips
22+
// Remove all entries which conflict with one or more disallowed ips
2323
result.RemoveAll(x => disallowed.Any(y => x.Overlaps(y)));
2424

25-
// Remove all entires which are outside of the underlying AllowedIPs-Ranges
25+
// Remove all entries which are outside of the underlying AllowedIPs-Ranges
2626
// Nothing happens here if the underlying range is the entire address space (e.g. 0.0.0.0/0 or ::/0)
2727
result.RemoveAll(x => allowed.Any(y => !y.Contains(x)));
2828

2929
// Add the networks which did not conflict with any disallowed ips
3030
result.AddRange(allowed.Where(x => !disallowed.Any(y => y.Overlaps(x))));
3131

32-
/*List<int> rIndices = new();
33-
for(int i = 0; i < result.Count; i++)
34-
{
35-
for(int j = 0; j < result.Count; j++)
36-
{
37-
if(j == i)
38-
continue;
39-
if(result[i] == result[j])
40-
{
41-
rIndices.Add(j);
42-
}
43-
}
44-
}
45-
46-
foreach(int i in rIndices.OrderByDescending(x => x))
47-
result.RemoveAt(i);*/
48-
4932
// Remove duplicates and return
5033
return result.Distinct().ToArray();
5134
}
@@ -61,7 +44,7 @@ public static IPv4Network[] CalculateAllowedIPv4s(IPv4Network[] allowed, IPv4Net
6144
IPv4Network last = new(0, 32);
6245

6346
// Treat the entire address space as a continous numeric range (which it is)
64-
// and find the sections which are not inside a disallowed range
47+
// and find the sections which are not inside a disallowed range.
6548
// This can be done sequentially because we sorted the disallowed ranges by ascending address value
6649
foreach(IPv4Network dis in sortedDisallowed)
6750
{

0 commit comments

Comments
 (0)