forked from ayushj94/ExpoCPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.cpp
74 lines (66 loc) · 1.93 KB
/
system.cpp
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
#include <iostream>
#include "system.hpp"
#include "localnode.hpp"
#include "scpmessage.hpp"
#include "nominationstate.hpp"
#include "slot.hpp"
using namespace std;
System::System(unsigned nodeSize, string name) {
this->name = name;
this->nodeSize = nodeSize;
for (unsigned i = 0; i < nodeSize; i++) {
nodes.push_back(new LocalNode(this, i));
}
}
void System::setFullQset() {
vector<unsigned> fullQuorumSet;
for (unsigned i = 0; i < nodeSize; i++) {
fullQuorumSet.push_back(i);
}
for (unsigned i = 0; i < nodeSize; i++) {
nodes.at(i)->updateQset(fullQuorumSet);
}
}
void System::setHalfQset() {
for (unsigned i = 0; i < nodeSize; i++) {
vector<unsigned> qSet;
for(unsigned j = i; j <= i + nodeSize / 2; j++) {
qSet.push_back(j % nodeSize);
}
nodes[i]->updateQset(qSet);
}
}
void System::sendMsg(unsigned toNodeId, ScpMessage msg) {
nodes.at(toNodeId)->processMsg(msg);
}
bool System::getStatus() {
int value = -1;
bool status = false; //"Unknown";
int accepted_count = 0;
for(unsigned i = 0; i < nodes.size(); i++) {
NominationState* state = (nodes.at(i)->slots).at(0)->nominationState;
if(state->y > 0)
accepted_count++;
else
cout << "!!!! Node " << i << " was not able to accept !!!!\n";
// if (state->y >= 0) {
// if (value < 0) {
// value = state->y;
// }
// if (value == state->y) {
// status = "Agreed ";
// } else {
// status = "Stuck ";
// }
// }
}
return accepted_count == nodes.size();
}
void System::printStatus() {
string s = "";
for(unsigned i = 0 ; i < nodes.size(); i++) {
s += nodes.at(i)->getStatusString(i);
}
string st = ""; //getStatus();
cout << "Status: " + st + "Nodes: " + s << "\n";
}