43#include <StormByte/crypto/tls/session.hxx>
50#include <StormByte/safe/atomic.hxx>
51#include <StormByte/safe/deque.hxx>
52#include <StormByte/safe/map.hxx>
53#include <StormByte/safe/mutex.hxx>
54#include <StormByte/safe/optional.hxx>
55#include <StormByte/safe/pair.hxx>
56#include <StormByte/safe/pointers.hxx>
57#include <StormByte/safe/string.hxx>
58#include <StormByte/safe/thread.hxx>
59#include <StormByte/safe/vector.hxx>
60#include <StormByte/size.hxx>
107 class TLSConfiguration;
124 namespace RemoteFile {
197 bool Connect(const
Connection::Protocol& protocol,
std::string_view address, const
unsigned short& port) override;
210 bool refresh_validation_time = true) noexcept;
280 std::string_view path,
std::uint16_t maximum_timeout_seconds = 30) noexcept;
290 std::string_view path,
std::uint16_t maximum_timeout_seconds = 30) noexcept;
347 Safe::Shared<const
Detail::TLSConfiguration> m_tls_configuration;
351 using CompletionReason =
Detail::CompletionReason;
356 using Completion =
Detail::Completion;
361 using MountedRemoteFile =
Detail::MountedRemoteFile;
363 static constexpr
Size MAX_REMOTE_FILE_CHANNELS{128};
388 Connection::Protocol m_protocol{Connection::Protocol::IPv4};
389 Safe::String m_bind_address;
390 Safe::Vector<MountedRemoteFile> m_remote_files;
391 Safe::Map<Safe::String, Detail::RemotePlaneRegistration> m_remote_planes;
392 Safe::Shared<Detail::RemoteFile::MountRegistry> m_remote_file_registry;
393 Safe::Mutex m_remote_file_mutex;
394 Safe::Mutex m_completion_mutex;
395 Safe::Deque<Command> m_commands;
396 Safe::Mutex m_command_mutex;
397 Safe::Shared<ServerTelemetry> m_telemetry;
398 Safe::Thread m_discovery_thread;
399 Safe::Atomic<bool> m_discovery_stop{
false};
407 static Server&& StopForMove(Server& other)
noexcept;
416 void MoveStoppedState(Server& other)
noexcept;
421 void AcceptClients() noexcept;
427 bool CreateWakeup() noexcept;
432 void SignalWakeup() noexcept;
437 void CloseWakeup() noexcept;
442 void AcceptOneClient() noexcept;
450 void ProcessSession(const Safe::Shared<Detail::Session>& session,
bool readable,
bool writable) noexcept;
456 void PostCompletion(Completion completion) noexcept;
461 void DrainCompletions() noexcept;
467 void PostCommand(Command command) noexcept;
472 void DrainCommands() noexcept;
478 void DisconnectClientOnLoop(std::string_view uuid) noexcept;
483 void RevokeAllRemoteFiles() noexcept;
491 void ProcessRemotePlane(const Safe::Shared<Detail::RemoteFile::Host>& host,
492 bool readable,
bool writable) noexcept;
500 virtual PacketPointer ProcessClientPacket(std::string_view client_uuid, PacketPointer packet) noexcept = 0;
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Buffer::Bridge)
Forward declaration of a Network-owned peer data plane.
Forward declaration of the remote-file mount registry.
Forward declaration of the listening socket implementation.
Forward declaration of a client parser session.
Caller-owned callback that builds a packet from opcode and payload.
Definition typedefs.hxx:143
Endpoint(DeserializePacketFunction deserialize_packet_function, StormByte::Safe::Shared< Logger::Log > logger) noexcept
Construct with a packet factory and a logger.
Public, validated descriptor for attaching to one remote file channel.
Definition remote_file_mount.hxx:69
Server-wide cumulative telemetry aggregated across all sessions.
Definition server_telemetry.hxx:71
void DisconnectClient(std::string_view uuid) noexcept
Disconnect a client by UUID.
virtual StormByte::Safe::Binary OnDiscoveryQuery(const StormByte::Safe::Binary &query) const noexcept
Decide whether to answer a discovery query.
virtual void OnClientDisconnected(std::string_view uuid) noexcept
Release derived state when an application session is removed.
Connection::Status Status() const noexcept override
Listener / server status.
bool DisableTLS() noexcept
Restore plaintext while the server is stopped.
virtual bool AllowOutgoingOpcode(std::string_view uuid, Transport::Packet::OpcodeType opcode) const noexcept
Admit a response opcode before output transformation.
Server(Server &&other) noexcept
Stop the source before transferring its inactive state.
Safe::Optional< PeerAddress > GetPeerAddress(std::string_view uuid)
Get the remote address for an active client session.
virtual ~Server() noexcept
Destructor (joins threads, disconnects clients).
bool Announce(const Connection::Protocol &protocol, unsigned short discovery_port) noexcept
Start listening for discovery queries on discovery_port.
Server(DeserializePacketFunction deserialize_packet_function, StormByte::Safe::Shared< Logger::Log > logger)
Construct with a packet factory and a logger.
StormByte::Safe::Shared< ServerTelemetry > Telemetry() const noexcept
Shared live telemetry aggregated across this Server's sessions.
RemoteFileMount MountRemoteFileWriter(std::string_view client_uuid, std::string_view path, std::uint16_t maximum_timeout_seconds=30) noexcept
Mount a server-owned file for exclusive writing after application authorization.
RemoteFileMount MountRemoteFileReader(std::string_view client_uuid, std::string_view path, std::uint16_t maximum_timeout_seconds=30) noexcept
Mount a server-owned file for an already authorized client session.
void StopAnnounce() noexcept
Stop the discovery listener.
Server(const Server &other)=delete
Copy constructor (deleted).
virtual bool AllowIncomingOpcode(std::string_view uuid, Transport::Packet::OpcodeType opcode) const noexcept
Admit an application opcode before its pipeline and factory run.
void Disconnect() noexcept override
Stop accept, disconnect clients and close the listener.
bool Connect(const Connection::Protocol &protocol, std::string_view address, const unsigned short &port) override
Bind, listen and start the accept thread.
void DisconnectClientAfterReply(std::string_view uuid) noexcept
Send the current handler's reply, then close and discard pending input.
bool ConfigureTLS(const Crypto::TLS::ServerConfiguration &configuration, bool refresh_validation_time=true) noexcept
Require TLS for new application and remote-file connections.
virtual bool OnClientConnected(std::string_view uuid) noexcept
Admit and initialize a newly registered application session.
Network-owned native wakeup handles, defined out-of-line.
Forward declaration of the packet worker pool.
@ Disconnected
Closed / idle.
Definition status.hxx:55
CommandType
Event-loop action requested by a worker or callback.
Definition server_state.hxx:196
Private native transport implementation.
Network module of the StormByte suite.
Root namespace of the StormByte suite.
Event-loop command and optional target client UUID.
Definition server_state.hxx:209
Numeric IP address and source port of a connected peer.
Definition peer_address.hxx:51
#define STORMBYTE_NETWORK_PUBLIC
Definition visibility.h:51