-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommons.h
More file actions
131 lines (101 loc) · 2.07 KB
/
commons.h
File metadata and controls
131 lines (101 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef COMMONS_H
#define COMMONS_H
#include <chrono>
#include <iostream>
#include <memory>
#include <random>
#include <string>
#include <thread>
#include <stdint.h>
#include <time.h>
#include <mutex>
#include <fstream>
#include <utility>
#include <cstddef>
#include <sys/types.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <bits/stdc++.h>
#include <cstdint>
#include <cstring>
#include <future>
#include <utility>
#include <grpc/grpc.h>
#include <grpcpp/grpcpp.h>
#include <grpcpp/channel.h>
#include <grpcpp/client_context.h>
#include <grpcpp/create_channel.h>
//#define DEBUG_FLAG 1
//#define DEBUG_LOG_QUEUE 1
#define INTERFACE "lo"
//#define INTERFACE "ens4"
#define SIZE_OF_VALUE 3
#define ABD_NUMBER_OF_CLIENTS 3
#define CM_NUMBER_OF_CLIENTS 10
#define MP_NUMBER_OF_CLIENTS 3
#define INT_SIZE sizeof(int)
#define INIT_COMMAND_LENGTH 100000
using namespace std;
enum request_type {
READ_QUERY = 0,
WRITE_QUERY = 1,
READ = 2,
WRITE = 3
};
enum return_code {
ACK = 0,
ERROR = 1,
OK = 2,
NACK = 3,
SOME_NACK = 4
};
enum protocol_type {
CM = 0,
ABD = 1,
MP = 2 // Multi-Paxos
};
typedef struct tag {
uint32_t integer;
uint32_t client_id;
} tag_t;
typedef struct request_ {
request_type type;
protocol_type protocol;
tag_t tag;
char *key;
uint32_t key_sz;
char *value;
uint32_t value_sz;
} request_t;
typedef struct response_ {
return_code code;
protocol_type protocol;
tag_t tag;
char *key;
uint32_t key_sz;
char *value;
uint32_t value_sz;
} response_t;
typedef struct value_ {
tag_t tag;
char* key;
uint32_t key_sz;
char* value;
uint32_t value_sz;
} value_t;
typedef struct cm_message_request_ {
uint32_t nodenum;
char* key;
uint32_t key_sz;
char* value;
uint32_t value_sz;
int *vec_clk;
uint32_t vecclk_sz;
} cm_message_request_t;
typedef struct cm_message_response_ {
return_code code;
} cm_message_response_t;
extern uint32_t get_random_number ();
bool apply_last_write(string key, uint32_t index);
#endif //end of COMMONS_H