tgstation-server 6.12.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.Types.Relay;
6
7using Microsoft.Extensions.Options;
8
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 [TgsGraphQLAuthorize]
57 public static SwarmNode? GetSwarmNode(
58 string identifier,
59 [Service] ISwarmService swarmService)
60 {
61 ArgumentNullException.ThrowIfNull(identifier);
62 ArgumentNullException.ThrowIfNull(swarmService);
63 var info = swarmService
64 .GetSwarmServers()
65 ?.FirstOrDefault(x => x.Identifier == identifier);
66
67 if (info == null)
68 return null;
69
70 return new SwarmNode(info);
71 }
72
77 public SwarmNode(SwarmServerInformation? nodeInformation)
78 {
79 ArgumentNullException.ThrowIfNull(nodeInformation);
80
81 Identifier = nodeInformation.Identifier!;
82 Address = nodeInformation.Address!;
83 PublicAddress = nodeInformation.PublicAddress;
84 Controller = nodeInformation.Controller;
85 }
86
93 public IGateway Gateway([Service] IOptionsSnapshot<SwarmConfiguration> swarmConfigurationOptions)
94 {
95 ArgumentNullException.ThrowIfNull(swarmConfigurationOptions);
96
97 bool local = Identifier == swarmConfigurationOptions.Value.Identifier;
98 if (local)
99 return new LocalGateway();
100
101 throw new ErrorMessageException(ErrorCode.RemoteGatewaysNotImplemented);
102
103 // return new RemoteGateway();
104 }
105 }
106}
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:77
IGateway Gateway([Service] IOptionsSnapshot< SwarmConfiguration > swarmConfigurationOptions)
Gets the SwarmNode's IGateway.
Definition SwarmNode.cs:93
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:11
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