1 /** @file messages.h 2 * Razorback API messages. 3 */ 4 #ifndef RAZORBACK_MESSAGES_H 5 #define RAZORBACK_MESSAGES_H 6 7 #include <razorback/visibility.h> 8 #include <razorback/message_formats.h> 9 #include <razorback/types.h> 10 #include <razorback/api.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 #define MESSAGE_MODE_BIN 1 17 #define MESSAGE_MODE_JSON 2 18 19 /** Message Groups 20 * @{ 21 */ 22 #define MESSAGE_GROUP_C_AND_C 0x10000000 ///< Command And Control 23 #define MESSAGE_GROUP_CACHE 0x20000000 ///< Global Cache 24 #define MESSAGE_GROUP_SUBMIT 0x40000000 ///< Submission 25 #define MESSAGE_GROUP_OUTPUT 0x80000000 ///< Submission 26 /// @} 27 /** Command And Control Messages 28 * @{ 29 */ 30 #define MESSAGE_TYPE_HELLO ( MESSAGE_GROUP_C_AND_C | 1 ) ///< Hello Message 31 #define MESSAGE_TYPE_REG_REQ ( MESSAGE_GROUP_C_AND_C | 2 ) ///< Registration Request 32 #define MESSAGE_TYPE_REG_RESP ( MESSAGE_GROUP_C_AND_C | 3 ) ///< Registration Response 33 #define MESSAGE_TYPE_REG_ERR ( MESSAGE_GROUP_C_AND_C | 4 ) ///< Registration Error 34 #define MESSAGE_TYPE_CONFIG_UPDATE ( MESSAGE_GROUP_C_AND_C | 5 ) ///< Configuration Update Notice 35 #define MESSAGE_TYPE_CONFIG_ACK ( MESSAGE_GROUP_C_AND_C | 6 ) ///< Configuration Updated OK 36 #define MESSAGE_TYPE_CONFIG_ERR ( MESSAGE_GROUP_C_AND_C | 7 ) ///< Configuration Update Failed 37 #if 0 38 #define MESSAGE_TYPE_STATS_REQ ( MESSAGE_GROUP_C_AND_C | 8 ) ///< Statistics Request 39 #define MESSAGE_TYPE_STATS_RESP ( MESSAGE_GROUP_C_AND_C | 9 ) ///< Statistics Response (With Data) 40 #define MESSAGE_TYPE_STATS_ERR ( MESSAGE_GROUP_C_AND_C | 10 ) ///< Statistics Error 41 #endif 42 #define MESSAGE_TYPE_PAUSE ( MESSAGE_GROUP_C_AND_C | 11 ) ///< Pause Processing 43 #define MESSAGE_TYPE_PAUSED ( MESSAGE_GROUP_C_AND_C | 12 ) ///< Pause Confirmation 44 #define MESSAGE_TYPE_GO ( MESSAGE_GROUP_C_AND_C | 13 ) ///< Unpause Processing 45 #define MESSAGE_TYPE_RUNNING ( MESSAGE_GROUP_C_AND_C | 14 ) ///< Unpuase Confirmation 46 #define MESSAGE_TYPE_TERM ( MESSAGE_GROUP_C_AND_C | 15 ) ///< Terminate Processing 47 #define MESSAGE_TYPE_BYE ( MESSAGE_GROUP_C_AND_C | 16 ) ///< Terminating Processing 48 #define MESSAGE_TYPE_CLEAR ( MESSAGE_GROUP_C_AND_C | 17 ) ///< Clear Local Cache 49 #define MESSAGE_TYPE_REREG ( MESSAGE_GROUP_C_AND_C | 18 ) ///< Reregister 50 /// @} 51 52 /** Global Cache Messages 53 * @{ 54 */ 55 #define MESSAGE_TYPE_REQ ( MESSAGE_GROUP_CACHE | 1 ) ///< Global Cache Request 56 #define MESSAGE_TYPE_RESP ( MESSAGE_GROUP_CACHE | 2 ) ///< Global Cache Response 57 /// @} 58 59 /** Submission Messages 60 * @{ 61 */ 62 #define MESSAGE_TYPE_BLOCK ( MESSAGE_GROUP_SUBMIT | 1 ) ///< Data Block Submission 63 #define MESSAGE_TYPE_JUDGMENT ( MESSAGE_GROUP_SUBMIT | 2 ) ///< Judgment Submission 64 #define MESSAGE_TYPE_INSPECTION ( MESSAGE_GROUP_SUBMIT | 3 ) ///< Inspection Submission 65 #define MESSAGE_TYPE_LOG ( MESSAGE_GROUP_SUBMIT | 4 ) ///< Log Message 66 #define MESSAGE_TYPE_ALERT ( MESSAGE_GROUP_SUBMIT | 5 ) ///< Alert Message 67 /// @} 68 69 /** Output Messages 70 * @{ 71 */ 72 #define MESSAGE_TYPE_ALERT_PRIMARY ( MESSAGE_GROUP_OUTPUT | 1 ) ///< Block turns to bad 73 #define MESSAGE_TYPE_ALERT_CHILD ( MESSAGE_GROUP_OUTPUT | 2 ) ///< Block turns to bad due to child 74 #define MESSAGE_TYPE_OUTPUT_EVENT ( MESSAGE_GROUP_OUTPUT | 3 ) ///< Event Record 75 #define MESSAGE_TYPE_OUTPUT_LOG ( MESSAGE_GROUP_OUTPUT | 4 ) ///< Log Record 76 #define MESSAGE_TYPE_OUTPUT_INSPECTION ( MESSAGE_GROUP_OUTPUT | 5 ) ///< Inspection status 77 /// @} 78 79 80 /** Message Versions 81 * @{ 82 */ 83 #define MESSAGE_VERSION_1 1 84 /// @} 85 86 #define MSG_CNC_HEADER_SOURCE "Source_Nugget" 87 #define MSG_CNC_HEADER_DEST "Dest_Nugget" 88 89 #define DISP_HELLO_FLAG_LM (1 << 0) 90 #define DISP_HELLO_FLAG_LS (1 << 1) 91 #define DISP_HELLO_FLAG_DD (1 << 2) 92 #define DISP_HELLO_FLAG_LF (1 << 3) 93 94 /** Message handler structure 95 */ 96 struct MessageHandler 97 { 98 uint32_t type; ///< Message type code 99 bool (*serialize)(struct Message *msg, int mode); ///< Serialization function pointer 100 bool (*deserialize)(struct Message *msg, int mode); ///< Deserialization function pointer 101 void (*destroy)(struct Message *msg); ///< Destructor function pointer 102 }; 103 104 /** Create a list for storing message headers 105 * @return A new list on success, NULL on failure. 106 */ 107 SO_PUBLIC extern struct List * Message_Header_List_Create(void); 108 109 /** Add a header to a header list structure. 110 * @param headers The header list. 111 * @param name The header name. 112 * @param value The header value. 113 * @return true on success false on failure 114 */ 115 SO_PUBLIC extern bool Message_Add_Header(struct List *headers, const char *name, const char *value); 116 117 /** Register a message handler 118 * @param handler The handler structure. 119 * @return true on success, false on error. 120 */ 121 SO_PUBLIC extern bool Message_Register_Handler(struct MessageHandler *handler); 122 123 /** Get nugget ID headers from a message 124 * @param message The message 125 * @param source The UUID to store the source nugget id in. 126 * @param dest The UUID to store the destination nugget in. 127 * @return true on success, false on error. 128 */ 129 SO_PUBLIC extern bool Message_Get_Nuggets(struct Message *message, uuid_t source, uuid_t dest); 130 131 /** Deserialize an empty message 132 * @param message The message 133 * @param mode Messaging mode. 134 * @return true on success, false on failure. 135 */ 136 SO_PUBLIC extern bool Message_Deserialize_Empty(struct Message *message, int mode); 137 138 /** Deserialize an empty message 139 * @param message The message 140 * @param mode Messaging mode. 141 * @return true on success, false on failure. 142 */ 143 SO_PUBLIC extern bool Message_Serialize_Empty(struct Message *message, int mode); 144 145 /** Create a message with directed message headers on a topic. 146 * @param type Message type. 147 * @param version Message version 148 * @param msgSize Message size 149 * @param source Source nugget UUID 150 * @param dest Destination nugget UUID 151 * @return A new message on success, NULL on failure. 152 */ 153 SO_PUBLIC extern struct Message * Message_Create_Directed(uint32_t type, uint32_t version, size_t msgSize, const uuid_t source, const uuid_t dest); 154 155 /** Create a message with broadcast message headers on a topic. 156 * @param type Message type. 157 * @param version Message version 158 * @param msgSize Message size 159 * @param source Source nugget UUID 160 * @return A new message on success, NULL on failure. 161 */ 162 SO_PUBLIC extern struct Message * Message_Create_Broadcast(uint32_t type, uint32_t version, size_t msgSize, const uuid_t source); 163 164 /** Destroy a message. 165 * @param message The message to destroy. 166 */ 167 SO_PUBLIC extern void Message_Destroy(struct Message *message); 168 169 170 /** Initializes message cache request 171 * @param requestorUUID the requester 172 * @param blockId the block id 173 * @return A new message on success, NULL On failure. 174 */ 175 SO_PUBLIC extern struct Message* MessageCacheReq_Initialize ( 176 const uuid_t requestorUUID, 177 const struct BlockId *blockId); 178 179 180 /** Initializes message cache response 181 * @param iblockId the block id 182 * @param sfFlags the code 183 * @param entFlags the code 184 * @return A new message on success, NULL On failure. 185 */ 186 SO_PUBLIC extern struct Message* MessageCacheResp_Initialize ( 187 const struct BlockId *blockId, 188 uint32_t sfFlags, uint32_t entFlags); 189 190 191 /** Initializes message block submission 192 * @param event The event 193 * @param reason The submission reason 194 * @param locality The locality the block was stored in. 195 * @return A new message on success, NULL On failure. 196 */ 197 SO_PUBLIC extern struct Message* MessageBlockSubmission_Initialize ( 198 struct Event *event, 199 uint32_t reason, uint8_t locality); 200 201 202 /** Initializes message block submission 203 * @param reason The judgment type. 204 * @param judgment The judgment data. 205 * @return A new message on success, NULL On failure. 206 */ 207 SO_PUBLIC extern struct Message* MessageJudgmentSubmission_Initialize ( 208 uint8_t reason, 209 struct Judgment* judgment); 210 211 /** Initializes message inspection submission 212 * @param event The event 213 * @param reason the reason 214 * @param localityCount The number of localities the block is stored in 215 * @param locality Array of localities the block is stored in 216 * @return A new message on success, NULL On failure. 217 */ 218 SO_PUBLIC extern struct Message* MessageInspectionSubmission_Initialize ( 219 const struct Event *event, 220 uint32_t reason, 221 uint32_t localityCount, 222 uint8_t *localities 223 ); 224 225 /** Initializes a hello message 226 * @param context The context of this message. 227 * @return A new message on success, NULL On failure. 228 */ 229 SO_PUBLIC extern struct Message* MessageHello_Initialize (struct RazorbackContext *context); 230 231 232 /** Initializes a registration request message 233 * @param disptacherId Dispatcher to send the request to. 234 * @param sourceNugget the source 235 * @param nuggetTye the nugget type 236 * @param applicationType the application type 237 * @param dataTypeCount the number of data types 238 * @param dataTypeList the data types 239 * @return A new message on success, NULL On failure. 240 */ 241 SO_PUBLIC extern struct Message* MessageRegistrationRequest_Initialize ( 242 const uuid_t dispatcherId, 243 const uuid_t sourceNugget, 244 const uuid_t nuggetType, 245 const uuid_t applicationType, 246 uint32_t dataTypeCount, 247 uuid_t * dataTypeList); 248 249 250 /** Initializes a registration response message 251 * @param sourceNugget the source 252 * @param destNugget the destination 253 * @return A new message on success, NULL On failure. 254 */ 255 SO_PUBLIC extern struct Message* MessageRegistrationResponse_Initialize ( 256 const uuid_t sourceNugget, 257 const uuid_t destNugget); 258 259 /** Initializes a configuration update message 260 * @param sourceNugget the source 261 * @param destNugget the destination 262 * @return A new message on success, NULL On failure. 263 */ 264 SO_PUBLIC extern struct Message * MessageConfigurationUpdate_Initialize ( 265 const uuid_t sourceNugget, 266 const uuid_t destNugget); 267 268 269 /** Initializes a configuration acknowledgment message 270 * @param sourceNugget the source 271 * @param destNugget the destination 272 * @param nuggetType the type of nugget 273 * @param applicationType the application type 274 * @return A new message on success, NULL On failure. 275 */ 276 SO_PUBLIC extern struct Message* MessageConfigurationAck_Initialize ( 277 const uuid_t sourceNugget, 278 const uuid_t sestNugget, 279 const uuid_t nuggetType, 280 const uuid_t applicationType); 281 282 283 /** Initializes a pause message 284 * @param sourceNugget the source 285 * @param destNugget the destination 286 * @return A new message on success, NULL On failure. 287 */ 288 SO_PUBLIC extern struct Message * MessagePause_Initialize ( 289 const uuid_t sourceNugget, 290 const uuid_t destNugget); 291 292 293 /** Initializes a paused message 294 * @param sourceNugget the source 295 * @param destNugget the destination 296 * @return A new message on success, NULL On failure. 297 */ 298 SO_PUBLIC extern struct Message* MessagePaused_Initialize ( 299 const uuid_t sourceNugget, 300 const uuid_t destNugget); 301 302 303 /** Initializes a go message 304 * @param sourceNugget the source 305 * @param destNugget the destination 306 * @return A new message on success, NULL On failure. 307 */ 308 SO_PUBLIC extern struct Message * MessageGo_Initialize ( 309 const uuid_t sourceNugget, 310 const uuid_t destNugget); 311 312 313 314 /** Initializes a running message 315 * @param sourceNugget the source 316 * @param destNugget the destination 317 * @return A new message on success, NULL On failure. 318 */ 319 SO_PUBLIC extern struct Message * MessageRunning_Initialize ( 320 const uuid_t sourceNugget, 321 const uuid_t destNugget); 322 323 324 /** Initializes a terminate message 325 * @param sourceNugget the source 326 * @param destNugget the destination 327 * @param reason the reason 328 * @return A new message on success, NULL On failure. 329 */ 330 SO_PUBLIC extern struct Message * MessageTerminate_Initialize ( 331 const uuid_t sourceNugget, 332 const uuid_t destNugget, 333 const uint8_t * reason); 334 335 336 /** Initializes a bye message 337 * @param sourceNugget the source 338 * @return A new message on success, NULL On failure. 339 */ 340 SO_PUBLIC extern struct Message * MessageBye_Initialize ( 341 const uuid_t sourceNugget); 342 343 344 /** Initialize a cache clear message 345 * @param sourceNugget the source 346 * @return A new message on success, NULL On failure. 347 */ 348 SO_PUBLIC extern struct Message * MessageCacheClear_Initialize ( 349 const uuid_t sourceNugget); 350 351 /** Initialize an error message 352 * @param errorCode The error code 353 * @param message The message text 354 * @param sourceNugget The source 355 * @param destNugget The destination 356 * @return A new message on success, NULL On failure. 357 */ 358 SO_PUBLIC extern struct Message * MessageError_Initialize ( 359 uint32_t errorCode, 360 const char *message, 361 const uuid_t sourceNugget, 362 const uuid_t destNugget); 363 364 /** Initialize a log message 365 * @param nuggetId The source nugget. 366 * @param priority The message level 367 * @param message The message text. 368 * @param eventId The optional event id, use NULL if no event is linked to this log message. 369 * @return A new message on success, NULL On failure. 370 */ 371 SO_PUBLIC extern struct Message * 372 MessageLog_Initialize ( 373 const uuid_t nuggetId, 374 uint8_t priority, 375 char *message, 376 struct EventId *eventId); 377 378 /** Initialize a primary alert message 379 * @param event The event that triggered inspection 380 * @param block The block that triggered the alert. 381 * @param metadata The alert metadata. 382 * @param nugget The inspector that triggered the alert. 383 * @param judgment The judgment data from the inspector. 384 * @param new_SF_Flags Post alert block SF Flags 385 * @param new Ent_Flags Post alert block Enterprise flags. 386 * @param old_SF_Flags Pre alert block SF Flags 387 * @param old_Ent_Flags Pre alert block Enterprise flags. 388 * @return A new message on success, NULL On failure. 389 */ 390 SO_PUBLIC extern struct Message * 391 MessageAlertPrimary_Initialize ( 392 struct Event *event, 393 struct Block *block, 394 struct List *metadata, 395 struct Nugget *nugget, 396 struct Judgment *judgment, 397 uint32_t new_SF_Flags, uint32_t new_Ent_Flags, 398 uint32_t old_SF_Flags, uint32_t old_Ent_Flags); 399 400 /** Initialize a child alert message 401 * @param block The block that has changed state. 402 * @param child The child block that triggered the state change. 403 * @param nugget The nugget that sent the alert. 404 * @param parentCount The number of blocks that have this block as a parent. 405 * @param eventCount The number of events associated with this block. 406 * @param new_SF_Flags Post alert block SF Flags 407 * @param new Ent_Flags Post alert block Enterprise flags. 408 * @param old_SF_Flags Pre alert block SF Flags 409 * @param old_Ent_Flags Pre alert block Enterprise flags. 410 * @return A new message on success, NULL On failure. 411 */ 412 SO_PUBLIC extern struct Message * 413 MessageAlertChild_Initialize ( 414 struct Block *block, 415 struct Block *child, 416 struct Nugget *nugget, 417 uint64_t parentCount, uint64_t eventCount, 418 uint32_t new_SF_Flags, uint32_t new_Ent_Flags, 419 uint32_t old_SF_Flags, uint32_t old_Ent_Flags); 420 421 /** Initialize an event output message 422 * @param event The event that has occurred. 423 * @param nugget The nugget that created the event. 424 * @return A new message on success, NULL On failure. 425 */ 426 SO_PUBLIC extern struct Message * 427 MessageOutputEvent_Initialize ( 428 struct Event *event, 429 struct Nugget *nugget); 430 431 /** Initialize a log output message 432 * @param log The log message received to be output 433 * @param nugget The nugget that sent the log message. 434 * @return A new message on success, NULL On failure. 435 */ 436 SO_PUBLIC extern struct Message * 437 MessageOutputLog_Initialize ( 438 struct MessageLogSubmission *log, 439 struct Nugget *nugget); 440 441 /** Initialize an inspection status output message. 442 * @param nugget The nugget that is inspecting the block 443 * @param blockId The block ID of the block being inspected. 444 * @param reason The reason for this output. 445 * @param final Is this the last inspection to complete. 446 * @return A new message on success, NULL On failure. 447 */ 448 SO_PUBLIC struct Message * 449 MessageOutputInspection_Initialize ( 450 struct Nugget *nugget, 451 struct BlockId *blockId, 452 uint8_t reason, 453 bool final); 454 455 #ifdef __cplusplus 456 } 457 #endif 458 #endif //RAZORBACK_MESSAGES_H 459