Skip to content

Commit

Permalink
Merge pull request #95 from argon-chat/feature/grpc
Browse files Browse the repository at this point in the history
Grpc Feature
  • Loading branch information
urumo authored Dec 3, 2024
2 parents 8dc2404 + 7b06676 commit 6bd0e97
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 84 deletions.
14 changes: 7 additions & 7 deletions src/Argon.Api/Argon.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@

<ItemGroup>
<PackageReference Include="Aspire.StackExchange.Redis" Version="9.0.0"/>
<PackageReference Include="Fluid.Core" Version="2.12.0"/>
<PackageReference Include="Fluid.Core" Version="2.14.0"/>
<PackageReference Include="Flurl.Http" Version="4.0.2"/>
<PackageReference Include="Flurl.Http.Newtonsoft" Version="0.9.1"/>
<PackageReference Include="Genbox.SimpleS3.Core" Version="3.2.4"/>
<PackageReference Include="Genbox.SimpleS3.Extensions.GenericS3" Version="3.2.4"/>
<PackageReference Include="Genbox.SimpleS3.Extensions.HttpClient" Version="3.2.4"/>
<PackageReference Include="MemoryPack" Version="1.21.3"/>
<PackageReference Include="Genbox.SimpleS3.Core" Version="3.2.7"/>
<PackageReference Include="Genbox.SimpleS3.Extensions.GenericS3" Version="3.2.7"/>
<PackageReference Include="Genbox.SimpleS3.Extensions.HttpClient" Version="3.2.7"/>
<PackageReference Include="Grpc.AspNetCore" Version="2.67.0"/>
<PackageReference Include="Grpc.AspNetCore.Web" Version="2.67.0"/>
<PackageReference Include="MessagePipe" Version="1.8.1"/>
<PackageReference Include="MessagePipe.Analyzer" Version="1.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10"/>
<PackageReference Include="ActualLab.Fusion" Version="9.5.64"/>
<PackageReference Include="Argon.Sfu.Protocol" Version="1.26.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.10"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
Expand Down Expand Up @@ -59,7 +59,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Argon.Contracts\Argon.Contracts.csproj"/>
<ProjectReference Include="..\Argon.Contracts\Argon.Shared.csproj"/>
<ProjectReference Include="..\ServiceDefaults\ServiceDefaults.csproj"/>
</ItemGroup>

Expand Down
9 changes: 9 additions & 0 deletions src/Argon.Api/Features/Rpc/RpcServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ namespace Argon.Services;

