From 7abe90499739c1649d0561237222c2cdd5714367 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Sun, 5 Jan 2025 15:37:18 +0100 Subject: [PATCH 1/2] Testing search query --- Backend/Handler/IpScanner.cs | 58 +++++++++++------------------- Backend/Handler/ThreadHandler.cs | 4 +-- Backend/Helper/HttpClientHelper.cs | 36 ++++++++++++++++--- frontend/app.vue | 11 ++++-- frontend/nuxt.config.ts | 4 +++ frontend/pages/index.vue | 9 +++-- frontend/pages/searchResult.vue | 8 +++++ 7 files changed, 82 insertions(+), 48 deletions(-) create mode 100644 frontend/pages/searchResult.vue diff --git a/Backend/Handler/IpScanner.cs b/Backend/Handler/IpScanner.cs index 3652ca3..cd4f360 100644 --- a/Backend/Handler/IpScanner.cs +++ b/Backend/Handler/IpScanner.cs @@ -32,7 +32,7 @@ public class IpScanner _discardedQueue = discardedQueue; _unfilteredQueue = unfilteredQueue; _resumeQueue = resumeQueue; - + SetTimeout(64); } @@ -48,24 +48,12 @@ public class IpScanner { threadsAmount = 256 / threads; } - - WaitHandle[] waitHandle1; - WaitHandle[] waitHandle2; - - // This is jank. But it was to get it production ready. - if (threads <= 64) - { - waitHandle1 = new WaitHandle[threads]; - waitHandle2 = new WaitHandle[threads]; - } - else - { - waitHandle1 = new WaitHandle[64]; - waitHandle2 = new WaitHandle[64]; - } + + WaitHandle[] waitHandle = new WaitHandle[64]; int counter = 0; - int counter2 = 0; + + List waitHandles = []; for (int i = 0; i < threads; i++) { @@ -79,32 +67,27 @@ public class IpScanner Handle = handle }; - if (i < 64) + if (counter < 64) { - waitHandle1[counter] = handle; + waitHandle[counter] = handle; counter++; - } - else - { - waitHandle2[counter2] = handle; - counter2++; + + Thread f = new (Scan!); + f.Start(scanSettings); + + Console.WriteLine($"Scanner thread ({i}) started"); + Thread.Sleep(100); + + continue; } - Thread f = new (Scan!); - f.Start(scanSettings); + counter = 0; - Console.WriteLine($"Scanner thread ({i}) started"); - Thread.Sleep(100); + waitHandles.Add(waitHandle); + + waitHandle = new WaitHandle[64]; } - List waitHandles = new(); - - Console.WriteLine("Waithandle 1 count = " + waitHandle1.Length); - Console.WriteLine("Waithandle 2 count = " + waitHandle2.Length); - - waitHandles.Add(waitHandle1); - waitHandles.Add(waitHandle2); - return waitHandles; } @@ -183,7 +166,8 @@ public class IpScanner _ = IPAddress.TryParse(ip.ToString(), out IPAddress? address); if (address is not null) { - responseCode = ping.Send(address, _timeout, buf, null).Status; + responseCode = IPStatus.TimedOut; //ping.Send(address, _timeout, buf, null).Status; + Thread.Sleep(_timeout); } } catch diff --git a/Backend/Handler/ThreadHandler.cs b/Backend/Handler/ThreadHandler.cs index 784c270..4cebb5a 100644 --- a/Backend/Handler/ThreadHandler.cs +++ b/Backend/Handler/ThreadHandler.cs @@ -59,7 +59,7 @@ public class ThreadHandler { Thread.Sleep(5000); // Let the database handler instantiate and warm up first. - List wait = _ipScanner.Start(128); + List wait = _ipScanner.Start(256); for (int i = 0; i < wait.Count; i++) { @@ -101,7 +101,7 @@ public class ThreadHandler private void StartDiscardedDbHandler() { - WaitHandle[] wait = _dbHandler.Start(4); + WaitHandle[] wait = _dbHandler.Start(5); WaitHandle.WaitAll(wait); diff --git a/Backend/Helper/HttpClientHelper.cs b/Backend/Helper/HttpClientHelper.cs index 444c16c..8444b31 100644 --- a/Backend/Helper/HttpClientHelper.cs +++ b/Backend/Helper/HttpClientHelper.cs @@ -18,11 +18,25 @@ public static partial class HttpClientHelper if (port == 80) { - client.BaseAddress = new($"http://{url}"); + try + { + client.BaseAddress = new($"http://{url}"); + } + catch + { + // + } } else { - client.BaseAddress = new($"https://{url}"); + try + { + client.BaseAddress = new($"https://{url}"); + } + catch + { + // + } } client.DefaultRequestHeaders.Accept.Clear(); @@ -87,11 +101,25 @@ public static partial class HttpClientHelper if (port == 80) { - client.BaseAddress = new($"http://{url}"); + try + { + client.BaseAddress = new($"http://{url}"); + } + catch + { + // + } } else { - client.BaseAddress = new($"https://{url}"); + try + { + client.BaseAddress = new($"https://{url}"); + } + catch + { + // + } } client.DefaultRequestHeaders.Accept.Clear(); diff --git a/frontend/app.vue b/frontend/app.vue index bd800ae..7d22476 100644 --- a/frontend/app.vue +++ b/frontend/app.vue @@ -9,8 +9,15 @@ useHead({ \ No newline at end of file diff --git a/frontend/nuxt.config.ts b/frontend/nuxt.config.ts index bf16940..a4824e3 100644 --- a/frontend/nuxt.config.ts +++ b/frontend/nuxt.config.ts @@ -13,5 +13,9 @@ export default defineNuxtConfig({ }, }, + nitro: { + static: true, + }, + modules: ['@nuxtjs/tailwindcss', 'nuxt-purgecss'], }); \ No newline at end of file diff --git a/frontend/pages/index.vue b/frontend/pages/index.vue index 1a91f55..0f0eb0b 100644 --- a/frontend/pages/index.vue +++ b/frontend/pages/index.vue @@ -1,12 +1,15 @@ + diff --git a/frontend/pages/searchResult.vue b/frontend/pages/searchResult.vue new file mode 100644 index 0000000..a3adcbb --- /dev/null +++ b/frontend/pages/searchResult.vue @@ -0,0 +1,8 @@ + + + \ No newline at end of file From 41dfb5809a9f5b27c394124fc9a53fd102a87d52 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Thu, 16 Jan 2025 11:10:43 +0100 Subject: [PATCH 2/2] Add stuff --- Proxy/Program.cs | 4 +-- frontend/app.vue | 5 +--- frontend/pages/progress.vue | 60 +++++++++++++++++++++++++++---------- frontend/types/global.d.ts | 14 +++++++-- 4 files changed, 59 insertions(+), 24 deletions(-) diff --git a/Proxy/Program.cs b/Proxy/Program.cs index e78d714..8bf0147 100644 --- a/Proxy/Program.cs +++ b/Proxy/Program.cs @@ -60,7 +60,7 @@ progressApi.MapGet("/", (IMemoryCache memoryCache) => return scanningStatus; }); -/* + RouteGroupBuilder searchApi = app.MapGroup("/search"); searchApi.MapGet("/{term}", (string term) => { @@ -78,7 +78,7 @@ searchApi.MapGet("/{term}", (string term) => return JsonSerializer.Deserialize(msg); }); -*/ + app.Run(); [JsonSerializable(typeof(ScanningStatus))] diff --git a/frontend/app.vue b/frontend/app.vue index 7d22476..8c74edf 100644 --- a/frontend/app.vue +++ b/frontend/app.vue @@ -16,8 +16,5 @@ useHead({ - - - - + \ No newline at end of file diff --git a/frontend/pages/progress.vue b/frontend/pages/progress.vue index 4777cb4..5b7acd6 100644 --- a/frontend/pages/progress.vue +++ b/frontend/pages/progress.vue @@ -39,23 +39,51 @@ fetchMyData(); diff --git a/frontend/types/global.d.ts b/frontend/types/global.d.ts index e3e1453..9ae112f 100644 --- a/frontend/types/global.d.ts +++ b/frontend/types/global.d.ts @@ -6,12 +6,22 @@ interface ProgressType { discardedDbSize: bigint; filteredDbSize: bigint; myDbSize: bigint; -} +}; interface ProgressDictionary { description: string; value: string; -} +}; + +interface SearchResult { + title: string; + description: string; + url: string; +}; + +interface SearchResults { + results: SearchResult[]; +}; type CacheEntry = { data: T;