-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMP1Node.h
88 lines (80 loc) · 2.18 KB
/
MP1Node.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**********************************
* FILE NAME: MP1Node.cpp
*
* DESCRIPTION: Membership protocol run by this Node.
* Header file of MP1Node class.
**********************************/
#ifndef _MP1NODE_H_
#define _MP1NODE_H_
#include "EmulNet.h"
#include "Log.h"
#include "Member.h"
#include "Params.h"
#include "Queue.h"
#include "stdincludes.h"
/**
* Macros
*/
#define TREMOVE 20
#define TFAIL 4
/**
* Message Types
*/
enum MsgTypes { JOINREQ, JOINREP, DELETE, PING, PINGREQ, ACK };
/**
* STRUCT NAME: MessageHdr
*
* DESCRIPTION: Header and content of a message
*/
typedef struct MessageHdr {
enum MsgTypes msgType;
vector<MemberListEntry> memberList;
Address srcAddr;
Address endAddr;
} MessageHdr;
/**
* CLASS NAME: MP1Node
*
* DESCRIPTION: Class implementing Membership protocol functionalities for
* failure detection
*/
class MP1Node {
private:
EmulNet *emulNet;
Log *log;
Params *par;
Member *memberNode;
bool finishedPING;
Address pingTarget;
size_t posInMemberList;
char NULLADDR[6];
public:
MP1Node(Member *, Params *, EmulNet *, Log *, Address *);
Member *getMemberNode() { return memberNode; }
int recvLoop();
static int enqueueWrapper(void *env, char *buff, int size);
void nodeStart(char *servaddrstr, short serverport);
int initThisNode(Address *joinaddr);
int introduceSelfToGroup(Address *joinAddress);
int finishUpThisNode();
void nodeLoop();
void checkMessages();
bool recvCallBack(Member *memberNode, MessageHdr *data, int size);
void nodeLoopOps();
int isNullAddress(Address *addr);
Address getJoinAddress();
void initMemberListTable(Member *memberNode);
virtual ~MP1Node();
bool deleteNode(Address *deleteNodeAddr);
bool sendFailedNode();
bool startPing();
bool startPingREQ();
// subFunctions for recvCallBack
bool handleJoinReq(MessageHdr *msg, int size);
bool handleJoinReply(MessageHdr *msg, int size);
bool handlePing(MessageHdr *msg, int size);
bool handlePingReq(MessageHdr *msg, int size);
bool handleAck(MessageHdr *msg, int size);
bool handleDelete(MessageHdr *msg, int size);
};
#endif /* _MP1NODE_H_ */