tgstation-server 6.19.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
SwarmNode.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3
4using HotChocolate;
5using HotChocolate.Authorization;
6using HotChocolate.Types.Relay;
7
8using Microsoft.Extensions.Options;
9
15
17{
21 [Node]
22 public sealed class SwarmNode : IServerNode
23 {
27 [ID]
28 public string NodeId => Identifier;
29
33 public string Identifier { get; }
34
38 public Uri Address { get; }
39
43 public Uri? PublicAddress { get; }
44
48 public bool Controller { get; }
49
56 [Authorize]
57 public static SwarmNode? GetSwarmNode(
58 string identifier,
59 [Service] ISwarmService swarmService)
60 {
61 ArgumentNullException.ThrowIfNull(identifier);
62 ArgumentNullException.ThrowIfNull(swarmService);
63
64 var info = swarmService
65 .GetSwarmServers()
66 ?.FirstOrDefault(x => x.Identifier == identifier);
67
68 if (info == null)
69 return null;
70
71 return new SwarmNode(info);
72 }
73
78 public SwarmNode(SwarmServerInformation? nodeInformation)
79 {
80 ArgumentNullException.ThrowIfNull(nodeInformation);
81
82 Identifier = nodeInformation.Identifier!;
83 Address = nodeInformation.Address!;
84 PublicAddress = nodeInformation.PublicAddress;
85 Controller = nodeInformation.Controller;
86 }
87
94 public IGateway Gateway([Service] IOptionsSnapshot<SwarmConfiguration> swarmConfigurationOptions)
95 {
96 ArgumentNullException.ThrowIfNull(swarmConfigurationOptions);
97
98 bool local = Identifier == swarmConfigurationOptions.Value.Identifier;
99 if (local)
100 return new LocalGateway();
101
102 throw new ErrorMessageException(ErrorCode.RemoteGatewaysNotImplemented);
103
104 // return new RemoteGateway();
105 }
106 }
107}
virtual ? Uri PublicAddress
The address the swarm server can be publically accessed.
virtual ? Uri Address
The public address of the server.
string? Identifier
The server's identifier.
Represents information about a running SwarmServer.
bool Controller
If the SwarmServerResponse is the controller.
Exception representing ErrorMessageResponses.
IGateway for the SwarmNode this query is executing on.
Represents a node server in a swarm.
Definition SwarmNode.cs:23
static ? SwarmNode GetSwarmNode(string identifier, [Service] ISwarmService swarmService)
Node resolver for SwarmNodes.
Definition SwarmNode.cs:57
string Identifier
The swarm server ID.
Definition SwarmNode.cs:33
SwarmNode(SwarmServerInformation? nodeInformation)
Initializes a new instance of the SwarmNode class.
Definition SwarmNode.cs:78
IGateway Gateway([Service] IOptionsSnapshot< SwarmConfiguration > swarmConfigurationOptions)
Gets the SwarmNode's IGateway.
Definition SwarmNode.cs:94
Uri Address
The swarm server's internal Uri.
Definition SwarmNode.cs:38
Uri? PublicAddress
The swarm server's optional public address.
Definition SwarmNode.cs:43
Management interface for the parent SwarmNode.
Definition IGateway.cs:13
Represents a tgstation-server installation.
Used for swarm operations. Functions may be no-op based on configuration.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
Definition ErrorCode.cs:12