-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.h
More file actions
76 lines (63 loc) · 1.59 KB
/
data.h
File metadata and controls
76 lines (63 loc) · 1.59 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
#ifndef DATA_H
#define DATA_H
#include <vector>
#include <cstring>
#include <cstdint>
#include <string>
#include <bitset>
using byte = unsigned char;
#ifdef _WIN32
using u_int8_t = unsigned char;
using u_int16_t = unsigned short;
using u_int32_t = unsigned;
#endif
enum class OperationResult { Timeout, Error, Success, ConnectionClosed, PartiallyFinished, NotConfirmed };
enum class ServerResponce:byte { Success, Error, Retry, Reset };
enum class ServerCommand:byte { Echo, FileTransferStart, FileTransferExecute, Identify };
struct Header
{
u_int8_t zero = 0;
u_int8_t id = 0;
u_int8_t needsConfirmation = 0;
u_int8_t command = 0;
u_int32_t packageSize;
};
struct FileInitPackage
{
Header header;
u_int32_t chunksCount;
u_int32_t chunkSize;
size_t fileSize;
char fileName[256] = {0};
FileInitPackage(u_int32_t chunksCount = 0, u_int32_t chunkSize = 0, size_t fileSize = 0)
{
this->chunksCount = chunksCount;
this->chunkSize = chunkSize;
this->fileSize = fileSize;
}
};
struct FileTransferPackage
{
Header header;
u_int8_t isMarker = 0;
u_int32_t chunkId = 0;
u_int32_t size = 0;
FileTransferPackage(u_int32_t chunkId = 0):chunkId(chunkId) {}
};
struct MarkerResponce
{
std::bitset<512> bits;
u_int32_t chunkId = 0;
};
constexpr size_t markerResponceSize = sizeof(MarkerResponce);
struct RedirectResponce
{
char newIp[18] = { 0 };
unsigned short newPort = 0;
};
struct ServerResponcePackage
{
u_int8_t responce;
ServerResponcePackage(u_int8_t responce = 0):responce(responce) {}
};
#endif // DATA_H