My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
msu_message.h
Go to the documentation of this file.
1 /*
2 START OF LICENSE STUB
3  DeDOS: Declarative Dispersion-Oriented Software
4  Copyright (C) 2017 University of Pennsylvania, Georgetown University
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 END OF LICENSE STUB
19 */
26 #ifndef MSU_MESSAGE_H
27 #define MSU_MESSAGE_H
28 #include "message_queue.h"
29 #include "msu_type.h"
30 
36 struct composite_key {
37  uint64_t k1;
38  uint64_t k2;
39  uint64_t k3;
40 };
41 
46 struct msu_msg_key {
50  size_t key_len;
52  int32_t id;
55  int group_id;
56 };
57 
60  unsigned int type_id;
61  unsigned int msu_id;
62  unsigned int runtime_id;
63 };
64 
66 #define MAX_PATH_LEN 8
67 
78  int path_len;
79 };
80 
85 struct msu_msg_hdr {
87  struct msu_msg_key key;
92 #ifdef DEDOS_PROFILER
93 
94  bool do_profile;
95 #endif
96 };
97 
101 struct msu_msg {
102  struct msu_msg_hdr hdr;
103  size_t data_size;
104  void *data;
105 };
106 
110 unsigned int msu_msg_sender_type(struct msg_provinance *prov);
111 
115 struct msu_provinance_item *get_provinance_item(struct msg_provinance *p, struct msu_type *type);
116 
123 int add_provinance(struct msg_provinance *prov,
124  struct local_msu *sender);
125 
133 int init_msu_msg_hdr(struct msu_msg_hdr *hdr, struct msu_msg_key *key);
134 
138 int set_msg_key(int32_t id, struct msu_msg_key *key);
139 
144 int seed_msg_key(void *seed, size_t seed_size, struct msu_msg_key *key);
145 
149 void destroy_msu_msg_and_contents(struct msu_msg *msg);
150 
159 struct msu_msg *read_msu_msg(struct local_msu *msu, int fd, size_t size);
160 
168 int schedule_msu_msg(struct msg_queue *q, struct msu_msg *data, struct timespec *interval);
169 
176 int enqueue_msu_msg(struct msg_queue *q, struct msu_msg *data);
177 
183 struct msu_msg *dequeue_msu_msg(struct msg_queue *q);
184 
193 void *serialize_msu_msg(struct msu_msg *msg,
194  struct msu_type *dst_type, size_t *size_out);
195 
200 struct msu_msg *create_msu_msg(struct msu_msg_hdr *hdr,
201  size_t data_size,
202  void *data);
203 #endif
Item in the chain of history kept track of in each MSU.
Definition: msu_message.h:59
uint64_t k2
Definition: msu_message.h:38
Header for messages passed to MSUs.
Definition: msu_message.h:85
struct composite_key key
The full, arbitrary-length, unique key (used in state)
Definition: msu_message.h:48
struct msu_msg * read_msu_msg(struct local_msu *msu, int fd, size_t size)
Reads an MSU message of the given size from the provided file descriptor.
Definition: msu_message.c:171
struct msu_provinance_item * get_provinance_item(struct msg_provinance *p, struct msu_type *type)
Definition: msu_message.c:45
int error_flag
0 if no error has been encountered
Definition: msu_message.h:91
void destroy_msu_msg_and_contents(struct msu_msg *msg)
Frees both the message and message data.
Definition: msu_message.c:156
Defines a type of MSU, including callback and accessor functions.
int schedule_msu_msg(struct msg_queue *q, struct msu_msg *data, struct timespec *interval)
Schedules an MSU message to be delivered after interval time has passed.
Definition: msu_message.c:106
Container for linked list message queue.
Definition: message_queue.h:56
void * data
Payload.
Definition: msu_message.h:104
int32_t id
A shorter, often hashed id for the key of fixed length (used in routing)
Definition: msu_message.h:52
struct msu_provinance_item sender
The last MSU to see this message.
Definition: msu_message.h:73
int seed_msg_key(void *seed, size_t seed_size, struct msu_msg_key *key)
Sets the key's composite-ID to the provided value, and sets the key's ID to a hash of the value...
Definition: msu_message.c:62
unsigned int type_id
Definition: msu_message.h:60
struct msu_provinance_item origin
The first MSU to see this message.
Definition: msu_message.h:71
void * serialize_msu_msg(struct msu_msg *msg, struct msu_type *dst_type, size_t *size_out)
Converts an MSU message into a serializes stream of bytes.
Definition: msu_message.c:216
unsigned int runtime_id
Definition: msu_message.h:62
Keeps track of which MSUs have seen a given message header.
Definition: msu_message.h:69
struct msu_msg * dequeue_msu_msg(struct msg_queue *q)
Dequeues an MSU message from the provided message queue.
Definition: msu_message.c:124
int add_provinance(struct msg_provinance *prov, struct local_msu *sender)
Adds a new item to the path of MSUs taken within the mesasge provinance in the header.
Definition: msu_message.c:74
size_t data_size
Payload size.
Definition: msu_message.h:103
struct msg_provinance provinance
Message history.
Definition: msu_message.h:89
int path_len
The current length of msg_provinance::path.
Definition: msu_message.h:78
int set_msg_key(int32_t id, struct msu_msg_key *key)
Sets the key's ID and composite-ID to be equal to the provided id.
Definition: msu_message.c:54
struct msu_provinance_item path[8]
A list of each MSU that has seen this message TODO: For now, one MSU of each type.
Definition: msu_message.h:76
The structure that represents an MSU located on the local machine.
Definition: local_msu.h:38
int init_msu_msg_hdr(struct msu_msg_hdr *hdr, struct msu_msg_key *key)
Initializes and resets a message header, storing a copy of the provided key.
Definition: msu_message.c:35
Structures and functions for enqueueing and dequeuing general-purpose messages from a queue...
The composite key is used to store a key of arbitrary length (up to 192 bytes).
Definition: msu_message.h:36
Defines a type of MSU.
Definition: msu_type.h:46
uint64_t k1
Definition: msu_message.h:37
unsigned int msu_msg_sender_type(struct msg_provinance *prov)
Definition: msu_message.c:41
struct msu_msg * create_msu_msg(struct msu_msg_hdr *hdr, size_t data_size, void *data)
Creates an MSU message with the appropriate header, data size, and data.
Definition: msu_message.c:161
int enqueue_msu_msg(struct msg_queue *q, struct msu_msg *data)
Enqueues a message for immediate delivery.
Definition: msu_message.c:101
struct msu_msg_hdr hdr
Definition: msu_message.h:102
#define MAX_PATH_LEN
The maximum path length recorded for a messages path through MSUs.
Definition: msu_message.h:66
unsigned int msu_id
Definition: msu_message.h:61
int group_id
Used to mark a route ID when storing state.
Definition: msu_message.h:55
A message that is to be delivered to an instance of an MSU.
Definition: msu_message.h:101
Used to uniquely identify the source of a message, used in state storage as well as routing...
Definition: msu_message.h:46
size_t key_len
The length of the composite key.
Definition: msu_message.h:50
uint64_t k3
Definition: msu_message.h:39
struct msu_msg_key key
Routing/state key.
Definition: msu_message.h:87