ORE Studio 0.0.4
Loading...
Searching...
No Matches
message_types.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_MESSAGING_MESSAGE_TYPES_HPP
21#define ORES_COMMS_MESSAGING_MESSAGE_TYPES_HPP
22
23#include <ostream>
24#include <cstdint>
25
26// Configure magic_enum to support our enum value ranges
27#define MAGIC_ENUM_RANGE_MIN 0
28#define MAGIC_ENUM_RANGE_MAX 0x4000
29
30#include <magic_enum/magic_enum.hpp>
31
32namespace ores::comms::messaging {
33
34 // "ORES" in ASCII
35constexpr std::uint32_t PROTOCOL_MAGIC = 0x4F524553;
36
37// Protocol version 7 adds correlation_id field to frame header for
38// request/response matching, enabling concurrent operations and server-push
39// notifications.
40//
41// Version 7.1 adds subscription protocol messages (subscribe_request,
42// subscribe_response, unsubscribe_request, unsubscribe_response, notification)
43// for server-push event notifications.
44//
45// Version 7.2 changes logout_request to have empty payload. Account ID is now
46// determined from session context to prevent clients from forging logout
47// requests for other users.
48//
49// Version 7.3 adds database_status_notification message for server-push
50// database health status updates, and database_unavailable error code.
51// Version 8.0 removes requester_account_id from lock_account_request and
52// unlock_account_request. Authorization is now handled via server-side session
53// tracking instead of client-provided identity. This is a breaking change.
54//
55// Version 9.0 adds optional payload compression support. The reserved1 field
56// in the frame header is now used for compression_type (1 byte) and flags
57// (1 byte). Supported compression algorithms: none, zlib, gzip, bzip2.
58// Uncompressed payloads remain fully supported (compression_type::none).
59//
60// Version 10.0 replaces valid_from/valid_to fields with recorded_by/recorded_at
61// in domain types (currency, account, feature_flags). This is a breaking change
62// affecting all entity serialization in the protocol.
63//
64// Version 10.1 adds update_account_request and update_account_response messages
65// for editing existing account email and admin status.
66//
67// Version 11.0 changes lock_account_request and unlock_account_request to support
68// batch operations with a vector of account IDs. Responses now return a vector of
69// per-account results (lock_account_result/unlock_account_result). This is a
70// breaking change as the wire format is incompatible with previous versions.
71//
72// Version 12.0 adds reset_password_request and reset_password_response messages
73// for admin-initiated password reset. Adds password_reset_required field to
74// login_response and list_login_info_response. This is a breaking change as
75// existing serialization formats are extended with new fields.
76//
77// Version 13.0 adds role-based access control (RBAC) with full authorization
78// system. New domain types: permission, role, account_role, role_permission.
79// New RBAC messages: list_roles_request/response, list_permissions_request/response,
80// assign_role_request/response, revoke_role_request/response,
81// get_account_roles_request/response, get_account_permissions_request/response.
82// Adds authorization checks to all protected endpoints. This is a breaking change
83// as it introduces mandatory RBAC enforcement for administrative operations.
84constexpr std::uint16_t PROTOCOL_VERSION_MAJOR = 13;
85constexpr std::uint16_t PROTOCOL_VERSION_MINOR = 0;
86
87// Subsystem message type ranges
88constexpr std::uint16_t CORE_SUBSYSTEM_MIN = 0x0000;
89constexpr std::uint16_t CORE_SUBSYSTEM_MAX = 0x0FFF;
90constexpr std::uint16_t RISK_SUBSYSTEM_MIN = 0x1000;
91constexpr std::uint16_t RISK_SUBSYSTEM_MAX = 0x1FFF;
92constexpr std::uint16_t ACCOUNTS_SUBSYSTEM_MIN = 0x2000;
93constexpr std::uint16_t ACCOUNTS_SUBSYSTEM_MAX = 0x2FFF;
94constexpr std::uint16_t VARIABILITY_SUBSYSTEM_MIN = 0x3000;
95constexpr std::uint16_t VARIABILITY_SUBSYSTEM_MAX = 0x3FFF;
96
104enum class compression_type : std::uint8_t {
105 none = 0x00, // No compression (default)
106 zlib = 0x01, // zlib/deflate compression
107 gzip = 0x02, // gzip compression
108 bzip2 = 0x03 // bzip2 compression
109};
110
111enum class message_type {
112 // Core protocol messages (0x0000 - 0x0FFF)
113 handshake_request = 0x0001,
114 handshake_response = 0x0002,
115 handshake_ack = 0x0003,
116 error_response = 0x0004,
117 ping = 0x0005,
118 pong = 0x0006,
119
120 // Subscription/Notification messages (0x0010 - 0x001F)
121 subscribe_request = 0x0010,
122 subscribe_response = 0x0011,
123 unsubscribe_request = 0x0012,
124 unsubscribe_response = 0x0013,
125 notification = 0x0014,
126
127 // System status notifications (0x0020 - 0x002F)
128 database_status_notification = 0x0020,
129
130 // Risk subsystem messages (0x1000 - 0x1FFF)
131 get_currencies_request = 0x1001,
132 get_currencies_response = 0x1002,
133 save_currency_request = 0x1003,
134 save_currency_response = 0x1004,
135 delete_currency_request = 0x1005,
136 delete_currency_response = 0x1006,
137 get_currency_history_request = 0x1007,
138 get_currency_history_response = 0x1008,
139
140 // Accounts subsystem messages (0x2000 - 0x2FFF)
141 create_account_request = 0x2001,
142 create_account_response = 0x2002,
143 list_accounts_request = 0x2003,
144 list_accounts_response = 0x2004,
145 login_request = 0x2005,
146 login_response = 0x2006,
147 unlock_account_request = 0x2007,
148 unlock_account_response = 0x2008,
149 delete_account_request = 0x2009,
150 delete_account_response = 0x200A,
151 list_login_info_request = 0x200B,
152 list_login_info_response = 0x200C,
153 logout_request = 0x200D,
154 logout_response = 0x200E,
155 create_initial_admin_request = 0x200F,
156 create_initial_admin_response = 0x2010,
157 bootstrap_status_request = 0x2011,
158 bootstrap_status_response = 0x2012,
159 lock_account_request = 0x2013,
160 lock_account_response = 0x2014,
161 update_account_request = 0x2015,
162 update_account_response = 0x2016,
163 get_account_history_request = 0x2017,
164 get_account_history_response = 0x2018,
165 reset_password_request = 0x2019,
166 reset_password_response = 0x201A,
167 change_password_request = 0x201B,
168 change_password_response = 0x201C,
169 update_my_email_request = 0x201D,
170 update_my_email_response = 0x201E,
171
172 // Authorization/RBAC messages (0x2020 - 0x202F)
173 list_roles_request = 0x2020,
174 list_roles_response = 0x2021,
175 list_permissions_request = 0x2022,
176 list_permissions_response = 0x2023,
177 assign_role_request = 0x2024,
178 assign_role_response = 0x2025,
179 revoke_role_request = 0x2026,
180 revoke_role_response = 0x2027,
181 get_account_roles_request = 0x2028,
182 get_account_roles_response = 0x2029,
183 get_account_permissions_request = 0x202A,
184 get_account_permissions_response = 0x202B,
185
186 // Variability subsystem messages (0x3000 - 0x3FFF)
187 list_feature_flags_request = 0x3000,
188 list_feature_flags_response = 0x3001,
189
190 last_value
191};
192
193enum class error_code {
194 none = 0x0000,
195 version_mismatch = 0x0001,
196 crc_validation_failed = 0x0002,
197 invalid_message_type = 0x0003,
198 handshake_timeout = 0x0004,
199 handshake_failed = 0x0005,
200 payload_too_large = 0x0006,
201 network_error = 0x0007,
202 handler_error = 0x0008,
203 database_error = 0x0009,
204 authentication_failed = 0x000A,
205 authorization_failed = 0x000B,
206 invalid_request = 0x000C,
207 bootstrap_mode_only = 0x000D,
208 bootstrap_mode_forbidden = 0x000E,
209 weak_password = 0x000F,
210 not_localhost = 0x0010,
211 database_unavailable = 0x0011,
212 decompression_failed = 0x0012,
213 unsupported_compression = 0x0013,
214 compression_failed = 0x0014,
215 last_value
216};
217
224inline std::ostream& operator<<(std::ostream& os, message_type mt) {
225 return os << magic_enum::enum_name(mt)
226 << " (0x" << std::hex << static_cast<std::uint16_t>(mt) << std::dec << ")";
227}
228
235inline std::ostream& operator<<(std::ostream& os, error_code ec) {
236 return os << magic_enum::enum_name(ec)
237 << " (0x" << std::hex << static_cast<std::uint16_t>(ec) << std::dec << ")";
238}
239
243inline std::ostream& operator<<(std::ostream& os, compression_type ct) {
244 return os << magic_enum::enum_name(ct)
245 << " (0x" << std::hex << static_cast<std::uint8_t>(ct) << std::dec << ")";
246}
247
251inline std::string to_string(error_code ec) {
252 return std::string(magic_enum::enum_name(ec));
253}
254
255}
256
257#endif
Contains messaging related infrastructure in the comms library.
Definition compression.hpp:29
std::string to_string(error_code ec)
Convert error_code to string for display.
Definition message_types.hpp:251
compression_type
Compression algorithm used for payload compression.
Definition message_types.hpp:104