-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp2p.h
87 lines (71 loc) · 1.48 KB
/
p2p.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
/*
COMP3331 Assignment
Written by Joshua Z
Student ID: z5196042
*/
#ifndef P2P_H
#define P2P_H
#include <arpa/inet.h>
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <threads.h>
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
#include <ctype.h>
#include "List.h"
#include "functions.h"
// message types
#define REQUEST 0
#define RESPONSE 1
#define JOIN_REQUEST 2
#define CHANGE_REQUEST 3
#define QUIT_REQUEST 4
#define QUIT_CHANGE 5
#define QUIT_NOW 6
#define STORE_REQUEST 7
#define RETRIEVE_REQUEST 8
#define RETRIEVE_RESPONSE 9
// quit types
#define ABRUPT 0
#define GRACEFULLY 1
// peer statuses
#define NORMAL 0
#define JOINING 1
#define DEPARTING 2
// address info
#define SERVER_PORT 12200
#define LOCALHOST "127.0.0.1"
// commands
#define INIT "init"
#define JOIN "join"
#define QUIT "quit\n"
#define STORE "store"
#define REQ "request"
#define TRUE 1
#define FALSE 0
// Messages sent over the network will use this struct
struct message {
int sender;
int type;
int origin;
int known;
int newFirst;
int newSecond;
char payload[1000];
};
typedef struct message *Message;
// list of filenames
List fileList;
int peerID;
int fsID;
int ssID;
int pingInterval;
int status;
int knownPeer;
char type[5];
int lostPings[2];
#endif