mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-27 02:20:32 +00:00
libtorrent sync 1442
This commit is contained in:
parent
51376bd2be
commit
28ad94ea6e
@ -90,47 +90,47 @@ struct bandwidth_limit
|
|||||||
{
|
{
|
||||||
static const int inf = boost::integer_traits<int>::const_max;
|
static const int inf = boost::integer_traits<int>::const_max;
|
||||||
|
|
||||||
bandwidth_limit()
|
bandwidth_limit() throw()
|
||||||
: m_quota_left(0)
|
: m_quota_left(0)
|
||||||
, m_local_limit(inf)
|
, m_local_limit(inf)
|
||||||
, m_current_rate(0)
|
, m_current_rate(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void throttle(int limit)
|
void throttle(int limit) throw()
|
||||||
{
|
{
|
||||||
m_local_limit = limit;
|
m_local_limit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
int throttle() const
|
int throttle() const throw()
|
||||||
{
|
{
|
||||||
return m_local_limit;
|
return m_local_limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
void assign(int amount)
|
void assign(int amount) throw()
|
||||||
{
|
{
|
||||||
assert(amount > 0);
|
assert(amount > 0);
|
||||||
m_current_rate += amount;
|
m_current_rate += amount;
|
||||||
m_quota_left += amount;
|
m_quota_left += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void use_quota(int amount)
|
void use_quota(int amount) throw()
|
||||||
{
|
{
|
||||||
assert(amount <= m_quota_left);
|
assert(amount <= m_quota_left);
|
||||||
m_quota_left -= amount;
|
m_quota_left -= amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int quota_left() const
|
int quota_left() const throw()
|
||||||
{
|
{
|
||||||
return (std::max)(m_quota_left, 0);
|
return (std::max)(m_quota_left, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void expire(int amount)
|
void expire(int amount) throw()
|
||||||
{
|
{
|
||||||
assert(amount >= 0);
|
assert(amount >= 0);
|
||||||
m_current_rate -= amount;
|
m_current_rate -= amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int max_assignable() const
|
int max_assignable() const throw()
|
||||||
{
|
{
|
||||||
if (m_local_limit == inf) return inf;
|
if (m_local_limit == inf) return inf;
|
||||||
if (m_local_limit <= m_current_rate) return 0;
|
if (m_local_limit <= m_current_rate) return 0;
|
||||||
@ -160,7 +160,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
T clamp(T val, T ceiling, T floor)
|
T clamp(T val, T ceiling, T floor) throw()
|
||||||
{
|
{
|
||||||
assert(ceiling >= floor);
|
assert(ceiling >= floor);
|
||||||
if (val >= ceiling) return ceiling;
|
if (val >= ceiling) return ceiling;
|
||||||
@ -171,7 +171,7 @@ T clamp(T val, T ceiling, T floor)
|
|||||||
template<class PeerConnection, class Torrent>
|
template<class PeerConnection, class Torrent>
|
||||||
struct bandwidth_manager
|
struct bandwidth_manager
|
||||||
{
|
{
|
||||||
bandwidth_manager(io_service& ios, int channel)
|
bandwidth_manager(io_service& ios, int channel) throw()
|
||||||
: m_ios(ios)
|
: m_ios(ios)
|
||||||
, m_history_timer(m_ios)
|
, m_history_timer(m_ios)
|
||||||
, m_limit(bandwidth_limit::inf)
|
, m_limit(bandwidth_limit::inf)
|
||||||
@ -179,14 +179,14 @@ struct bandwidth_manager
|
|||||||
, m_channel(channel)
|
, m_channel(channel)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void throttle(int limit)
|
void throttle(int limit) throw()
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
assert(limit >= 0);
|
assert(limit >= 0);
|
||||||
m_limit = limit;
|
m_limit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
int throttle() const
|
int throttle() const throw()
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
return m_limit;
|
return m_limit;
|
||||||
@ -197,7 +197,7 @@ struct bandwidth_manager
|
|||||||
// this is used by web seeds
|
// this is used by web seeds
|
||||||
void request_bandwidth(intrusive_ptr<PeerConnection> peer
|
void request_bandwidth(intrusive_ptr<PeerConnection> peer
|
||||||
, int blk
|
, int blk
|
||||||
, bool non_prioritized)
|
, bool non_prioritized) throw()
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
assert(blk > 0);
|
assert(blk > 0);
|
||||||
@ -257,8 +257,11 @@ struct bandwidth_manager
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void add_history_entry(history_entry<PeerConnection, Torrent> const& e) try
|
void add_history_entry(history_entry<PeerConnection, Torrent> const& e) throw()
|
||||||
{
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
try {
|
||||||
|
#endif
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
m_history.push_front(e);
|
m_history.push_front(e);
|
||||||
m_current_quota += e.amount;
|
m_current_quota += e.amount;
|
||||||
@ -268,11 +271,17 @@ private:
|
|||||||
|
|
||||||
m_history_timer.expires_at(e.expires_at);
|
m_history_timer.expires_at(e.expires_at);
|
||||||
m_history_timer.async_wait(bind(&bandwidth_manager::on_history_expire, this, _1));
|
m_history_timer.async_wait(bind(&bandwidth_manager::on_history_expire, this, _1));
|
||||||
|
#ifndef NDEBUG
|
||||||
|
}
|
||||||
|
catch (std::exception&) { assert(false); }
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
catch (std::exception&) { assert(false); }
|
|
||||||
|
|
||||||
void on_history_expire(asio::error_code const& e) try
|
void on_history_expire(asio::error_code const& e) throw()
|
||||||
{
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
try {
|
||||||
|
#endif
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
if (e) return;
|
if (e) return;
|
||||||
@ -303,14 +312,20 @@ private:
|
|||||||
// means we can hand out more (in case there
|
// means we can hand out more (in case there
|
||||||
// are still consumers in line)
|
// are still consumers in line)
|
||||||
if (!m_queue.empty()) hand_out_bandwidth();
|
if (!m_queue.empty()) hand_out_bandwidth();
|
||||||
|
#ifndef NDEBUG
|
||||||
|
}
|
||||||
|
catch (std::exception&)
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
catch (std::exception&)
|
|
||||||
{
|
|
||||||
assert(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
void hand_out_bandwidth() try
|
void hand_out_bandwidth() throw()
|
||||||
{
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
try {
|
||||||
|
#endif
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
ptime now(time_now());
|
ptime now(time_now());
|
||||||
@ -404,9 +419,12 @@ private:
|
|||||||
add_history_entry(history_entry<PeerConnection, Torrent>(
|
add_history_entry(history_entry<PeerConnection, Torrent>(
|
||||||
qe.peer, t, hand_out_amount, now + bw_window_size));
|
qe.peer, t, hand_out_amount, now + bw_window_size));
|
||||||
}
|
}
|
||||||
|
#ifndef NDEBUG
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{ assert(false); };
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
|
||||||
{ assert(false); };
|
|
||||||
|
|
||||||
|
|
||||||
typedef boost::mutex mutex_t;
|
typedef boost::mutex mutex_t;
|
||||||
|
@ -48,9 +48,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ac_cxx_namespaces.m4 \
|
|||||||
$(top_srcdir)/m4/ax_boost_program_options.m4 \
|
$(top_srcdir)/m4/ax_boost_program_options.m4 \
|
||||||
$(top_srcdir)/m4/ax_boost_regex.m4 \
|
$(top_srcdir)/m4/ax_boost_regex.m4 \
|
||||||
$(top_srcdir)/m4/ax_boost_thread.m4 \
|
$(top_srcdir)/m4/ax_boost_thread.m4 \
|
||||||
$(top_srcdir)/m4/check_ssl.m4 $(top_srcdir)/m4/libtool.m4 \
|
$(top_srcdir)/m4/check_ssl.m4 $(top_srcdir)/configure.in
|
||||||
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
|
|
||||||
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/configure.in
|
|
||||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||||
$(ACLOCAL_M4)
|
$(ACLOCAL_M4)
|
||||||
mkinstalldirs = $(install_sh) -d
|
mkinstalldirs = $(install_sh) -d
|
||||||
@ -65,9 +63,8 @@ am__installdirs = "$(DESTDIR)$(libdir)"
|
|||||||
libLTLIBRARIES_INSTALL = $(INSTALL)
|
libLTLIBRARIES_INSTALL = $(INSTALL)
|
||||||
LTLIBRARIES = $(lib_LTLIBRARIES)
|
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||||
libtorrent_la_DEPENDENCIES =
|
libtorrent_la_DEPENDENCIES =
|
||||||
am__libtorrent_la_SOURCES_DIST = allocate_resources.cpp \
|
am__libtorrent_la_SOURCES_DIST = allocate_resources.cpp entry.cpp \
|
||||||
bandwidth_manager.cpp entry.cpp escape_string.cpp \
|
escape_string.cpp peer_connection.cpp bt_peer_connection.cpp \
|
||||||
peer_connection.cpp bt_peer_connection.cpp \
|
|
||||||
web_peer_connection.cpp natpmp.cpp piece_picker.cpp policy.cpp \
|
web_peer_connection.cpp natpmp.cpp piece_picker.cpp policy.cpp \
|
||||||
session.cpp session_impl.cpp sha1.cpp stat.cpp storage.cpp \
|
session.cpp session_impl.cpp sha1.cpp stat.cpp storage.cpp \
|
||||||
torrent.cpp torrent_handle.cpp pe_crypto.cpp torrent_info.cpp \
|
torrent.cpp torrent_handle.cpp pe_crypto.cpp torrent_info.cpp \
|
||||||
@ -86,12 +83,12 @@ am__libtorrent_la_SOURCES_DIST = allocate_resources.cpp \
|
|||||||
@USE_DHT_TRUE@ find_data.lo node.lo node_id.lo refresh.lo \
|
@USE_DHT_TRUE@ find_data.lo node.lo node_id.lo refresh.lo \
|
||||||
@USE_DHT_TRUE@ routing_table.lo rpc_manager.lo \
|
@USE_DHT_TRUE@ routing_table.lo rpc_manager.lo \
|
||||||
@USE_DHT_TRUE@ traversal_algorithm.lo
|
@USE_DHT_TRUE@ traversal_algorithm.lo
|
||||||
am_libtorrent_la_OBJECTS = allocate_resources.lo bandwidth_manager.lo \
|
am_libtorrent_la_OBJECTS = allocate_resources.lo entry.lo \
|
||||||
entry.lo escape_string.lo peer_connection.lo \
|
escape_string.lo peer_connection.lo bt_peer_connection.lo \
|
||||||
bt_peer_connection.lo web_peer_connection.lo natpmp.lo \
|
web_peer_connection.lo natpmp.lo piece_picker.lo policy.lo \
|
||||||
piece_picker.lo policy.lo session.lo session_impl.lo sha1.lo \
|
session.lo session_impl.lo sha1.lo stat.lo storage.lo \
|
||||||
stat.lo storage.lo torrent.lo torrent_handle.lo pe_crypto.lo \
|
torrent.lo torrent_handle.lo pe_crypto.lo torrent_info.lo \
|
||||||
torrent_info.lo tracker_manager.lo http_connection.lo \
|
tracker_manager.lo http_connection.lo \
|
||||||
http_tracker_connection.lo udp_tracker_connection.lo alert.lo \
|
http_tracker_connection.lo udp_tracker_connection.lo alert.lo \
|
||||||
identify_client.lo ip_filter.lo file.lo metadata_transfer.lo \
|
identify_client.lo ip_filter.lo file.lo metadata_transfer.lo \
|
||||||
logger.lo file_pool.lo ut_pex.lo lsd.lo upnp.lo \
|
logger.lo file_pool.lo ut_pex.lo lsd.lo upnp.lo \
|
||||||
@ -252,7 +249,7 @@ lib_LTLIBRARIES = libtorrent.la
|
|||||||
@USE_DHT_TRUE@kademlia/traversal_algorithm.cpp
|
@USE_DHT_TRUE@kademlia/traversal_algorithm.cpp
|
||||||
|
|
||||||
libtorrent_la_SOURCES = allocate_resources.cpp \
|
libtorrent_la_SOURCES = allocate_resources.cpp \
|
||||||
bandwidth_manager.cpp entry.cpp escape_string.cpp \
|
entry.cpp escape_string.cpp \
|
||||||
peer_connection.cpp bt_peer_connection.cpp web_peer_connection.cpp \
|
peer_connection.cpp bt_peer_connection.cpp web_peer_connection.cpp \
|
||||||
natpmp.cpp piece_picker.cpp policy.cpp session.cpp session_impl.cpp sha1.cpp \
|
natpmp.cpp piece_picker.cpp policy.cpp session.cpp session_impl.cpp sha1.cpp \
|
||||||
stat.cpp storage.cpp torrent.cpp torrent_handle.cpp pe_crypto.cpp \
|
stat.cpp storage.cpp torrent.cpp torrent_handle.cpp pe_crypto.cpp \
|
||||||
@ -332,7 +329,7 @@ $(top_srcdir)/include/libtorrent/version.hpp
|
|||||||
|
|
||||||
libtorrent_la_LDFLAGS = $(LDFLAGS) -release @VERSION@
|
libtorrent_la_LDFLAGS = $(LDFLAGS) -release @VERSION@
|
||||||
libtorrent_la_LIBADD = @ZLIB@ -l@BOOST_DATE_TIME_LIB@ -l@BOOST_FILESYSTEM_LIB@ -l@BOOST_THREAD_LIB@ @PTHREAD_LIBS@
|
libtorrent_la_LIBADD = @ZLIB@ -l@BOOST_DATE_TIME_LIB@ -l@BOOST_FILESYSTEM_LIB@ -l@BOOST_THREAD_LIB@ @PTHREAD_LIBS@
|
||||||
AM_CXXFLAGS = -ftemplate-depth-50 -I$(top_srcdir)/include -I$(top_srcdir)/include/libtorrent @ZLIBINCL@ @DEBUGFLAGS@ @PTHREAD_CFLAGS@
|
AM_CXXFLAGS = -ftemplate-depth-50 -I$(top_srcdir)/include -I$(top_srcdir)/include/libtorrent @ZLIBINCL@ @DEBUGFLAGS@ @PTHREAD_CFLAGS@ -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION
|
||||||
AM_LDFLAGS = $(LDFLAGS) -l@BOOST_DATE_TIME_LIB@ -l@BOOST_FILESYSTEM_LIB@ -l@BOOST_THREAD_LIB@ @PTHREAD_LIBS@
|
AM_LDFLAGS = $(LDFLAGS) -l@BOOST_DATE_TIME_LIB@ -l@BOOST_FILESYSTEM_LIB@ -l@BOOST_THREAD_LIB@ @PTHREAD_LIBS@
|
||||||
all: all-am
|
all: all-am
|
||||||
|
|
||||||
@ -405,7 +402,6 @@ distclean-compile:
|
|||||||
|
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alert.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alert.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/allocate_resources.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/allocate_resources.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bandwidth_manager.Plo@am__quote@
|
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bt_peer_connection.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bt_peer_connection.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/closest_nodes.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/closest_nodes.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/connection_queue.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/connection_queue.Plo@am__quote@
|
||||||
|
@ -248,17 +248,11 @@ namespace libtorrent
|
|||||||
void set_size(size_type s)
|
void set_size(size_type s)
|
||||||
{
|
{
|
||||||
size_type pos = tell();
|
size_type pos = tell();
|
||||||
// Only set size if current file size not equals s.
|
seek(s - 1);
|
||||||
// 2 as "m" argument is to be sure seek() sets SEEK_END on
|
char dummy = 0;
|
||||||
// all compilers.
|
read(&dummy, 1);
|
||||||
if(s != seek(0, 2))
|
seek(s - 1);
|
||||||
{
|
write(&dummy, 1);
|
||||||
seek(s - 1);
|
|
||||||
char dummy = 0;
|
|
||||||
read(&dummy, 1);
|
|
||||||
seek(s - 1);
|
|
||||||
write(&dummy, 1);
|
|
||||||
}
|
|
||||||
seek(pos);
|
seek(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1019,6 +1019,7 @@ namespace libtorrent
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// workaround for bugs in Mac OS X where zero run is not reported
|
||||||
if (!strcmp(fsinfo.f_fstypename, "hfs")
|
if (!strcmp(fsinfo.f_fstypename, "hfs")
|
||||||
|| !strcmp(fsinfo.f_fstypename, "ufs"))
|
|| !strcmp(fsinfo.f_fstypename, "ufs"))
|
||||||
return true;
|
return true;
|
||||||
@ -1026,7 +1027,7 @@ namespace libtorrent
|
|||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
struct statfs buf;
|
struct statfs buf;
|
||||||
int err = statfs(query_path.native_directory_string().c_str(), &buf);
|
int err = statfs(query_path.native_directory_string().c_str(), &buf);
|
||||||
if (err == 0)
|
if (err == 0)
|
||||||
@ -1059,11 +1060,7 @@ namespace libtorrent
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO: POSIX implementation
|
// TODO: POSIX implementation
|
||||||
#if defined(__FreeBSD__)
|
|
||||||
return true;
|
|
||||||
#else
|
|
||||||
return false;
|
return false;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- piece_manager -----------------------------------------------------
|
// -- piece_manager -----------------------------------------------------
|
||||||
@ -1575,16 +1572,12 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_unallocated_slots.empty())
|
if (m_unallocated_slots.empty())
|
||||||
{
|
|
||||||
m_state = state_create_files;
|
m_state = state_create_files;
|
||||||
return false;
|
else if (m_compact_mode)
|
||||||
}
|
|
||||||
|
|
||||||
if (m_compact_mode)
|
|
||||||
{
|
|
||||||
m_state = state_create_files;
|
m_state = state_create_files;
|
||||||
return false;
|
else
|
||||||
}
|
m_state = state_allocating;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_state = state_full_check;
|
m_state = state_full_check;
|
||||||
@ -1604,7 +1597,7 @@ namespace libtorrent
|
|||||||
| |
|
| |
|
||||||
| v
|
| v
|
||||||
| +------------+
|
| +------------+
|
||||||
| | allocating |
|
|->| allocating |
|
||||||
| +------------+
|
| +------------+
|
||||||
| |
|
| |
|
||||||
| v
|
| v
|
||||||
|
@ -1109,7 +1109,7 @@ namespace libtorrent
|
|||||||
|
|
||||||
void torrent::set_piece_priority(int index, int priority)
|
void torrent::set_piece_priority(int index, int priority)
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
// INVARIANT_CHECK;
|
||||||
|
|
||||||
assert(valid_metadata());
|
assert(valid_metadata());
|
||||||
if (is_seed()) return;
|
if (is_seed()) return;
|
||||||
@ -1125,7 +1125,7 @@ namespace libtorrent
|
|||||||
|
|
||||||
int torrent::piece_priority(int index) const
|
int torrent::piece_priority(int index) const
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
// INVARIANT_CHECK;
|
||||||
|
|
||||||
assert(valid_metadata());
|
assert(valid_metadata());
|
||||||
if (is_seed()) return 1;
|
if (is_seed()) return 1;
|
||||||
|
@ -62,7 +62,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
if (a.is_v6()) return false;
|
if (a.is_v6()) return false;
|
||||||
address_v4 a4 = a.to_v4();
|
address_v4 a4 = a.to_v4();
|
||||||
unsigned long ip = htonl(a4.to_ulong());
|
unsigned long ip = a4.to_ulong();
|
||||||
return ((ip & 0xff000000) == 0x0a000000
|
return ((ip & 0xff000000) == 0x0a000000
|
||||||
|| (ip & 0xfff00000) == 0xac100000
|
|| (ip & 0xfff00000) == 0xac100000
|
||||||
|| (ip & 0xffff0000) == 0xc0a80000);
|
|| (ip & 0xffff0000) == 0xc0a80000);
|
||||||
|
@ -197,39 +197,41 @@ namespace libtorrent { namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual bool on_extended(int length, int msg, buffer::const_interval body)
|
virtual bool on_extended(int length, int msg, buffer::const_interval body)
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (msg != extension_index) return false;
|
if (msg != extension_index) return false;
|
||||||
if (m_message_index == 0) return false;
|
if (m_message_index == 0) return false;
|
||||||
|
|
||||||
if (length > 500 * 1024)
|
if (length > 500 * 1024)
|
||||||
throw protocol_error("ut peer exchange message larger than 500 kB");
|
throw protocol_error("uT peer exchange message larger than 500 kB");
|
||||||
|
|
||||||
if (body.left() < length) return true;
|
if (body.left() < length) return true;
|
||||||
|
|
||||||
entry pex_msg = bdecode(body.begin, body.end);
|
try
|
||||||
std::string const& peers = pex_msg["added"].string();
|
|
||||||
std::string const& peer_flags = pex_msg["added.f"].string();
|
|
||||||
|
|
||||||
int num_peers = peers.length() / 6;
|
|
||||||
char const* in = peers.c_str();
|
|
||||||
char const* fin = peer_flags.c_str();
|
|
||||||
|
|
||||||
if (int(peer_flags.size()) != num_peers)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
peer_id pid(0);
|
|
||||||
policy& p = m_torrent.get_policy();
|
|
||||||
for (int i = 0; i < num_peers; ++i)
|
|
||||||
{
|
{
|
||||||
tcp::endpoint adr = detail::read_v4_endpoint<tcp::endpoint>(in);
|
entry pex_msg = bdecode(body.begin, body.end);
|
||||||
char flags = detail::read_uint8(fin);
|
std::string const& peers = pex_msg["added"].string();
|
||||||
p.peer_from_tracker(adr, pid, peer_info::pex, flags);
|
std::string const& peer_flags = pex_msg["added.f"].string();
|
||||||
}
|
|
||||||
return true;
|
int num_peers = peers.length() / 6;
|
||||||
}
|
char const* in = peers.c_str();
|
||||||
catch (std::exception&)
|
char const* fin = peer_flags.c_str();
|
||||||
{
|
|
||||||
|
if (int(peer_flags.size()) != num_peers)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
peer_id pid(0);
|
||||||
|
policy& p = m_torrent.get_policy();
|
||||||
|
for (int i = 0; i < num_peers; ++i)
|
||||||
|
{
|
||||||
|
tcp::endpoint adr = detail::read_v4_endpoint<tcp::endpoint>(in);
|
||||||
|
char flags = detail::read_uint8(fin);
|
||||||
|
p.peer_from_tracker(adr, pid, peer_info::pex, flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (std::exception&)
|
||||||
|
{
|
||||||
|
throw protocol_error("invalid uT peer exchange message");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user