ORE Studio 0.0.4
Loading...
Searching...
No Matches
session_data.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_COMMS_SERVICE_SESSION_DATA_HPP
21#define ORES_COMMS_SERVICE_SESSION_DATA_HPP
22
23#include <chrono>
24#include <string>
25#include <cstdint>
26#include <optional>
27#include <boost/uuid/uuid.hpp>
28#include <boost/asio/ip/address.hpp>
29
30namespace ores::comms::service {
31
35enum class session_protocol : std::uint8_t {
39 binary = 0,
40
44 http = 1
45};
46
63struct session_data final {
67 boost::uuids::uuid id;
68
72 boost::uuids::uuid account_id;
73
77 std::chrono::system_clock::time_point start_time;
78
84 std::optional<std::chrono::system_clock::time_point> end_time;
85
89 boost::asio::ip::address client_ip;
90
96 std::string client_identifier;
97
101 std::uint16_t client_version_major = 0;
102
106 std::uint16_t client_version_minor = 0;
107
111 std::uint64_t bytes_sent = 0;
112
116 std::uint64_t bytes_received = 0;
117
123 std::string country_code;
124
129
136 std::string username;
137
141 [[nodiscard]] bool is_active() const {
142 return !end_time.has_value();
143 }
144
150 [[nodiscard]] std::optional<std::chrono::seconds> duration() const {
151 if (!end_time) {
152 return std::nullopt;
153 }
154 return std::chrono::duration_cast<std::chrono::seconds>(
156 }
157};
158
159}
160
161#endif
Main server application for ORE Studio.
Definition application.hpp:30
session_protocol
Protocol used for the session connection.
Definition session_data.hpp:35
@ http
HTTP/REST API with JWT authentication.
@ binary
ORE Studio binary protocol over TCP.
Session data owned by ores.comms for protocol-level session tracking.
Definition session_data.hpp:63
std::optional< std::chrono::seconds > duration() const
Calculates the session duration.
Definition session_data.hpp:150
std::optional< std::chrono::system_clock::time_point > end_time
Timestamp when the session ended (logout or disconnect).
Definition session_data.hpp:84
std::string client_identifier
Client identifier string from handshake.
Definition session_data.hpp:96
std::uint16_t client_version_major
Client protocol version major number.
Definition session_data.hpp:101
std::uint64_t bytes_sent
Total bytes sent to the client during this session.
Definition session_data.hpp:111
boost::asio::ip::address client_ip
Client IP address.
Definition session_data.hpp:89
boost::uuids::uuid account_id
Foreign key referencing the associated account.
Definition session_data.hpp:72
session_protocol protocol
Protocol used for this session (binary or HTTP).
Definition session_data.hpp:128
std::uint16_t client_version_minor
Client protocol version minor number.
Definition session_data.hpp:106
std::string username
Username of the account that owns this session.
Definition session_data.hpp:136
std::uint64_t bytes_received
Total bytes received from the client during this session.
Definition session_data.hpp:116
boost::uuids::uuid id
Unique identifier for this session.
Definition session_data.hpp:67
std::chrono::system_clock::time_point start_time
Timestamp when the session started (login time).
Definition session_data.hpp:77
std::string country_code
ISO 3166-1 alpha-2 country code from geolocation.
Definition session_data.hpp:123
bool is_active() const
Checks if the session is still active.
Definition session_data.hpp:141