-
Notifications
You must be signed in to change notification settings - Fork 20
/
messages.hpp
115 lines (97 loc) · 2.1 KB
/
messages.hpp
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
/*
utrack is a very small an efficient BitTorrent tracker
Copyright (C) 2011 Arvid Norberg
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _MESSAGES_HPP_
#define _MESSAGES_HPP_
#include <stdint.h>
#include <string.h>
struct sha1_hash
{
uint32_t val[5];
};
inline bool operator==(sha1_hash const& lhs, sha1_hash const& rhs)
{
return memcmp(lhs.val, rhs.val, 20) == 0;
}
enum
{
max_scrape_responses = 71
};
#pragma pack (push)
struct udp_announce_message
{
uint64_t connection_id;
uint32_t action;
uint32_t transaction_id;
sha1_hash hash;
sha1_hash peer_id;
int64_t downloaded;
int64_t left;
int64_t uploaded;
int32_t event;
uint32_t ip;
uint32_t key;
int32_t num_want;
uint16_t port;
uint16_t extensions;
};
struct udp_scrape_message
{
uint64_t connection_id;
uint32_t action;
uint32_t transaction_id;
sha1_hash hash[max_scrape_responses];
};
struct udp_connect_response
{
uint32_t action;
uint32_t transaction_id;
uint64_t connection_id;
};
struct udp_announce_response
{
uint32_t action;
uint32_t transaction_id;
uint32_t interval;
uint32_t downloaders;
uint32_t seeds;
};
struct udp_scrape_data
{
uint32_t downloaders;
uint32_t download_count;
uint32_t seeds;
};
struct udp_scrape_response
{
uint32_t action;
uint32_t transaction_id;
udp_scrape_data data[71];
};
#pragma pack(pop)
enum action_t
{
action_connect = 0,
action_announce = 1,
action_scrape = 2,
action_error = 3
};
enum event_t
{
event_none = 0,
event_completed = 1,
event_started = 2,
event_stopped = 3
};
#endif