From 007da589bff0cc9bb28205bfc6484e83ce21d326 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 14 Jul 2025 00:09:32 +0800 Subject: [PATCH] :recycle: Still don't know what I am doing. But basically the microservices are done. --- DysonNetwork.Drive/Program.cs | 2 +- .../Startup/ServiceCollectionExtensions.cs | 13 +++++++------ DysonNetwork.Drive/appsettings.json | 4 ++-- DysonNetwork.Pass/Program.cs | 1 + .../Startup/KestrelConfiguration.cs | 17 ----------------- .../Startup/ServiceCollectionExtensions.cs | 4 ++-- DysonNetwork.Pass/appsettings.json | 2 +- .../Startup/ServiceCollectionExtensions.cs | 4 ++-- DysonNetwork.Pusher/appsettings.json | 2 +- .../Http}/KestrelConfiguration.cs | 13 +++++++++++-- DysonNetwork.Shared/Proto/GrpcClientHelper.cs | 13 +++++++++---- 11 files changed, 37 insertions(+), 38 deletions(-) delete mode 100644 DysonNetwork.Pass/Startup/KestrelConfiguration.cs rename {DysonNetwork.Drive/Startup => DysonNetwork.Shared/Http}/KestrelConfiguration.cs (60%) diff --git a/DysonNetwork.Drive/Program.cs b/DysonNetwork.Drive/Program.cs index e701c37..480ed64 100644 --- a/DysonNetwork.Drive/Program.cs +++ b/DysonNetwork.Drive/Program.cs @@ -1,7 +1,7 @@ using DysonNetwork.Drive; using DysonNetwork.Drive.Startup; -using DysonNetwork.Pusher.Startup; using DysonNetwork.Shared.Auth; +using DysonNetwork.Shared.Http; using DysonNetwork.Shared.Registry; using Microsoft.EntityFrameworkCore; diff --git a/DysonNetwork.Drive/Startup/ServiceCollectionExtensions.cs b/DysonNetwork.Drive/Startup/ServiceCollectionExtensions.cs index a9b4ae1..fba75d1 100644 --- a/DysonNetwork.Drive/Startup/ServiceCollectionExtensions.cs +++ b/DysonNetwork.Drive/Startup/ServiceCollectionExtensions.cs @@ -34,7 +34,7 @@ public static class ServiceCollectionExtensions options.MaxReceiveMessageSize = 16 * 1024 * 1024; // 16MB options.MaxSendMessageSize = 16 * 1024 * 1024; // 16MB }); - + // Register gRPC reflection for service discovery services.AddGrpc(); @@ -69,7 +69,7 @@ public static class ServiceCollectionExtensions return services; } - + public static IServiceCollection AddAppFlushHandlers(this IServiceCollection services) { services.AddSingleton(); @@ -85,9 +85,10 @@ public static class ServiceCollectionExtensions options.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", - Title = "DysonNetwork.Drive API", - Description = "DysonNetwork Drive Service", - TermsOfService = new Uri("https://example.com/terms"), // Update with actual terms + Title = "Dyson Drive", + Description = + "The file service of the Dyson Network. Mainly handling file storage and sharing. Also provide image processing and media analysis. Powered the Solar Network Drive as well.", + TermsOfService = new Uri("https://solsynth.dev/terms"), // Update with actual terms License = new OpenApiLicense { Name = "APGLv3", // Update with actual license @@ -127,4 +128,4 @@ public static class ServiceCollectionExtensions // Add your business services here return services; } -} +} \ No newline at end of file diff --git a/DysonNetwork.Drive/appsettings.json b/DysonNetwork.Drive/appsettings.json index 721bba8..df61dbb 100644 --- a/DysonNetwork.Drive/appsettings.json +++ b/DysonNetwork.Drive/appsettings.json @@ -9,7 +9,7 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "App": "Host=localhost;Port=5432;Database=dyson_network;Username=postgres;Password=postgres;Include Error Detail=True;Maximum Pool Size=20;Connection Idle Lifetime=60", + "App": "Host=localhost;Port=5432;Database=dyson_drive;Username=postgres;Password=postgres;Include Error Detail=True;Maximum Pool Size=20;Connection Idle Lifetime=60", "FastRetrieve": "localhost:6379", "Etcd": "etcd.orb.local:2379" }, @@ -129,7 +129,7 @@ ], "Service": { "Name": "DysonNetwork.Drive", - "Url": "http://localhost:5216", + "Url": "https://localhost:7092", "ClientCert": "../Certificates/client.crt", "ClientKey": "../Certificates/client.key" } diff --git a/DysonNetwork.Pass/Program.cs b/DysonNetwork.Pass/Program.cs index 2d11e2e..1dfa7d2 100644 --- a/DysonNetwork.Pass/Program.cs +++ b/DysonNetwork.Pass/Program.cs @@ -1,6 +1,7 @@ using DysonNetwork.Pass; using DysonNetwork.Pass.Account; using DysonNetwork.Pass.Startup; +using DysonNetwork.Shared.Http; using DysonNetwork.Shared.Registry; using Microsoft.EntityFrameworkCore; diff --git a/DysonNetwork.Pass/Startup/KestrelConfiguration.cs b/DysonNetwork.Pass/Startup/KestrelConfiguration.cs deleted file mode 100644 index b042534..0000000 --- a/DysonNetwork.Pass/Startup/KestrelConfiguration.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace DysonNetwork.Pass.Startup; - -public static class KestrelConfiguration -{ - public static WebApplicationBuilder ConfigureAppKestrel(this WebApplicationBuilder builder) - { - builder.Host.UseContentRoot(Directory.GetCurrentDirectory()); - builder.WebHost.ConfigureKestrel(options => - { - options.Limits.MaxRequestBodySize = 50 * 1024 * 1024; - options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2); - options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(30); - }); - - return builder; - } -} diff --git a/DysonNetwork.Pass/Startup/ServiceCollectionExtensions.cs b/DysonNetwork.Pass/Startup/ServiceCollectionExtensions.cs index 3f539e9..20c3279 100644 --- a/DysonNetwork.Pass/Startup/ServiceCollectionExtensions.cs +++ b/DysonNetwork.Pass/Startup/ServiceCollectionExtensions.cs @@ -132,8 +132,8 @@ public static class ServiceCollectionExtensions options.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", - Title = "Solar Network API", - Description = "An open-source social network", + Title = "Dyson Pass", + Description = "The authentication service of the Dyson Network. Mainly handling authentication and authorization.", TermsOfService = new Uri("https://solsynth.dev/terms"), License = new OpenApiLicense { diff --git a/DysonNetwork.Pass/appsettings.json b/DysonNetwork.Pass/appsettings.json index 5a0f1e1..8dbd4e6 100644 --- a/DysonNetwork.Pass/appsettings.json +++ b/DysonNetwork.Pass/appsettings.json @@ -80,7 +80,7 @@ ], "Service": { "Name": "DysonNetwork.Pass", - "Url": "http://localhost:5216", + "Url": "https://localhost:7058", "ClientCert": "../Certificates/client.crt", "ClientKey": "../Certificates/client.key" }, diff --git a/DysonNetwork.Pusher/Startup/ServiceCollectionExtensions.cs b/DysonNetwork.Pusher/Startup/ServiceCollectionExtensions.cs index 2148160..1064dbf 100644 --- a/DysonNetwork.Pusher/Startup/ServiceCollectionExtensions.cs +++ b/DysonNetwork.Pusher/Startup/ServiceCollectionExtensions.cs @@ -84,8 +84,8 @@ public static class ServiceCollectionExtensions options.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", - Title = "Solar Network API", - Description = "An open-source social network", + Title = "Dyson Pusher", + Description = "The pusher service of the Dyson Network. Mainly handling emailing, notifications and websockets.", TermsOfService = new Uri("https://solsynth.dev/terms"), License = new OpenApiLicense { diff --git a/DysonNetwork.Pusher/appsettings.json b/DysonNetwork.Pusher/appsettings.json index 2bea1db..59ec98b 100644 --- a/DysonNetwork.Pusher/appsettings.json +++ b/DysonNetwork.Pusher/appsettings.json @@ -36,7 +36,7 @@ ], "Service": { "Name": "DysonNetwork.Pusher", - "Url": "http://localhost:5212", + "Url": "https://localhost:7259", "ClientCert": "../Certificates/client.crt", "ClientKey": "../Certificates/client.key" }, diff --git a/DysonNetwork.Drive/Startup/KestrelConfiguration.cs b/DysonNetwork.Shared/Http/KestrelConfiguration.cs similarity index 60% rename from DysonNetwork.Drive/Startup/KestrelConfiguration.cs rename to DysonNetwork.Shared/Http/KestrelConfiguration.cs index f35e4dd..a023a75 100644 --- a/DysonNetwork.Drive/Startup/KestrelConfiguration.cs +++ b/DysonNetwork.Shared/Http/KestrelConfiguration.cs @@ -1,4 +1,9 @@ -namespace DysonNetwork.Pusher.Startup; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.Extensions.Hosting; + +namespace DysonNetwork.Shared.Http; public static class KestrelConfiguration { @@ -10,8 +15,12 @@ public static class KestrelConfiguration options.Limits.MaxRequestBodySize = 50 * 1024 * 1024; options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2); options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(30); + options.ConfigureEndpointDefaults(endpoints => + { + endpoints.Protocols = HttpProtocols.Http1AndHttp2; + }); }); return builder; } -} +} \ No newline at end of file diff --git a/DysonNetwork.Shared/Proto/GrpcClientHelper.cs b/DysonNetwork.Shared/Proto/GrpcClientHelper.cs index df42e78..49ce2c6 100644 --- a/DysonNetwork.Shared/Proto/GrpcClientHelper.cs +++ b/DysonNetwork.Shared/Proto/GrpcClientHelper.cs @@ -1,3 +1,4 @@ +using System.Net; using Grpc.Net.Client; using System.Security.Cryptography.X509Certificates; using Grpc.Core; @@ -16,11 +17,14 @@ public static class GrpcClientHelper { var handler = new HttpClientHandler(); handler.ClientCertificates.Add( - clientCertPassword is null ? - X509Certificate2.CreateFromPemFile(clientCertPath, clientKeyPath) : - X509Certificate2.CreateFromEncryptedPemFile(clientCertPath, clientCertPassword, clientKeyPath) + clientCertPassword is null + ? X509Certificate2.CreateFromPemFile(clientCertPath, clientKeyPath) + : X509Certificate2.CreateFromEncryptedPemFile(clientCertPath, clientCertPassword, clientKeyPath) ); - return GrpcChannel.ForAddress(url, new GrpcChannelOptions { HttpHandler = handler }).CreateCallInvoker(); + var httpClient = new HttpClient(handler); + httpClient.DefaultRequestVersion = HttpVersion.Version20; + httpClient.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher; + return GrpcChannel.ForAddress(url, new GrpcChannelOptions { HttpClient = httpClient }).CreateCallInvoker(); } private static async Task GetServiceUrlFromEtcd(IEtcdClient etcdClient, string serviceName) @@ -30,6 +34,7 @@ public static class GrpcClientHelper { throw new InvalidOperationException($"Service '{serviceName}' not found in Etcd."); } + return response.Kvs[0].Value.ToStringUtf8(); }