-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.hpp
More file actions
108 lines (95 loc) · 2.21 KB
/
node.hpp
File metadata and controls
108 lines (95 loc) · 2.21 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
#ifndef NODE_HPP
#define NODE_HPP
#include "query_client.hpp"
#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <cassert>
#include <fcntl.h>
#include <fstream>
#include <filesystem>
#include <unistd.h>
#include <vector>
#include <iterator>
#include <algorithm>
#include <random>
#include <ctime>
#include "helpers.hpp"
using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using query::Query;
using query::ColorReply;
using query::ColorRequest;
using grpc::Channel;
using grpc::ClientContext;
using std::string;
using std::thread;
using std::stoi;
using std::cout;
using std::ifstream;
using std::endl;
using std::to_string;
using std::vector;
enum Color {
RED,
BLUE,
UNCOLORED
};
class Node {
int id;
string color;
Color color_enum;
string port;
bool is_server_ready;
bool to_start;
//int config_fd;
bool is_byzantine;
time_t start_time;
public:
Node(string id, string color1, int is_byzantine1);
int getId();
string getColor();
string getPort();
bool getIsByzantine();
bool getIsServerReady();
bool getToStart();
bool checkIfClusterReady(int num_of_nodes);
void setColor(string new_color);
void setReady();
void setStart();
void colorToString();
void stringToColor();
virtual string getReply(string request);
/***
* Given n and k, picks k elements from the set {1...n}/{my_id}
***/
vector<int> getSample(int n,int k);
int* askSample(int n,int k, int* count);
string Snowball(int n, int k, int alpha, int beta);
};
class Byzantine : public Node {
public:
Byzantine(string id, string color1, int is_byzantine1);
string getReply(string request) override;
};
class Coordinator {
int n;
int numOfConnectedNodes;
string port_num;
vector<string> nodes_ports;
public:
Coordinator(int n);
string getCPort();
int getNumOfConnectedNodes();
vector<string> getVector();
void addNum();
void addToVector(string node_port);
};
void ready_thread(Node* node);
void server_thread(Node* node);
void server_cthread(Coordinator* coordinator);
const string contact_etcd_cmd = "etcdctl --endpoints 172.20.0.5:2379 ";
#endif