-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.h
71 lines (48 loc) · 1.41 KB
/
node.h
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
#include<commons.h>
class Node {
char* constructJoinRespMessage(long uoid,
long distance,
char[] hostName,
char[] hostPort,
Header hdr,
u_int msgType) {
int msgLen = 52 + strlen(hostName);
char* msg = (char*)malloc(msgLen * sizeof(char));
// TODO: construct
return msg;
}
char* constructJoinReqMessage(Header hdr,
uint32_t hostLoc,
char[] hostName,
char[] hostPort) {
int msgLen = 32 + strlen(hostName);
char* msg = (char*)malloc(msgLen * sizeof(char));
hdr.dataLength = strlen(hostName)+6;
memcpy((void*)msg ,(void*)hdr ,27) //Copy the common header
memcpy((void*)(msg+27),(void*)&hostLoc,4);
memcpy((void*)(msg+31),(void*)hostPort,2);
memcpy((void*)(msg+33),(void*)hostName,strlen(hostName));
return msg;
}
}
class StateTransitionFSM {
int rowSize = 3;
int colSize = 8;
int[] row = {STATUS_SHUTDOWN, STATUS_DISCOVERY, STATUS_NETWORK_READY};
int[] col = {JOIN_REQ, JOIN_RSP, HELLO_REQ, NOTIFY, KEEPALIVE, CHECK_RSP, CHECK_REQ, DEFAULT};
int[][] states = { {} , {}, {}, {}, {}, {}, {} };
int getState(int inputState, int currState) {
int iInput=0; iState=0;
for(int i=0; i<rowSize; i++) {
if(row[i] == inputState) {
iInput = i
}
}
for(int i=0; i<colSize; i++) {
if(colk[i] == currState) {
iState = i;
}
}
return states[iInput][iState];
}
}