forked from plrectco/GossipMembership
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MP1Node.h
98 lines (81 loc) · 2.01 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
89
90
91
92
93
94
95
96
97
98
/**********************************
* FILE NAME: MP1Node.cpp
*
* DESCRIPTION: Membership protocol run by this Node.
* Header file of MP1Node class.
**********************************/
#ifndef _MP1NODE_H_
#define _MP1NODE_H_
#include "stdincludes.h"
#include "Log.h"
#include "Params.h"
#include "Member.h"
#include "EmulNet.h"
#include "Queue.h"
/**
* Macros
*/
#define TREMOVE 10
#define TFAIL 5
#define TGOSSIP 1
/*
* Note: You can change/add any functions in MP1Node.{h,cpp}
*/
/**
* Message Types
*/
enum MsgTypes{
JOINREQ,
JOINREP,
GOSSIP,
DUMMYLASTMSGTYPE
};
/**
* STRUCT NAME: MessageHdr
*
* DESCRIPTION: Header and content of a message
*/
typedef struct MessageHdr {
enum MsgTypes msgType;
}MessageHdr;
/**
* CLASS NAME: MP1Node
*
* DESCRIPTION: Class implementing Membership protocol functionalities for failure detection
*/
class MP1Node {
private:
EmulNet *emulNet;
Log *log;
Params *par;
Member *memberNode;
char NULLADDR[6];
long localtime;
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(void *env, char *data, int size);
void nodeLoopOps();
int isNullAddress(Address *addr);
Address getJoinAddress();
void initMemberListTable(Member *memberNode);
void printAddress(Address *addr);
virtual ~MP1Node();
Address getMemberAddress(MemberListEntry &member);
bool updateMemberList(Address *src, long *heartbeat, long timestamp);
void heartBeating();
void sendMemberList(Address *dst, MsgTypes type);
bool handleGossip(Address *src, char *data, size_t size);
void checkFailure();
};
#endif /* _MP1NODE_H_ */