public static class RpcServiceCollectionExtensions
{
public static void MapArgonTransport(this WebApplication app)
{
app.MapGrpcService<ArgonTransport>().EnableGrpcWeb();
app.UseGrpcWeb(new GrpcWebOptions
{
DefaultEnabled = true
});
}

public static void AddArgonTransport(this WebApplicationBuilder builder, Action<ITransportRegistration> onRegistration)
{
var col = builder.Services;
Expand Down
19 changes: 18 additions & 1 deletion src/Argon.Api/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
// Global using directives

global using System.Collections.Concurrent;
global using System.ComponentModel;
global using System.Reflection;
global using System.Runtime.Serialization;
global using System.Security.Cryptography;
global using System.Text;
global using ActualLab.Collections;
global using ActualLab.Text;
global using Argon;
global using Argon.ArchetypeModel;
global using Argon.Entities;
global using Argon.Extensions;
global using Argon.Features;
global using Argon.Grains.Interfaces;
global using Argon.Streaming;
global using Argon.Streaming.Events;
global using Argon.Users;
global using MemoryPack;
global using MessagePack;
global using MessagePack;
global using Microsoft.AspNetCore.Authorization;
global using Microsoft.EntityFrameworkCore;
global using Microsoft.Extensions.Options;
2 changes: 1 addition & 1 deletion src/Argon.Api/GlobalVersion.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Argon.Api;
namespace Argon;

public static class GlobalVersion
{
Expand Down
69 changes: 34 additions & 35 deletions src/Argon.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
using ActualLab.Fusion;
using ActualLab.Rpc;
using ActualLab.Rpc.Server;
using Argon.Api;
using Argon.Api.Entities;
using Argon.Api.Extensions;
using Argon.Api.Features;
using Argon.Api.Features.Captcha;
using Argon.Api.Features.EF;
using Argon.Api.Features.Env;
using Argon.Api.Features.Jwt;
using Argon.Api.Features.MediaStorage;
using Argon.Api.Features.OrleansStreamingProviders;
using Argon.Api.Features.Otp;
using Argon.Api.Features.Pex;
using Argon.Api.Features.Repositories;
using Argon.Api.Features.Template;
using Argon.Api.Grains.Interfaces;
using Argon.Api.Migrations;
using Argon.Api.Services;
using Argon.Api.Services.Fusion;
using Argon.Contracts;
using Argon.Features.Captcha;
using Argon.Features.EF;
using Argon.Features.Env;
using Argon.Features.Jwt;
using Argon.Features.MediaStorage;
using Argon.Features.OrleansStreamingProviders;
using Argon.Features.Otp;
using Argon.Features.Pex;
using Argon.Features.Repositories;
using Argon.Features.Template;
using Argon.Migrations;
using Argon.Services;
using Argon.Sfu;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Converters;

var builder = WebApplication.CreateBuilder(args);

builder.WebHost.ConfigureKestrel(options => {
options.Limits.KeepAliveTimeout = TimeSpan.FromSeconds(400);
options.AddServerHeader = false;
options.Limits.Http2.MaxStreamsPerConnection = 100;
options.Limits.Http2.InitialConnectionWindowSize = 65535;
options.Limits.Http2.KeepAlivePingDelay = TimeSpan.FromSeconds(30);
options.Limits.Http2.KeepAlivePingTimeout = TimeSpan.FromSeconds(10);
});

builder.AddSentry(builder.Configuration.GetConnectionString("Sentry"));
builder.Services.Configure<SmtpConfig>(builder.Configuration.GetSection("Smtp"));
builder.AddServiceDefaults();
builder.AddRedisOutputCache("cache");
builder.AddRedisClient("cache");
builder.AddNatsStreaming();
builder.Services.AddDbContext<ApplicationDbContext>(x => x
.EnableDetailedErrors().EnableSensitiveDataLogging().UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))
.EnableDetailedErrors()
.EnableSensitiveDataLogging()
.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))
.AddInterceptors(new TimeStampAndSoftDeleteInterceptor()));

builder.Services.AddSingleton<IPasswordHashingService, PasswordHashingService>();
Expand All @@ -51,27 +52,26 @@
z.AllowAnyMethod();
});
});
builder.Services.AddFusion(RpcServiceMode.Server, true).Rpc
.AddWebSocketServer(true).Rpc
.AddServer<IUserInteraction, UserInteraction>()
.AddServer<IServerInteraction, ServerInteraction>()
.AddServer<IEventBus, EventBusService>()
.AddServer<IUserPreferenceInteraction, UserPreferenceInteraction>();
builder.AddSwaggerWithAuthHeader();
builder.Services.AddAuthorization();
builder.AddContentDeliveryNetwork();
builder.AddArgonTransport(x =>
{
x.AddService<IServerInteraction, ServerInteraction>();
x.AddService<IUserInteraction, UserInteraction>();
x.AddService<IEventBus, EventBusService>();
});
}

builder.AddContentDeliveryNetwork();
builder.AddArgonPermissions();
builder.AddSelectiveForwardingUnit();
builder.Services.AddTransient<UserManagerService>();
builder.Services.AddSingleton<IFusionContext, FusionContext>();
builder.AddOtpCodes();
builder.AddOrleans();
builder.AddTemplateEngine();
builder.AddEfRepositories();
builder.AddKubeResources();
builder.AddCaptchaFeature();
builder.Services.AddSignalR();
builder.Services.AddDataProtection();
var app = builder.Build();

Expand All @@ -81,11 +81,10 @@
app.UseAuthentication();
app.UseAuthorization();
app.UseWebSockets();
app.MapRpcWebSocketServer();
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
app.MapControllers();
app.MapArgonTransport();
}

