using System.Net; using LumaTunnel.Server.Core.Runtime; using LumaTunnel.Shared.Models; using XFEExtension.NetCore.ServerInteractive.Attributes; using XFEExtension.NetCore.ServerInteractive.Implements.CoreService; namespace LumaTunnel.Server.Core.Services; public partial class NodeStatusService : ServerCoreStandardServiceBase { [EntryPoint("v1/node/status")] public async Task GetStatusAsync() { string? deviceId = Json > "deviceId"; string? deviceToken = Json > "deviceToken"; var runtime = ServerRuntime.Current; if (string.IsNullOrWhiteSpace(deviceId) || string.IsNullOrWhiteSpace(deviceToken) || !runtime.Devices.Validate(deviceId, deviceToken, out var device)) { await CloseWithError("Invalid device credentials.", HttpStatusCode.Unauthorized).ConfigureAwait(false); return; } var deviceTotals = runtime.Traffic.GetDevice(deviceId); await Close(new NodeStatusDto( runtime.Settings.NodeId, runtime.Settings.NodeName, typeof(NodeStatusService).Assembly.GetName().Version?.ToString(3) ?? "0.1.0", DateTimeOffset.UtcNow, runtime.Traffic.ActiveConnections, deviceTotals.ActiveConnections, deviceTotals.UploadBytes + device!.UploadBytes, deviceTotals.DownloadBytes + device.DownloadBytes, runtime.Settings.MaxConnections, ["http-connect", "socks5-connect", "tcp-multiplex", "device-revocation"])).ConfigureAwait(false); } }