-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.h
More file actions
101 lines (82 loc) · 2.57 KB
/
node.h
File metadata and controls
101 lines (82 loc) · 2.57 KB
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
// Patrick Brodie
#ifndef NODE_H_
#define NODE_H_
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <netdb.h>
#include <errno.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <time.h>
#include <dirent.h>
// ====== Message Types ======
#define I_AM_CAESAR 0 // Caesar's heartbeat. Only one permitted.
#define HEARTBEAT 1 // General's heartbeat.
#define REQUEST_TROOP_COUNT 2 // Caesar requests a general send a headcount.
#define REPLY_TROOP_LIST 3 // General replies with a headcount.
#define SEND_TROOPS 4 // Caesar orders troops to be sent.
#define REINFORCEMENT 5 // A message containing troops.
#define BEGIN_OVERANXIUS 6 // Order Overanxius to begin execution
#define OA_HEARTBEAT 7 // Overanxius' heartbeat
#define LIST 8 // Request to list all troops at a given general's camp
#define SEARCHREQ 9 // Find the general who has the given troop name.
#define GET 10 // Request that a trooper be transferred here from another camp.
#define BEGIN_P2P 11 // Begin the p2p program.
#define LIST_RESPONSE 12
#define SEARCH_RESPONSE 13
#define GET_RESPONSE 14
// ===========================
// ======= Gen. Status =======
#define UNKNOWN 0 // Heartbeat has not yet been registered.
#define READY 1 // Heartbeat has been registered.
// ===========================
// ======== Gen. Types =======
#define GENERAL 0 // Non-Caesar General
#define CAESAR 1 // Marker for Caesar
#define OVERANXIUS 2
// ===========================
struct msg {
int type;
int ownerid;
int relaytoid;
int dmeclock;
int vclock[4];
char text[512];
struct msg *next;
};
struct general {
int id;
int name;
int ready;
int port;
int replied;
char hostname[128];
struct sockaddr_in server_addr;
struct general *next;
};
// GLOBALS
struct general *genlist; // List of all generals.
struct general *caesar; // Pointer to caesar's general node.
struct general *overanxius; // Pointer to Overanxius' general node.
struct general *mygeneral; // Pointer to my general's node.
struct army *myarmy; // Pointer to my army.
struct genstate *mystate; // Struct for recording state.
int myid;
int myclock[5];
// PROTOTYPES
struct general *find_general (int);
void print_army (int);
void update_troop_count (struct army*, struct army*);
void zero_army (struct army*);
void reconcile_clocks (int*, int*);
void register_local_event ();
void copy_vclock (int*, int*);
void print_clock (int*);
void record_msg (struct msg*);
#endif