app.MapDefaultEndpoints();
Expand Down
30 changes: 15 additions & 15 deletions src/Argon.Contracts/Argon.Shared.csproj
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ActualLab.Core" Version="9.6.2" />
<PackageReference Include="Google.Protobuf" Version="3.29.0" />
<PackageReference Include="Grpc.Core" Version="2.46.6" />
<PackageReference Include="ActualLab.Core" Version="9.6.2"/>
<PackageReference Include="Google.Protobuf" Version="3.29.0"/>
<PackageReference Include="Grpc.Core" Version="2.46.6"/>
<PackageReference Include="Grpc.Tools" Version="2.67.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MessagePack" Version="2.5.192" />
<PackageReference Include="MessagePack" Version="2.5.192"/>
<PackageReference Include="MessagePackAnalyzer" Version="2.5.192">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.10" />
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="8.2.0" />
<PackageReference Include="Microsoft.Orleans.Streaming" Version="8.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Reinforced.Typings" Version="1.6.5" />
<Protobuf Include="Protos\transport.proto" GrpcServices="Server" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.10"/>
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="8.2.0"/>
<PackageReference Include="Microsoft.Orleans.Streaming" Version="8.2.0"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
<PackageReference Include="Reinforced.Typings" Version="1.6.5"/>
<Protobuf Include="Protos\transport.proto" GrpcServices="Server"/>

</ItemGroup>

Expand Down
3 changes: 3 additions & 0 deletions src/Argon.Entry/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Global using directives

global using ActualLab.Serialization;
44 changes: 19 additions & 25 deletions src/Argon.Entry/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
using ActualLab.Fusion;
using ActualLab.Rpc;
using ActualLab.Rpc.Server;
using ActualLab.Serialization;
using Argon.Api;
using Argon.Api.Controllers;
using Argon.Api.Entities;
using Argon.Api.Extensions;
using Argon.Api.Features.Jwt;
using Argon.Api.Features.Pex;
using Argon.Api.Services;
using Argon.Api.Services.Fusion;
using Argon.Contracts;
using Argon;
using Argon.Controllers;
using Argon.Extensions;
using Argon.Features.Jwt;
using Argon.Features.MediaStorage;
using Argon.Services;
using Argon.Streaming;
using Newtonsoft.Json.Converters;
using Orleans.Clustering.Kubernetes;
using Orleans.Configuration;
Expand All @@ -27,12 +21,11 @@
options.Limits.Http2.KeepAlivePingDelay = TimeSpan.FromSeconds(30);
options.Limits.Http2.KeepAlivePingTimeout = TimeSpan.FromSeconds(10);
});

builder.AddArgonPermissions();
builder.AddContentDeliveryNetwork();
builder.AddServiceDefaults();
builder.AddJwt();
builder.Services.AddControllers()
.AddApplicationPart(typeof(AuthorizationController).Assembly)
.AddApplicationPart(typeof(FilesController).Assembly)
.AddNewtonsoftJson(x => x.SerializerSettings.Converters.Add(new StringEnumConverter()));
builder.Services.AddCors(x =>
{
Expand All @@ -43,36 +36,37 @@
z.AllowAnyMethod();
});
});
builder.Services.AddFusion(RpcServiceMode.Server, true)
.Rpc.AddWebSocketServer(true).Rpc
.AddServer<IUserInteraction, UserInteraction>()
.AddServer<IServerInteraction, ServerInteraction>()
.AddServer<IEventBus, EventBusService>()
.AddServer<IUserPreferenceInteraction, UserPreferenceInteraction>();
builder.AddSwaggerWithAuthHeader();
builder.Services.AddSerializer(x => x.AddMessagePackSerializer(null, null, MessagePackByteSerializer.Default.Options))
.AddOrleansClient(x =>
{
x.Configure<ClusterOptions>(builder.Configuration.GetSection("Orleans")).AddStreaming();
x.Configure<ClusterOptions>(builder.Configuration.GetSection("Orleans"))
.AddStreaming()
.AddBroadcastChannel(IArgonEvent.Broadcast);
if (builder.Environment.IsProduction())
x.UseKubeGatewayListProvider();
else
x.UseLocalhostClustering();
});
builder.AddArgonTransport(x =>
{
x.AddService<IServerInteraction, ServerInteraction>();
x.AddService<IUserInteraction, UserInteraction>();
x.AddService<IEventBus, EventBusService>();
});
builder.Services.AddAuthorization();
builder.Services.AddSingleton<IFusionContext, FusionContext>();
var app = builder.Build();

app.UseCors();
app.UseWebSockets();
app.MapRpcWebSocketServer();
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.MapDefaultEndpoints();
app.MapArgonTransport();

app.MapGet("/", () => new
{
Expand Down

0 comments on commit 6bd0e97

Please sign in to comment.