added some precautionary checks in bdecoder
[libtorrent.git] / include / libtorrent / peer_info.hpp
blobc85069bff1d8f4cbdcda09067656404400455a71
1 /*
3 Copyright (c) 2003, Arvid Norberg
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the distribution.
15 * Neither the name of the author nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE.
33 #ifndef TORRENT_PEER_INFO_HPP_INCLUDED
34 #define TORRENT_PEER_INFO_HPP_INCLUDED
36 #include "libtorrent/socket.hpp"
37 #include "libtorrent/peer_id.hpp"
38 #include "libtorrent/size_type.hpp"
39 #include "libtorrent/config.hpp"
40 #include "libtorrent/bitfield.hpp"
42 namespace libtorrent
44 struct TORRENT_EXPORT peer_info
46 enum
48 interesting = 0x1,
49 choked = 0x2,
50 remote_interested = 0x4,
51 remote_choked = 0x8,
52 supports_extensions = 0x10,
53 local_connection = 0x20,
54 handshake = 0x40,
55 connecting = 0x80,
56 queued = 0x100,
57 on_parole = 0x200,
58 seed = 0x400,
59 optimistic_unchoke = 0x800,
60 snubbed = 0x1000,
61 upload_only = 0x2000
62 #ifndef TORRENT_DISABLE_ENCRYPTION
63 , rc4_encrypted = 0x100000,
64 plaintext_encrypted = 0x200000
65 #endif
68 unsigned int flags;
70 enum peer_source_flags
72 tracker = 0x1,
73 dht = 0x2,
74 pex = 0x4,
75 lsd = 0x8,
76 resume_data = 0x10,
77 incoming = 0x20
80 int source;
82 // bw_idle: the channel is not used
83 // bw_torrent: the channel is waiting for torrent quota
84 // bw_global: the channel is waiting for global quota
85 // bw_network: the channel is waiting for an async write
86 // for read operation to complete
87 enum bw_state { bw_idle, bw_torrent, bw_global, bw_network };
89 char read_state;
90 char write_state;
92 tcp::endpoint ip;
93 float up_speed;
94 float down_speed;
95 float payload_up_speed;
96 float payload_down_speed;
97 size_type total_download;
98 size_type total_upload;
99 peer_id pid;
100 bitfield pieces;
101 int upload_limit;
102 int download_limit;
104 // time since last request
105 time_duration last_request;
107 // time since last download or upload
108 time_duration last_active;
110 // the number of seconds until the current
111 // pending request times out
112 int request_timeout;
114 // the size of the send buffer for this peer, in bytes
115 int send_buffer_size;
116 // the number bytes that's actually used of the send buffer
117 int used_send_buffer;
119 int receive_buffer_size;
120 int used_receive_buffer;
122 // the number of failed hashes for this peer
123 int num_hashfails;
125 #ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
126 // in case the session settings is set
127 // to resolve countries, this is set to
128 // the two character country code this
129 // peer resides in.
130 char country[2];
131 #endif
133 #ifndef TORRENT_DISABLE_GEO_IP
134 // atonomous system this peer belongs to
135 std::string inet_as_name;
136 int inet_as;
137 #endif
139 size_type load_balancing;
141 // this is the number of requests
142 // we have sent to this peer
143 // that we haven't got a response
144 // for yet
145 int download_queue_length;
147 // the number of request messages
148 // waiting to be sent inside the send buffer
149 int requests_in_buffer;
151 // the number of requests that is
152 // tried to be maintained (this is
153 // typically a function of download speed)
154 int target_dl_queue_length;
156 // this is the number of requests
157 // the peer has sent to us
158 // that we haven't sent yet
159 int upload_queue_length;
161 // the number of times this IP
162 // has failed to connect
163 int failcount;
165 // the currently downloading piece
166 // if piece index is -1 all associated
167 // members are just set to 0
168 int downloading_piece_index;
169 int downloading_block_index;
170 int downloading_progress;
171 int downloading_total;
173 std::string client;
175 enum
177 standard_bittorrent = 0,
178 web_seed = 1
180 int connection_type;
182 // approximate peer download rate
183 int remote_dl_rate;
185 // number of bytes this peer has in
186 // the disk write queue
187 int pending_disk_bytes;
189 // numbers used for bandwidth limiting
190 int send_quota;
191 int receive_quota;
193 // estimated rtt to peer, in milliseconds
194 int rtt;
196 // the highest transfer rates seen for this peer
197 int download_rate_peak;
198 int upload_rate_peak;
201 struct TORRENT_EXPORT peer_list_entry
203 enum flags_t
205 banned = 1,
208 tcp::endpoint ip;
209 int flags;
210 boost::uint8_t failcount;
211 boost::uint8_t source;
215 #endif // TORRENT_PEER_INFO_HPP_INCLUDED