#ifndef H_MSG #define H_MSG #include "hosts.h" #include #include typedef struct { bool is_timed_out; uint8_t *data; // always in network byte order uint8_t len; } packet; // client msg requests: (ADD(x), SUB(x), MUL(x), GET) // state += x, -= x, *= x, returns state struct msg { uint8_t msg_type; // 0 = request, 1 = preprepare, 2 = prepare, 3 = commit, 4 = // response // request fields uint8_t req_message; // 0 = add, 1 = sub, 2 = mul, 3 = get uint32_t option_value; // value for message. uint64_t timestamp; uint32_t client_index; // preprepare, prepare, commit, checkpoint fields uint32_t view; uint32_t seq; uint32_t digest; uint32_t server_index; uint32_t signature; }; struct msg_log { struct msg_log *next; struct msg *m; }; void append_msg(struct msg *m); void discard_before_seq(uint32_t seq); void clean_packet(packet *p); struct msg *init_msg(); void clean_msg(struct msg *m); void display_msg(struct msg *m); struct msg *parse_packet_as_msg(packet *p); packet *parse_msg_as_packet(struct msg *m); void broadcast(struct host **conns, int num_conns, packet *data); void send_to(struct host *conn, packet *data); void send_to_replica(struct host **conns, int num_conns, int replica, packet *data); #endif