-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession.cpp
More file actions
executable file
·287 lines (240 loc) · 6.89 KB
/
session.cpp
File metadata and controls
executable file
·287 lines (240 loc) · 6.89 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*
Copyright (c) 2006, Arvid Norberg, Magnus Jonsson
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctime>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <set>
#include <cctype>
#include <algorithm>
#ifdef _MSC_VER
#pragma warning(push, 1)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/limits.hpp>
#include <boost/bind.hpp>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include "libtorrent/peer_id.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/tracker_manager.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/hasher.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/fingerprint.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/alert_types.hpp"
#include "libtorrent/invariant_check.hpp"
#include "libtorrent/file.hpp"
#include "libtorrent/allocate_resources.hpp"
#include "libtorrent/bt_peer_connection.hpp"
#include "libtorrent/ip_filter.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/aux_/session_impl.hpp"
#include "libtorrent/kademlia/dht_tracker.hpp"
using namespace boost::posix_time;
using boost::shared_ptr;
using boost::weak_ptr;
using boost::bind;
using boost::mutex;
using libtorrent::aux::session_impl;
namespace libtorrent
{
session::session(
fingerprint const& id
, std::pair<int, int> listen_port_range
, char const* listen_interface)
: m_impl(new session_impl(listen_port_range, id, listen_interface))
{
// turn off the filename checking in boost.filesystem
using namespace boost::filesystem;
if (path::default_name_check_writable())
path::default_name_check(no_check);
assert(listen_port_range.first > 0);
assert(listen_port_range.first < listen_port_range.second);
#ifndef NDEBUG
// this test was added after it came to my attention
// that devstudios managed c++ failed to generate
// correct code for boost.function
boost::function0<void> test = boost::ref(*m_impl);
assert(!test.empty());
#endif
}
session::session(fingerprint const& id)
: m_impl(new session_impl(std::make_pair(0, 0), id))
{
#ifndef NDEBUG
boost::function0<void> test = boost::ref(*m_impl);
assert(!test.empty());
#endif
}
session::~session()
{
assert(m_impl);
// if there is at least one destruction-proxy
// abort the session and let the destructor
// of the proxy to syncronize
if (!m_impl.unique())
m_impl->abort();
}
void session::disable_extensions()
{
m_impl->disable_extensions();
}
void session::set_ip_filter(ip_filter const& f)
{
m_impl->set_ip_filter(f);
}
void session::set_peer_id(peer_id const& id)
{
m_impl->set_peer_id(id);
}
void session::set_key(int key)
{
m_impl->set_key(key);
}
void session::enable_extension(extension_index i)
{
m_impl->enable_extension(i);
}
std::vector<torrent_handle> session::get_torrents() const
{
return m_impl->get_torrents();
}
// if the torrent already exists, this will throw duplicate_torrent
torrent_handle session::add_torrent(
torrent_info const& ti
, boost::filesystem::path const& save_path
, entry const& resume_data
, bool compact_mode
, int block_size)
{
return m_impl->add_torrent(ti, save_path, resume_data
, compact_mode, block_size);
}
torrent_handle session::add_torrent(
char const* tracker_url
, sha1_hash const& info_hash
, boost::filesystem::path const& save_path
, entry const& e
, bool compact_mode
, int block_size)
{
return m_impl->add_torrent(tracker_url, info_hash, save_path, e
, compact_mode, block_size);
}
void session::remove_torrent(const torrent_handle& h)
{
m_impl->remove_torrent(h);
}
bool session::listen_on(
std::pair<int, int> const& port_range
, const char* net_interface)
{
return m_impl->listen_on(port_range, net_interface);
}
unsigned short session::listen_port() const
{
return m_impl->listen_port();
}
session_status session::status() const
{
return m_impl->status();
}
#ifndef TORRENT_DISABLE_DHT
void session::start_dht(entry const& startup_state)
{
m_impl->start_dht(startup_state);
}
void session::stop_dht()
{
m_impl->stop_dht();
}
void session::set_dht_settings(dht_settings const& settings)
{
m_impl->set_dht_settings(settings);
}
entry session::dht_state() const
{
return m_impl->dht_state();
}
void session::add_dht_node(std::pair<std::string, int> const& node)
{
m_impl->add_dht_node(node);
}
void session::add_dht_router(std::pair<std::string, int> const& node)
{
m_impl->add_dht_router(node);
}
#endif
bool session::is_listening() const
{
return m_impl->is_listening();
}
void session::set_settings(session_settings const& s)
{
m_impl->set_settings(s);
}
session_settings const& session::settings()
{
return m_impl->settings();
}
void session::set_max_uploads(int limit)
{
m_impl->set_max_uploads(limit);
}
void session::set_max_connections(int limit)
{
m_impl->set_max_connections(limit);
}
void session::set_max_half_open_connections(int limit)
{
m_impl->set_max_half_open_connections(limit);
}
void session::set_upload_rate_limit(int bytes_per_second)
{
m_impl->set_upload_rate_limit(bytes_per_second);
}
void session::set_download_rate_limit(int bytes_per_second)
{
m_impl->set_download_rate_limit(bytes_per_second);
}
std::auto_ptr<alert> session::pop_alert()
{
return m_impl->pop_alert();
}
void session::set_severity_level(alert::severity_t s)
{
m_impl->set_severity_level(s);
}
}