Unfiltered object is now a struct.
This commit is contained in:
@@ -55,26 +55,29 @@ public class ContentFilter
|
||||
{
|
||||
if (_stop) break;
|
||||
|
||||
Unfiltered? unfiltered = _dbHandler.ReadUnfilteredWithId(i);
|
||||
Unfiltered unfiltered = _dbHandler.ReadUnfilteredWithId(i);
|
||||
|
||||
if (unfiltered is null || unfiltered.Filtered == 1) continue;
|
||||
if (unfiltered.Filtered) continue;
|
||||
|
||||
unfiltered.Filtered = 1;
|
||||
Ip ip = unfiltered.Ip;
|
||||
|
||||
unfiltered.Filtered = true;
|
||||
|
||||
QueueItem superUnfilteredObject = new()
|
||||
{
|
||||
Unfiltered = unfiltered,
|
||||
Operations = Operations.Update
|
||||
Operations = Operations.Update,
|
||||
DbType = DbType.Unfiltered
|
||||
};
|
||||
|
||||
_queue.Enqueue(superUnfilteredObject);
|
||||
|
||||
if (_dbHandler.GetFilteredIp(unfiltered.Ip))
|
||||
if (_dbHandler.FilteredIpExists(unfiltered.Ip))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Filtered filtered = GetSiteData(unfiltered.Ip);
|
||||
Filtered filtered = GetSiteData(ip);
|
||||
|
||||
filtered.Port1 = unfiltered.Port1;
|
||||
filtered.Port2 = unfiltered.Port2;
|
||||
@@ -82,7 +85,8 @@ public class ContentFilter
|
||||
QueueItem superFilteredObject = new()
|
||||
{
|
||||
Filtered = filtered,
|
||||
Operations = Operations.Insert
|
||||
Operations = Operations.Insert,
|
||||
DbType = DbType.Filtered
|
||||
};
|
||||
|
||||
_queue.Enqueue(superFilteredObject);
|
||||
@@ -94,7 +98,7 @@ public class ContentFilter
|
||||
((EventWaitHandle) obj).Set();
|
||||
}
|
||||
|
||||
private Filtered GetSiteData(string ip)
|
||||
private Filtered GetSiteData(Ip ip)
|
||||
{
|
||||
StartProcess(ip, 80);
|
||||
StartProcess(ip, 443);
|
||||
@@ -222,15 +226,15 @@ public class ContentFilter
|
||||
return siteData;
|
||||
}
|
||||
|
||||
private void StartProcess(string ip, int port)
|
||||
private void StartProcess(Ip ip, int port)
|
||||
{
|
||||
string fileName = port == 80 ? _getDomainPort80 : _getDomainPort443;
|
||||
|
||||
//Console.WriteLine($"{ip.Ip1}.{ip.Ip2}.{ip.Ip3}.{ip.Ip4}");
|
||||
Process proc = new();
|
||||
proc.StartInfo = new()
|
||||
{
|
||||
FileName = "/bin/bash",
|
||||
Arguments = $"{fileName} {ip} {_basePath}/Backend/Scripts/{port}Header.txt",
|
||||
Arguments = $"{fileName} {ip.Ip1}.{ip.Ip2}.{ip.Ip3}.{ip.Ip4} {_basePath}/Backend/Scripts/{port}Header.txt",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = false,
|
||||
RedirectStandardError = false,
|
||||
|
||||
@@ -127,16 +127,22 @@ public class IpScanner
|
||||
resumeObject.FourthByte = l;
|
||||
break;
|
||||
}
|
||||
|
||||
string ip = $"{i}.{j}.{k}.{l}";
|
||||
|
||||
|
||||
Ip ip = new()
|
||||
{
|
||||
Ip1 = i,
|
||||
Ip2 = j,
|
||||
Ip3 = k,
|
||||
Ip4 = l
|
||||
};
|
||||
|
||||
IPStatus responseCode = IPStatus.Unknown;
|
||||
|
||||
try
|
||||
{
|
||||
// Sometimes, if the pinger gets a Destination Unreachable Communication administratively prohibited response, the pinger will throw an exception.
|
||||
// https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol?useskin=vector#Control_messages
|
||||
_ = IPAddress.TryParse(ip, out IPAddress? address);
|
||||
_ = IPAddress.TryParse(ip.ToString(), out IPAddress? address);
|
||||
if (address is not null)
|
||||
{
|
||||
responseCode = ping.Send(address, _timeout, buf, null).Status;
|
||||
@@ -149,19 +155,19 @@ public class IpScanner
|
||||
|
||||
if (responseCode != IPStatus.Success)
|
||||
{
|
||||
_discardedQueue.Enqueue(CreateDiscardedQueueItem(ip, (int)responseCode));
|
||||
_discardedQueue.Enqueue(CreateDiscardedQueueItem(ip.ToString(), (int)responseCode));
|
||||
continue;
|
||||
}
|
||||
|
||||
(int, int) ports = TcpClientHelper.CheckPort(ip, 80, 443);
|
||||
(int, int) ports = TcpClientHelper.CheckPort(ip.ToString(), 80, 443);
|
||||
|
||||
if (ports is { Item1: 0, Item2: 0 })
|
||||
{
|
||||
_discardedQueue.Enqueue(CreateDiscardedQueueItem(ip, (int)responseCode));
|
||||
_discardedQueue.Enqueue(CreateDiscardedQueueItem(ip.ToString(), (int)responseCode));
|
||||
continue;
|
||||
}
|
||||
|
||||
_queue.Enqueue(CreateUnfilteredQueueItem(ip, (int)responseCode, ports));
|
||||
_queue.Enqueue(CreateUnfilteredQueueItem(ip, ports));
|
||||
}
|
||||
|
||||
if (_stop)
|
||||
@@ -208,21 +214,21 @@ public class IpScanner
|
||||
return discarded;
|
||||
}
|
||||
|
||||
private static QueueItem CreateUnfilteredQueueItem(string ip, int responseCode, (int, int) ports)
|
||||
private static QueueItem CreateUnfilteredQueueItem(Ip ip, (int, int) ports)
|
||||
{
|
||||
Unfiltered unfiltered = new()
|
||||
{
|
||||
Ip = ip,
|
||||
ResponseCode = responseCode,
|
||||
Port1 = ports.Item1,
|
||||
Port2 = ports.Item2,
|
||||
Filtered = 0
|
||||
Filtered = false
|
||||
};
|
||||
|
||||
QueueItem superUnfilteredObject = new()
|
||||
{
|
||||
Unfiltered = unfiltered,
|
||||
Operations = Operations.Insert
|
||||
Operations = Operations.Insert,
|
||||
DbType = DbType.Unfiltered
|
||||
};
|
||||
|
||||
return superUnfilteredObject;
|
||||
|
||||
@@ -49,9 +49,9 @@ public class ThreadHandler
|
||||
|
||||
private void StartScanner()
|
||||
{
|
||||
Thread.Sleep(10000); // Let the database handler instantiate and warm up first.
|
||||
Thread.Sleep(5000); // Let the database handler instantiate and warm up first.
|
||||
|
||||
WaitHandle[] wait = _ipScanner.Start(4);
|
||||
WaitHandle[] wait = _ipScanner.Start(64);
|
||||
|
||||
WaitHandle.WaitAll(wait);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user