♻️ Still don't know what I am doing. But basically the microservices are done.

This commit is contained in:
2025-07-14 00:09:32 +08:00
parent cde55eb237
commit 007da589bf
11 changed files with 37 additions and 38 deletions

View File

@ -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;

View File

@ -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<FlushBufferService>();
@ -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;
}
}
}

View File

@ -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"
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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
{

View File

@ -80,7 +80,7 @@
],
"Service": {
"Name": "DysonNetwork.Pass",
"Url": "http://localhost:5216",
"Url": "https://localhost:7058",
"ClientCert": "../Certificates/client.crt",
"ClientKey": "../Certificates/client.key"
},

View File

@ -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
{

View File

@ -36,7 +36,7 @@
],
"Service": {
"Name": "DysonNetwork.Pusher",
"Url": "http://localhost:5212",
"Url": "https://localhost:7259",
"ClientCert": "../Certificates/client.crt",
"ClientKey": "../Certificates/client.key"
},

View File

@ -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;
}
}
}

View File

@ -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<string> 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();
}