-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataStructures.h
169 lines (153 loc) · 4.28 KB
/
dataStructures.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifndef DATASTRUCTURES_H
#define DATASTRUCTURES_H
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#include <stdio.h>
//--------------------------------------------------------------------------------------------------------STRUTTURE DATI
//#define WINDOWSIZE 2048
//#define TIMERSIZE 2048
//#define LOSSPROB 100
//#define BASETIMER 200
#define PORT 4242
struct timer
{
volatile int seqNum;
struct timer * nextTimer;
volatile int posInWheel;
volatile short int isValid;
};
struct selectCell
{
int value;
struct timer packetTimer;
pthread_mutex_t cellMtx;
};
typedef struct datagram_t
{
volatile int command;
int opID;
int seqNum;
int ackSeqNum;
short int isFinal;
ssize_t packetLen;
char content[512];
} datagram;
typedef struct handshake_t
{
int ack; //se vale 1 sto ackando il precedente
int sequenceNum;
short int isFinal;
} handshake;
struct details
{
struct sockaddr_in addr;
struct sockaddr_in addr2;
int sockfd;
int sockfd2;
socklen_t Size;
socklen_t Size2;
int remoteSeq;
int mySeq;
int volatile sendBase;
int volatile firstSeqNum;
};
struct headTimer
{
struct timer * nextTimer;
};
struct pipeMessage
{
int seqNum;
short int isFinal;
};
struct RTTsample
{
int seqNum;
long timestamp;
long RTT;
long previousEstimate;
};
//-------------------------------------------------------------------------------------------------------------PROTOTIPI
//A
void ackSentPacket(int ackN);
void ACKandRTXcycle(int socketfd, struct sockaddr_in * servAddr, socklen_t servLen, int command);
void acceptConnection(int mainSocket, handshake * ACK, struct sockaddr * address, socklen_t *slen);
//B
void bindSocket(int sockfd, struct sockaddr * address , socklen_t size);
//C
void clockTick();
int checkPipe(struct pipeMessage *rtxN, int pipefd);
int createSocket();
void createThread(pthread_t * thread, void * function, void * arguments);
int checkSocketAck(struct sockaddr_in * servAddr, socklen_t servLen, int socketfd, handshake * ACK);
int checkSocketDatagram(struct sockaddr_in * servAddr, socklen_t servLen, int socketfd, datagram * packet);
void closeFile(int fd);
void condWaitSender(pthread_mutex_t * mutex, pthread_cond_t *cond, int connection);
int canISend();
//D
//E
//F
//G
int getRTTseq();
int getOpID();
int getSendBase();
int getSeqNum();
int getFileLen(int fd);
int getWheelPosition();
int getDataError();
void getResponse(int socket, struct sockaddr_in * address, socklen_t *slen, int fd, int command);
int getCurrentTimeSlot();
int getGlobalSenderWait();
//H
//I
void initTimerWheel();
void initWindow(int times);
void initPipe(int pipefd[2]);
void incrementRounds();
//J
//K
//L
//M
void mtxLock(pthread_mutex_t * mtx);
void mtxUnlock(pthread_mutex_t * mtx);
//N
//O
int openFile(char * fileName);
//P
//Q
//R
unsigned int randomGen();
int receiveACK(int mainSocket, struct sockaddr * address, socklen_t *slen);
datagram rebuildDatagram(int fd, struct pipeMessage pm, int command);
int readGlobalTimerStop();
void resetDataError();
//S
void startTimer(int packetN, int posInWheel);
void sentPacket(int packetN, int retransmission);
void slideWindow();
void sendDatagram(int socketfd, struct sockaddr_in * servAddr, socklen_t servLen, struct datagram_t * sndPacket, int rtx);
void sendACK(int socketfd, handshake *ACK, struct sockaddr_in * servAddr, socklen_t servLen);
struct sockaddr_in createStruct(unsigned short portN);
void sendSignalThread(pthread_mutex_t * mtx, pthread_cond_t * condition, int connection);
char * stringParser(char * string);
void sendSignalTimer();
void setDataError();
void startRTTsample(int seq);
//T
void * timerFunction();
void tellSenderSendACK(int packetN, short int isFinal);
void takingRTT();
//U
long updateRTTavg(long previousEstimate, long newRTT);
//V
//W
void waitForFirstPacketSender(int socketfd, struct sockaddr_in * servAddr, socklen_t servLen);
void waitForFirstPacketListener(int socketfd, struct sockaddr_in * servAddr, socklen_t servLen);
void writeOnFile(int file, char * content, int seqnum, int firstnum ,size_t len);
void waitForAckCycle(int socket, struct sockaddr * address, socklen_t *slen);
//X
//Y
//Z
//----------------------------------------------------------------------------------------------------------------------
#endif //DATASTRUCTURES_H