From ec9cca59da24debb56e0d1701d5f2a0e443cc97d Mon Sep 17 00:00:00 2001 From: Rasmus Date: Thu, 28 Nov 2024 14:36:36 +0100 Subject: [PATCH] Duscarded object is now a struct. --- Backend/Handler/IpScanner.cs | 6 +++--- Models/Filtered.db | Bin 12288 -> 0 bytes Models/Handler/DbHandler.cs | 13 +++++++------ Models/Model/Backend/Discarded.cs | 5 +++-- Models/ScannerResume.db | Bin 8192 -> 0 bytes Models/mydb.db | Bin 16384 -> 0 bytes 6 files changed, 13 insertions(+), 11 deletions(-) delete mode 100644 Models/Filtered.db delete mode 100644 Models/ScannerResume.db delete mode 100644 Models/mydb.db diff --git a/Backend/Handler/IpScanner.cs b/Backend/Handler/IpScanner.cs index 90ae450..b175b9c 100644 --- a/Backend/Handler/IpScanner.cs +++ b/Backend/Handler/IpScanner.cs @@ -155,7 +155,7 @@ public class IpScanner if (responseCode != IPStatus.Success) { - _discardedQueue.Enqueue(CreateDiscardedQueueItem(ip.ToString(), (int)responseCode)); + _discardedQueue.Enqueue(CreateDiscardedQueueItem(ip, (int)responseCode)); continue; } @@ -163,7 +163,7 @@ public class IpScanner if (ports is { Item1: 0, Item2: 0 }) { - _discardedQueue.Enqueue(CreateDiscardedQueueItem(ip.ToString(), (int)responseCode)); + _discardedQueue.Enqueue(CreateDiscardedQueueItem(ip, (int)responseCode)); continue; } @@ -203,7 +203,7 @@ public class IpScanner scanSettings.Handle!.Set(); } - private static Discarded CreateDiscardedQueueItem(string ip, int responseCode) + private static Discarded CreateDiscardedQueueItem(Ip ip, int responseCode) { Discarded discarded = new() { diff --git a/Models/Filtered.db b/Models/Filtered.db deleted file mode 100644 index 93bce66fc88ab3425ba107d6a5f3d5009b42d7ad..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeH~(Qeu>6ow5t!_CqSC;?ROPA);S?-|By~(R_5{1z z-eAwP2iUvJ=?VmTqTTEY9ZN|Z|L4cfXXga>KDVR>eiNywr+I_zvqFKrPwhJS_Y; z(cUnC4>Hi8V6?avn_b%yHW$|Wmd&e+<|?o4?o^#ob;ogq{n74nw=KBaZ?%ro_V^@E zIIVKdaZe*(dXp!0BBgWsN~KeL7((g*j7`{AX3&{|-wVd{NH~MUS2ETz3Nc?s#@u}s zU@p^)MfX76ffDl=9pXyGyxnLR=|o%!tiPp*IX`I~UxG?y^IOlVt;y-RKyop!~z?iHBG>|SV--lS+p&yN8IL2mdJp${*YIR)Xr<+k2 zg8z59@<*$ArJC1qQ|)w}3#&We=k}nMzTw>Ji?-vMJaA#VqP|=26w3!kM}@(CzDRBZ zgZVmv+ZlvDY}}UCvd4y43(b@t8)x0@0)D4C=zHaV<{$(MrHl1^x6BCG;#-Q?y36DP z%$t!hcP0l=x_J0#ZdZ~y=R diff --git a/Models/Handler/DbHandler.cs b/Models/Handler/DbHandler.cs index 8705e8e..248b0d7 100644 --- a/Models/Handler/DbHandler.cs +++ b/Models/Handler/DbHandler.cs @@ -19,7 +19,7 @@ public class DbHandler private const string InsertStatement = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = off; INSERT INTO Unfiltered (Ip1, Ip2, Ip3, Ip4, Port1, Port2, Filtered) VALUES (@ip1, @ip2, @ip3, @ip4, @port1, @port2, @filtered)"; private const string InsertIntoFiltered = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = off; INSERT INTO Filtered (Ip1, Ip2, Ip3, Ip4, Port1, Port2, Title1, Title2, Description1, Description2, Url1, Url2, ServerType1, ServerType2, RobotsTXT1, RobotsTXT2, HttpVersion1, HttpVersion2, CertificateIssuerCountry, CertificateOrganizationName, IpV6, TlsVersion, CipherSuite, KeyExchangeAlgorithm, PublicKeyType1, PublicKeyType2, PublicKeyType3, AcceptEncoding1, AcceptEncoding2, ALPN, Connection1, Connection2) VALUES (@ip1, @ip2, @ip3, @ip4, @port1, @port2, @title1, @title2, @description1, @description2, @url1, @url2, @serverType1, @serverType2, @robotsTXT1, @robotsTXT2, @httpVersion1, @httpVersion2, @certificateIssuerCountry, @certificateOrganizationName, @ipV6, @tlsVersion, @cipherSuite, @keyExchangeAlgorithm, @publicKeyType1, @publicKeyType2, @publicKeyType3, @acceptEncoding1, @acceptEncoding2, @aLPN, @connection1, @connection2)"; - private const string InsertIntoDiscarded = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = off; INSERT INTO Discarded (Ip, ResponseCode) VALUES (@ip, @responseCode)"; + private const string InsertIntoDiscarded = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = off; INSERT INTO Discarded (Ip1, Ip2, Ip3, Ip4, ResponseCode) VALUES (@ip1, @ip2, @ip3, @ip4, @responseCode)"; private const string InsertIntoResume = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = off; INSERT INTO Resume (ThreadNumber, StartRange, EndRange, FirstByte, SecondByte, ThirdByte, FourthByte) VALUES (@threadNumber, @startRange, @endRange, @firstByte, @secondByte, @thirdByte, @fourthByte);"; private const string ReadUnfilteredStatement = "SELECT * FROM Unfiltered WHERE Id = @id;"; @@ -156,9 +156,7 @@ public class DbHandler continue; } - _discardedQueue.TryDequeue(out Discarded? queueItem); - - if (queueItem is null) { continue; } + _discardedQueue.TryDequeue(out Discarded queueItem); InsertDiscarded(queueItem, connectionString); } @@ -194,7 +192,10 @@ public class DbHandler using SqliteCommand command = new(InsertIntoDiscarded, connection); - command.Parameters.AddWithValue("@ip", discarded.Ip); + command.Parameters.AddWithValue("@ip1", discarded.Ip.Ip1); + command.Parameters.AddWithValue("@ip2", discarded.Ip.Ip2); + command.Parameters.AddWithValue("@ip3", discarded.Ip.Ip3); + command.Parameters.AddWithValue("@ip4", discarded.Ip.Ip4); command.Parameters.AddWithValue("@responseCode", discarded.ResponseCode); _ = command.ExecuteNonQuery(); @@ -579,7 +580,7 @@ public class DbHandler { string databaseName = $"Data Source={_basePath}/Models/Discarded{threadNumber}.db"; - const string createStatement = "CREATE TABLE IF NOT EXISTS Discarded (Id INTEGER NOT NULL, Ip TEXT NOT NULL, ResponseCode INTEGER NOT NULL, PRIMARY KEY(Id AUTOINCREMENT))"; + const string createStatement = "CREATE TABLE IF NOT EXISTS Discarded (Id INTEGER NOT NULL, Ip1 TEXT NOT NULL, Ip2 TEXT NOT NULL, Ip3 TEXT NOT NULL, Ip4 TEXT NOT NULL, ResponseCode INTEGER NOT NULL, PRIMARY KEY(Id AUTOINCREMENT))"; _discardedConnectionStrings.Add(databaseName); diff --git a/Models/Model/Backend/Discarded.cs b/Models/Model/Backend/Discarded.cs index 8cc16fc..ccaa496 100644 --- a/Models/Model/Backend/Discarded.cs +++ b/Models/Model/Backend/Discarded.cs @@ -1,7 +1,8 @@ namespace Models.Model.Backend; -public class Discarded +public struct Discarded { - public string Ip { get; set; } = ""; + public Ip Ip { get; set; } + public int ResponseCode { get; set; } } \ No newline at end of file diff --git a/Models/ScannerResume.db b/Models/ScannerResume.db deleted file mode 100644 index a44725c94c534967899d2392373bfd3dd9f212b2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8192 zcmeI1K}#D!6oB8%Mzfp5osBsZ6=cY%g(6D-z$UVa5K@zD&UI~86ETTyHiw=XQlUMz z;1AG?=hkCS=^rR1$KLu2gdpT1(zhEIDl~fY^oE_;+3(G~8NNLYQz;c1zAN|IUeodA zD=>gDFr@^5OROAgRF<$4i$3tp{^?KaUc$upm&Vu#7IPgV&--(AQ>&nmB372 z;XH(D1e1sc@a;b2&_meg3XF}os!i4~p_fN;m6?s^DmX|NzhRNj$3lh;GQ5i)C~%ur eCQQTJK{~90hsls*GE;?7imAAhV25TLZvFzJ^MOqO diff --git a/Models/mydb.db b/Models/mydb.db deleted file mode 100644 index ef45e70ffa2d8792f084268584b3c401d3456d4a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI#-A>{_6bJAr7&e$xy=$@w@i z%07&5;j}`9hK6g&f09YtIh~L5oAzRQ*PT(U=m)@vm0 zUJjRYcD?qM?G5Ns4C+bpWcOva?P#Pc;mF2r!!1>;X44p?pwq{(KG6=R>T#yRpDOoQ zUZKqe>!CkUE#0%BKeiXERx|z{rek`uFdj|Rba5@MjKUYq$@XYxN*9^erd)>aotE-j zO|A7dS}*paSnByXNpYk1JKOVgG7$#FLHR3Ee&Ea|w<_XGUqGc?$^THvSsw)g5P$## zAOHafKmY;|fB*y_0D&zOFq51PwlFcI1OW&@00Izz00bZa0SG_<0uX>eCV=yQMu8g$ YKmY;|fB*y_009U<00Izzz}5=90#&xlbpQYW