-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnode.h
103 lines (87 loc) · 2.23 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
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
#ifndef NODE_H
#define NODE_H
#include<iostream>
#include<stdio.h>
#include<netdb.h>
#include<sys/socket.h>
#include<cstring>
#include<sstream>
#include<arpa/inet.h>
#include<pthread.h>
#include<stdlib.h>
#include<fstream>
#include<cstdlib>
#include<time.h>
#include<sys/time.h>
using namespace std;
#define MAX_NODES 10
#define HOST_PREFIX "net"
#define HOST_SUFFIX ".utdallas.edu"
#define HOST_RANGE_START 25
#define PORT_RANGE_START 1126
#define CS_LOG_FILE "cs_log_file"
#define MAX_CS_ENTRIES 40
#define MAX_BUFFER_SIZE 128
/***************************************
* GLOBAL VARIABLE Declaration
* *************************************/
int sockDesc[MAX_NODES];
int portNums[MAX_NODES];
int myId;
int mySeqNum, highestSeqNum, requestCount, replyCount;
int totalMessages, minMessages, maxMessages;
string hostNames[MAX_NODES];
string nodeDebugFile;
bool deferredReplies[MAX_NODES];
bool receivedReplies[MAX_NODES];
bool activeConnection[MAX_NODES];
bool completionStatus[MAX_NODES];
bool waiting, usingCS, receivedAllReplies, allNodesConnected, exitSession;
bool closeSockets = false;
pthread_t connThread;
pthread_t csThread;
pthread_mutex_t fileMutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t dataMutex = PTHREAD_MUTEX_INITIALIZER;
sockaddr_in nodeAddress[MAX_NODES];
ofstream csfStream;
ofstream dfStream;
/***************************************
* ENUM Declaration
* *************************************/
typedef enum
{
CS_REQUEST,
CS_REPLY,
CS_COMPLETION
}Message;
typedef enum
{
DEBUG,
CS_RECORD
}LogType;
/***************************************
* STRUCTURE Declaration
* *************************************/
typedef struct
{
int sockDesc;
sockaddr_in clientAddr;
int addrLen;
}Connection;
typedef struct
{
Message msgType;
int seqId;
int nodeId;
}CriticalSectionPacket;
/***************************************
* FUNCTION Declaration
* *************************************/
void* processControlMessages(void* ptr);
void* processCriticalSection(void* ptr);
void initializeGlobalData();
string packetToMessage(CriticalSectionPacket* pkt);
CriticalSectionPacket messageToPacket(string msg);
void logger(LogType type, string str);
int uniformDistGenerator(int min, int max);
#endif