-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleend.h
109 lines (86 loc) · 2.84 KB
/
middleend.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
104
105
106
107
108
109
/* Mark Jia, mij623, 11271998
* */
#ifndef _MIDDLEEND_H_
#define _MIDDLEEND_H_
#include <netdb.h>
#include <stdint.h>
#include <queue.h>
#include <stdbool.h>
#include <list.h>
#define MALLOCMSG
#if UINTPTR_MAX == 0xffff /* 16-bit */
#define SYS_BITS 16
#define VOID_PTR_CAST uint16_t
#define INT_FMT "%d"
#elif UINTPTR_MAX == 0xffffffff /* 32-bit */
#define SYS_BITS 32
#define VOID_PTR_CAST uint32_t
#define INT_FMT "%d"
#elif UINTPTR_MAX == 0xffffffffffffffff /* 64-bit */
#define SYS_BITS 64
#define VOID_PTR_INT_CAST uint64_t
#define INT_FMT "%ld"
#else
#define VOID_PTR_INT_CAST int /* default int */
#define INT_FMT "%d"
#endif
#define PORTMAX 65535
#define PORTMIN 1024
#define MAX_MSG_SIZE 256
#define MAX_ADDR_LEN NI_MAXHOST
#define MAX_PORT_LEN NI_MAXSERV
#define MAX_DELAY 10 /* seconds */
typedef struct _endPointInfo{
char hostName[NI_MAXHOST]; /* Hostname, we only support 1 hostname here */
char portRcv[NI_MAXSERV]; /* port used for receiving */
char portSnd[NI_MAXSERV]; /* port used for sending */
} EndPointName; /* this is 1 row on the table */
typedef struct _lookupTable{
EndPointName* left; /* left endpoint */
EndPointName* right; /* right endpoint */
} LookupTable; /* this is the table */
/* arguments to each thread. */
typedef struct sender_info {
pthread_t thread_id; /* set by pthread_create, parent has access to */
char *send_to_host1;
char *send_to_port1;
char *send_to_host2;
char *send_to_port2;
int propgDelay; /* how often to check the queue */
QUEUE *messagesQ; /* list of messages */
pthread_mutex_t *QLock; /* lock for the list */
char *killMsg; /* message to end the conversation */
VOID_PTR_INT_CAST nSent1to2;
VOID_PTR_INT_CAST nSent2to1; /* statistics */
VOID_PTR_INT_CAST retVal;
LookupTable *nameTbl;
} Sender_info;
typedef struct receiver_info {
pthread_t thread_id;
char *receive_from_port;
float drop_prob; /* drop probility */
QUEUE *messagesQ; /* list of messages */
pthread_mutex_t *QLock; /* lock for the list */
char *killMsg; /* message to end the conversation */
VOID_PTR_INT_CAST nRecv1;
VOID_PTR_INT_CAST nRecv2; /* statistics */
VOID_PTR_INT_CAST retVal;
LookupTable *nameTbl;
} Receiver_info;
/* TODO: kill message should also be an argument
add it to sender info and receiver info, also refactor the routines. */
typedef struct _channelMsg {
struct sockaddr * fromAddr; /* fill with `theirAddr` */
socklen_t fromAddrLen; /* fill with `addr_len` */
char *msg;
} ChannelMsg;
void *send_thread(void *);
void *receive_thread(void *);
int check_args(char*, char*, char*, char*, char*);
struct addrinfo * pickToSend( struct addrinfo *,
struct addrinfo *,
struct sockaddr *, socklen_t,
LookupTable * );
bool sameAddr(struct sockaddr *, socklen_t,
struct sockaddr *, socklen_t);
#endif /* _MIDDLEEND_H_ */