-
Notifications
You must be signed in to change notification settings - Fork 0
/
Receiver.h
69 lines (59 loc) · 1.68 KB
/
Receiver.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
/*
* Receiver.h
*
*/
#ifndef _RECEIVER_H_
#define _RECEIVER_H_
#include <iostream>
#include <time.h>
#include "Transmission.h"
#include "TransmissionTimer.h"
#include "DiskBuffer.h"
#include "Mutex.h"
using namespace std;
enum ReceiverState
{
RECV_NO_CONN,
RECV_DATA,
RECV_FIN
};
class Receiver {
public:
Receiver(unsigned short port);
virtual ~Receiver();
void Start();
private:
int _ConfigureSocket(unsigned short port);
void _StartRecvCheck();
void _ParseMessage(struct sockaddr_in* senderAddr, char* buff, uint32_t size);
void _ParseSyn(struct sockaddr_in* senderAddr, char* buff, uint32_t size, uint64_t seqNum);
void _ParseData(struct sockaddr_in* senderAddr, char* buff, uint32_t size, uint64_t seqNum);
void _ParseFin(struct sockaddr_in* senderAddr, char* buff, uint32_t size, uint64_t seqNum);
void _BuildAckPacket(char packet[kAckPacketSize]);
void _SendAck(bool isRetransmit);
void _SetSenderAddr(struct sockaddr_in* senderAddr, bool copy);
void _UpdateRtt();
void _AckTimeOut();
static void _TimeOutCallBack(void* caller);
TransmissionTimer* mTransTimer;
DiskBuffer *mDiskBuffer;
Mutex mPacketLock;
ReceiverState mCurrentState;
bool mIsStarted;
struct timeval mConnStartTime;
struct timeval mConnEndTime;
struct timeval mRttStartTime;
struct timeval mRttEndTime;
unsigned short mPort;
struct sockaddr_in* mSenderAddr;
int mSocket;
uint64_t mFileSize;
uint64_t mTotalReceived;
uint64_t mLastAck;
string mFileName;
uint32_t mEstRtt; // Estimated round trip time.
int mDevRtt; // Deviation of round trip time.
uint32_t mTimeOutInterval;
bool mLastAckRetransmit;
};
#endif