-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommons.h
More file actions
196 lines (165 loc) · 3.63 KB
/
commons.h
File metadata and controls
196 lines (165 loc) · 3.63 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
*
* Author: Pramod Kumar(veer)
*
* Description: commons.cc
* Shared declaration and variable accross all process code i.e included in Makefile
*
*/
#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 <grpc/grpc.h>
#include <grpcpp/grpcpp.h>
#include <grpcpp/channel.h>
#include <grpcpp/client_context.h>
#include <grpcpp/create_channel.h>
//#include <grpcpp/security/credentials.h>
#define DEBUG_FLAG 1
#define FILE_SERVER_CHUNK_SZ 4096
using namespace std;
enum request_type {
READ = 0,
WRITE = 1,
CREATE = 2,
DELETE = 3,
OPEN = 4,
FSTAT = 5
};
enum return_code {
OK = 0,
ERROR = 1
};
enum file_status {
NONE = 0,
CREATED = 1,
OPENED = 2,
WRITING = 3,
WRITTEN = 4,
READING = 5,
READ_ = 6,
CLOSED = 7
};
enum service_type {
CLIENT = 0,
FILE_SERVER = 1
};
typedef struct file_access_request_ {
request_type type;
uint32_t start_byte;
uint32_t end_byte;
int request_id;
string file_name;
string req_ipaddr_port;
uint32_t strip_width;
uint32_t fdis ;
} file_access_request_t;
typedef struct file_access_response_ {
int request_id ;
return_code code;
string token;
uint32_t start_byte;
uint32_t end_byte;
uint32_t fdis ;
uint64_t create_time;
uint64_t last_modified_time;
uint32_t file_size;
int stripe_width;
vector<string> server_list;
} file_access_response_t;
typedef struct fs_read_write_request_ {
request_type type;
uint32_t start_byte;
uint32_t end_byte;
int request_id;
string file_name;
string req_ipaddr_port;
char *data;
int strip_width;
} fs_read_write_request_t;
typedef struct fs_read_write_response_ {
int request_id ;
return_code code;
int size ;
char *data;
} fs_read_write_response_t;
typedef struct register_service_request_ {
service_type type;
string ip_port;
} register_service_request_t;
typedef struct response_ {
return_code code;
} register_service_response_t;
typedef struct permission_ {
string type;
pair<int,int> start_end;
} permission;
typedef struct file_store_ {
string file_name;
string global_permission; /*Permission with which this file was opened*/
file_status status;
uint32_t create_time;
uint32_t last_modified_time;
uint32_t file_size;
uint32_t stripe_width;
uint32_t fdis;
vector<string> server_list;
vector<permission> access_permission;
file_store_(string filename, int stripeWidth) {
file_name = filename;
global_permission ="";
status = CREATED;
create_time = 0;
last_modified_time = 0;
file_size = 0;
stripe_width = stripeWidth;
fdis = 0;
}
} file_info_store;
extern int get_random_number ();
/*
New Data Structs
*/
enum revoke_type {
READ_REVOKE = 0,
WRITE_REVOKE = 1,
DELETE_REVOKE = 2
};
enum revoke_code {
WHOLE = 0,
PARTIAL = 1
};
typedef struct revoke_access_request_ {
revoke_type type;
uint32_t start_byte;
uint32_t end_byte;
int request_id;
string file_name;
//string token;
} revoke_access_request_t;
typedef struct revoke_access_response_ {
int request_id ;
revoke_code code;
} revoke_access_response_t;
typedef struct update_modified_access_request_ {
string file_name;
uint64_t modified_time;
int last_address;
} update_modified_access_request_t;
typedef struct update_modified_access_response_ {
return_code code;
} update_modified_access_response_t;