GatewayOffload: rename to Offload

This commit is contained in:
Rory&
2026-03-19 08:38:20 +01:00
parent b839c0a2c4
commit d0eac0b8e7
22 changed files with 147 additions and 119 deletions
@@ -0,0 +1,5 @@
{
"dev": {
"AccessToken": "eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEwMDY1OTgyMzAxNTYzNDEyNzYiLCJpYXQiOjE3NjU4NjYxNDcsImtpZCI6IjVkZTcwNjZlNWQ5YTkxZDc4NGQ2NTY1Njc2Zjc0ZGY4NGQyMDllNzBjY2M3ZmZmNmFhNjgxNTkwODEwMWRjMWEiLCJ2ZXIiOjMsImRpZCI6IklCWkFSR01YT0UifQ.ALoB-4LXPaHTiUWRSoO3KIIc7CX2tP2vdebxmt10h3DqqBW57Zqx9zNImGxn0tV4cqFB1nZct3cZjJ_XVchtUF61AEgGR54QpV2sHAss2NMqZA_S3WK7UigFJYDddWUt2D_GrvzUYUVJ_WB4gt-tXekKzB2K6dazTEFYPFSY6xINBWed"
}
}
-2
View File
@@ -8,7 +8,6 @@ using Spacebar.ConfigModel.Extensions;
using Spacebar.Interop.Authentication;
using Spacebar.Interop.Authentication.AspNetCore;
using Spacebar.Models.Db.Contexts;
using Spacebar.Models.Generic.Constants;
using Spacebar.UApi.Services;
var builder = WebApplication.CreateBuilder(args);
@@ -114,7 +113,6 @@ app.Map("/", async context => {
foreach (var header in responseMessage.Headers) context.Response.Headers[header.Key] = header.Value.ToArray();
foreach (var header in responseMessage.Content.Headers) context.Response.Headers[header.Key] = header.Value.ToArray();
context.Response.Headers["X-SB-UApi-Status"] = "MISSING";
// await responseMessage.Content.CopyToAsync(context.Response.Body);
var txt = await responseMessage.Content.ReadAsStringAsync();
+1 -1
View File
@@ -36,6 +36,6 @@
</Folder>
<Project Path="Spacebar.AdminApi/Spacebar.AdminApi.csproj" />
<Project Path="Spacebar.Cdn/Spacebar.Cdn.csproj" />
<Project Path="Spacebar.GatewayOffload/Spacebar.GatewayOffload.csproj" />
<Project Path="Spacebar.Offload/Spacebar.Offload.csproj" />
<Project Path="Spacebar.UApi/Spacebar.UApi.csproj" />
</Solution>
+14 -14
View File
@@ -203,11 +203,11 @@ flake-utils.lib.eachSystem flake-utils.lib.allSystems (
proj.Spacebar-Interop-Cdn-Abstractions
];
};
Spacebar-GatewayOffload = makeNupkg {
name = "Spacebar.GatewayOffload";
nugetDeps = Spacebar.GatewayOffload/deps.json;
projectFile = "Spacebar.GatewayOffload.csproj";
srcRoot = ./Spacebar.GatewayOffload;
Spacebar-Offload = makeNupkg {
name = "Spacebar.Offload";
nugetDeps = Spacebar.Offload/deps.json;
projectFile = "Spacebar.Offload.csproj";
srcRoot = ./Spacebar.Offload;
packNupkg = false;
projectReferences = [
proj.Spacebar-DataMappings-Generic
@@ -258,30 +258,30 @@ flake-utils.lib.eachSystem flake-utils.lib.allSystems (
Expose = [ "5000" ];
};
};
containers.docker.gateway-offload = pkgs.dockerTools.buildLayeredImage {
name = "spacebar-server-ts-gateway-offload";
tag = builtins.replaceStrings [ "+" ] [ "_" ] self.packages.${system}.Spacebar-AdminApi.version;
containers.docker.offload = pkgs.dockerTools.buildLayeredImage {
name = "spacebar-server-ts-offload";
tag = builtins.replaceStrings [ "+" ] [ "_" ] self.packages.${system}.Spacebar-Offload.version;
contents = [ self.packages.${system}.Spacebar-AdminApi ];
config = {
Cmd = [ "${lib.getExe self.outputs.packages.${system}.Spacebar-GatewayOffload}" ];
Cmd = [ "${lib.getExe self.outputs.packages.${system}.Spacebar-Offload}" ];
Expose = [ "5000" ];
};
};
containers.docker.cdn-cs = pkgs.dockerTools.buildLayeredImage {
name = "spacebar-server-ts-cdn-cs";
tag = builtins.replaceStrings [ "+" ] [ "_" ] self.packages.${system}.Spacebar-AdminApi.version;
tag = builtins.replaceStrings [ "+" ] [ "_" ] self.packages.${system}.Spacebar-Cdn.version;
contents = [ self.packages.${system}.Spacebar-AdminApi ];
config = {
Cmd = [ "${lib.getExe self.outputs.packages.${system}.Spacebar-AdminApi}" ];
Cmd = [ "${lib.getExe self.outputs.packages.${system}.Spacebar-Cdn}" ];
Expose = [ "5000" ];
};
};
containers.docker.uapi = pkgs.dockerTools.buildLayeredImage {
name = "spacebar-server-ts-cdn-cs";
tag = builtins.replaceStrings [ "+" ] [ "_" ] self.packages.${system}.Spacebar-AdminApi.version;
tag = builtins.replaceStrings [ "+" ] [ "_" ] self.packages.${system}.Spacebar-UApi.version;
contents = [ self.packages.${system}.Spacebar-AdminApi ];
config = {
Cmd = [ "${lib.getExe self.outputs.packages.${system}.Spacebar-AdminApi}" ];
Cmd = [ "${lib.getExe self.outputs.packages.${system}.Spacebar-UApi}" ];
Expose = [ "5000" ];
};
};
@@ -295,7 +295,7 @@ flake-utils.lib.eachSystem flake-utils.lib.allSystems (
in
pkgs.lib.recursiveUpdate (pkgs.lib.attrsets.unionOfDisjoint { } self.packages) {
x86_64-linux = {
# spacebar-server-tests = self.packages.x86_64-linux.default.passthru.tests;
# spacebar-server-tests = self.packages.x86_64-linux.default.passthru.tests;
docker-admin-api = self.containers.x86_64-linux.docker.admin-api;
docker-gateway-offload = self.containers.x86_64-linux.docker.gateway-offload;
docker-cdn-cs = self.containers.x86_64-linux.docker.cdn-cs;
@@ -1,89 +0,0 @@
self:
{
config,
lib,
pkgs,
spacebar,
...
}:
let
secrets = import ../secrets.nix { inherit lib config; };
cfg = config.services.spacebarchat-server;
jsonFormat = pkgs.formats.json { };
in
{
imports = [ ];
options.services.spacebarchat-server.gatewayOffload = lib.mkOption {
default = { };
description = "Configuration for C# gateway offload daemon.";
type = lib.types.submodule {
options = {
enable = lib.mkEnableOption "Enable gateway offload daemon (C#).";
listenPort = lib.mkOption {
type = lib.types.port;
default = 3011;
description = "Port for the gateway offload daemon to listen on.";
};
extraConfiguration = lib.mkOption {
type = jsonFormat.type;
default = import ./default-appsettings-json.nix;
description = "Extra appsettings.json configuration for the gateway offload daemon.";
};
enableIdentify = lib.mkEnableOption "Enable offloading gateway opcode 2 (IDENTIFY).";
enableGuildMembers = lib.mkEnableOption "Enable offloading gateway opcode 8 (REQUEST_GUILD_MEMBERS).";
enableGuildSync = lib.mkEnableOption "Enable offloading gateway opcode 12 (GUILD_SYNC).";
enableLazyRequest = lib.mkEnableOption "Enable offloading gateway opcode 14 (LAZY_REQUEST).";
enableChannelStatuses = lib.mkEnableOption "Enable offloading gateway opcode 36 (CHANNEL_STATUSES).";
enableChannelInfo = lib.mkEnableOption "Enable offloading gateway opcode 43 (CHANNEL_INFO).";
};
};
};
config = lib.mkIf cfg.gatewayOffload.enable (
let
makeServerTsService = import ../makeServerTsService.nix { inherit cfg lib secrets; };
in
{
assertions = [
(import ./assert-has-connection-string.nix "Gateway Offload" cfg.gatewayOffload.extraConfiguration)
];
services.spacebarchat-server.settings.offload = {
gateway = {
identifyUrl = lib.mkIf cfg.gatewayOffload.enableIdentify "http://127.0.0.1:${builtins.toString cfg.gatewayOffload.listenPort}/_spacebar/offload/gateway/Identify";
guildMembersUrl = lib.mkIf cfg.gatewayOffload.enableGuildMembers "http://127.0.0.1:${builtins.toString cfg.gatewayOffload.listenPort}/_spacebar/offload/gateway/GuildMembers";
guildSyncUrlUrl = lib.mkIf cfg.gatewayOffload.enableGuildSync "http://127.0.0.1:${builtins.toString cfg.gatewayOffload.listenPort}/_spacebar/offload/gateway/GuildSync";
lazyRequestUrl = lib.mkIf cfg.gatewayOffload.enableLazyRequest "http://127.0.0.1:${builtins.toString cfg.gatewayOffload.listenPort}/_spacebar/offload/gateway/LazyRequest";
channelStatusesUrl = lib.mkIf cfg.gatewayOffload.enableChannelStatuses "http://127.0.0.1:${builtins.toString cfg.gatewayOffload.listenPort}/_spacebar/offload/gateway/ChannelStatuses";
channelInfoUrl = lib.mkIf cfg.gatewayOffload.enableChannelInfo "http://127.0.0.1:${builtins.toString cfg.gatewayOffload.listenPort}/_spacebar/offload/gateway/ChannelInfo";
};
};
systemd.services.spacebar-cs-gateway-offload = makeServerTsService {
description = "Spacebar Server - C# Gateway offload";
environment = builtins.mapAttrs (_: val: builtins.toString val) (
{
# things we set by default...
EVENT_TRANSMISSION = "unix";
EVENT_SOCKET_PATH = "/run/spacebar/";
}
// cfg.extraEnvironment
// {
# things we force...
# CONFIG_PATH = configFile;
CONFIG_READONLY = 1;
ASPNETCORE_URLS = "http://0.0.0.0:${toString cfg.gatewayOffload.listenPort}";
STORAGE_LOCATION = cfg.cdnPath;
APPSETTINGS_PATH = jsonFormat.generate "appsettings.spacebar-gateway-offload.json" (
lib.recursiveUpdate (import ./default-appsettings-json.nix) cfg.gatewayOffload.extraConfiguration
);
}
);
serviceConfig = {
ExecStart = "${self.packages.${pkgs.stdenv.hostPlatform.system}.Spacebar-GatewayOffload}/bin/Spacebar.GatewayOffload";
};
};
}
);
}
+97
View File
@@ -0,0 +1,97 @@
self:
{
config,
lib,
pkgs,
spacebar,
...
}:
let
secrets = import ../secrets.nix { inherit lib config; };
cfg = config.services.spacebarchat-server;
offloadCfg = cfg.offload;
jsonFormat = pkgs.formats.json { };
in
{
imports = [ ];
options.services.spacebarchat-server.offload = lib.mkOption {
default = { };
description = "Configuration for C# offload daemon.";
type = lib.types.submodule {
options = {
enable = lib.mkEnableOption "Enable offload daemon (C#).";
listenPort = lib.mkOption {
type = lib.types.port;
default = 3011;
description = "Port for the offload daemon to listen on.";
};
extraConfiguration = lib.mkOption {
type = jsonFormat.type;
default = import ./default-appsettings-json.nix;
description = "Extra appsettings.json configuration for the offload daemon.";
};
gateway = lib.mkOption {
description = "Gateway offloads";
type = lib.types.submodule {
options = {
enableIdentify = lib.mkEnableOption "Enable offloading gateway opcode 2 (IDENTIFY).";
enableGuildMembers = lib.mkEnableOption "Enable offloading gateway opcode 8 (REQUEST_GUILD_MEMBERS).";
enableGuildSync = lib.mkEnableOption "Enable offloading gateway opcode 12 (GUILD_SYNC).";
enableLazyRequest = lib.mkEnableOption "Enable offloading gateway opcode 14 (LAZY_REQUEST).";
enableChannelStatuses = lib.mkEnableOption "Enable offloading gateway opcode 36 (CHANNEL_STATUSES).";
enableChannelInfo = lib.mkEnableOption "Enable offloading gateway opcode 43 (CHANNEL_INFO).";
};
};
};
};
};
};
config = lib.mkIf offloadCfg.enable (
let
makeServerTsService = import ../makeServerTsService.nix { inherit cfg lib secrets; };
in
{
assertions = [
(import ./assert-has-connection-string.nix "Gateway Offload" offloadCfg.extraConfiguration)
];
services.spacebarchat-server.settings.offload = {
gateway = {
identifyUrl = lib.mkIf offloadCfg.gateway.enableIdentify "http://127.0.0.1:${builtins.toString offloadCfg.listenPort}/_spacebar/offload/gateway/Identify";
guildMembersUrl = lib.mkIf offloadCfg.gateway.enableGuildMembers "http://127.0.0.1:${builtins.toString offloadCfg.listenPort}/_spacebar/offload/gateway/GuildMembers";
guildSyncUrlUrl = lib.mkIf offloadCfg.gateway.enableGuildSync "http://127.0.0.1:${builtins.toString offloadCfg.listenPort}/_spacebar/offload/gateway/GuildSync";
lazyRequestUrl = lib.mkIf offloadCfg.gateway.enableLazyRequest "http://127.0.0.1:${builtins.toString offloadCfg.listenPort}/_spacebar/offload/gateway/LazyRequest";
channelStatusesUrl = lib.mkIf offloadCfg.gateway.enableChannelStatuses "http://127.0.0.1:${builtins.toString offloadCfg.listenPort}/_spacebar/offload/gateway/ChannelStatuses";
channelInfoUrl = lib.mkIf offloadCfg.gateway.enableChannelInfo "http://127.0.0.1:${builtins.toString offloadCfg.listenPort}/_spacebar/offload/gateway/ChannelInfo";
};
};
systemd.services.spacebar-cs-offload = makeServerTsService {
description = "Spacebar Server - C# offload";
environment = builtins.mapAttrs (_: val: builtins.toString val) (
{
# things we set by default...
EVENT_TRANSMISSION = "unix";
EVENT_SOCKET_PATH = "/run/spacebar/";
}
// cfg.extraEnvironment
// {
# things we force...
# CONFIG_PATH = configFile;
CONFIG_READONLY = 1;
ASPNETCORE_URLS = "http://0.0.0.0:${toString offloadCfg.listenPort}";
STORAGE_LOCATION = cfg.cdnPath;
APPSETTINGS_PATH = jsonFormat.generate "appsettings.spacebar-offload.json" (
lib.recursiveUpdate (import ./default-appsettings-json.nix) offloadCfg.extraConfiguration
);
}
);
serviceConfig = {
ExecStart = "${lib.getExe self.packages.${pkgs.stdenv.hostPlatform.system}.Spacebar-Offload}";
};
};
}
);
}
+1 -1
View File
@@ -20,7 +20,7 @@ in
(import ./gw-sharding.nix self)
(import ./pion-sfu.nix self)
(import ./cs/cdn-cs.nix self)
(import ./cs/gateway-offload-cs.nix self)
(import ./cs/offload-cs.nix self)
(import ./cs/admin-api.nix self)
(import ./cs/uapi.nix self)
];
+25 -10
View File
@@ -31,7 +31,7 @@ in
enable = true;
apiEndpoint = sbLib.mkEndpointRaw "api.sb.localhost" 3001 8080 false;
gatewayEndpoint = sbLib.mkEndpointRaw "gw.sb.localhost" 3002 8080 false;
extraGatewayPorts = lib.range 3100 3116;
extraGatewayPorts = lib.range 3100 3103; # 4 gateways total
cdnEndpoint = sbLib.mkEndpointRaw "cdn.sb.localhost" 3003 8080 false;
adminApiEndpoint = sbLib.mkEndpointRaw "admin.sb.localhost" 3004 8080 false;
webrtcEndpoint = sbLib.mkEndpointRaw "voice.sb.localhost" 3005 8080 false;
@@ -45,16 +45,24 @@ in
cdnSignatureIncludeUserAgent = false;
cdnSignatureKey = "meow";
};
limits = {
absoluteRate = {
register.enabled = false;
sendMessage.enabled = false;
};
};
};
gatewayOffload = {
offload = {
enable = true;
enableIdentify = true;
enableGuildMembers = true;
enableGuildSync = true;
enableLazyRequest = true;
enableChannelStatuses = true;
enableChannelInfo = true;
gateway = {
enableIdentify = true;
enableGuildMembers = true;
enableGuildSync = true;
enableLazyRequest = true;
enableChannelStatuses = true;
enableChannelInfo = true;
};
extraConfiguration.ConnectionStrings.Spacebar = csConnectionString;
};
@@ -62,7 +70,7 @@ in
enable = true;
extraConfiguration.ConnectionStrings.Spacebar = csConnectionString;
};
cdnCs = {
enable = false;
extraConfiguration.ConnectionStrings.Spacebar = csConnectionString;
@@ -80,7 +88,7 @@ in
extraEnvironment = {
DATABASE = "postgres://postgres:postgres@127.0.0.1/spacebar";
# LOG_REQUESTS = "-200,204,304";
# LOG_REQUESTS = "-200,204,304";
LOG_REQUESTS = "-";
LOG_VALIDATION_ERRORS = true;
#DB_LOGGING=true;
@@ -93,6 +101,13 @@ in
in
lib.trace ("Testing with config: " + builtins.toJSON cfg) cfg;
services.nginx.enable = true;
services.nginx.recommendedOptimisation = true;
services.nginx.appendConfig = ''
worker_processes 6;
'';
services.nginx.eventsConfig = ''
worker_connections 512;
'';
users.users.root.initialPassword = "root";
services.getty.autologinUser = "root";
+4 -2
View File
@@ -30,9 +30,11 @@ in
};
nginx.enable = true;
gatewayOffload = {
offload = {
enable = true;
enableGuildSync = true;
gateway = {
enableGuildSync = true;
};
extraConfiguration.ConnectionStrings.Spacebar = "Host=127.0.0.1; Username=Spacebar; Password=postgres; Database=spacebar; Port=5432; Include Error Detail=true; Maximum Pool Size=1000; Command Timeout=6000; Timeout=600;";
};
};