merged RC_1_1 into master
This commit is contained in:
commit
04a3c04075
|
@ -111,7 +111,7 @@ script:
|
||||||
|
|
||||||
- cd simulation
|
- cd simulation
|
||||||
- if [ $sim = "1" ]; then
|
- if [ $sim = "1" ]; then
|
||||||
bjam --hash -j2 crypto=built-in $coverage_toolset;
|
bjam --hash -j2 crypto=built-in warnings-as-errors=on $coverage_toolset;
|
||||||
fi
|
fi
|
||||||
- cd ..
|
- cd ..
|
||||||
- ccache --show-stats
|
- ccache --show-stats
|
||||||
|
|
|
@ -14,6 +14,7 @@ set(sources
|
||||||
bandwidth_manager
|
bandwidth_manager
|
||||||
bandwidth_queue_entry
|
bandwidth_queue_entry
|
||||||
bdecode
|
bdecode
|
||||||
|
bitfield
|
||||||
block_cache
|
block_cache
|
||||||
bloom_filter
|
bloom_filter
|
||||||
chained_buffer
|
chained_buffer
|
||||||
|
|
|
@ -6,6 +6,11 @@
|
||||||
* improved support for listening on multiple sockets and interfaces
|
* improved support for listening on multiple sockets and interfaces
|
||||||
* resume data no longer has timestamps of files
|
* resume data no longer has timestamps of files
|
||||||
|
|
||||||
|
1.1.1 release
|
||||||
|
|
||||||
|
* Added missing alert categories in python binding
|
||||||
|
* Added dht_get_peers_reply_alert alert in python binding
|
||||||
|
|
||||||
1.1.0 release
|
1.1.0 release
|
||||||
|
|
||||||
* improve robustness and performance of uTP PMTU discovery
|
* improve robustness and performance of uTP PMTU discovery
|
||||||
|
|
1
Jamfile
1
Jamfile
|
@ -564,6 +564,7 @@ SOURCES =
|
||||||
bandwidth_manager
|
bandwidth_manager
|
||||||
bandwidth_queue_entry
|
bandwidth_queue_entry
|
||||||
bdecode
|
bdecode
|
||||||
|
bitfield
|
||||||
block_cache
|
block_cache
|
||||||
bloom_filter
|
bloom_filter
|
||||||
chained_buffer
|
chained_buffer
|
||||||
|
|
|
@ -164,6 +164,21 @@ dict session_stats_values(session_stats_alert const& alert)
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list dht_get_peers_reply_alert_peers(dht_get_peers_reply_alert const& a)
|
||||||
|
{
|
||||||
|
list result;
|
||||||
|
|
||||||
|
std::vector<tcp::endpoint> v(a.peers());
|
||||||
|
|
||||||
|
for (std::vector<tcp::endpoint>::const_iterator i = v.begin();
|
||||||
|
i != v.end(); ++i)
|
||||||
|
{
|
||||||
|
result.append(endpoint_to_tuple(*i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void bind_alert()
|
void bind_alert()
|
||||||
{
|
{
|
||||||
using boost::noncopyable;
|
using boost::noncopyable;
|
||||||
|
@ -209,10 +224,16 @@ void bind_alert()
|
||||||
.value("progress_notification", alert::progress_notification)
|
.value("progress_notification", alert::progress_notification)
|
||||||
.value("ip_block_notification", alert::ip_block_notification)
|
.value("ip_block_notification", alert::ip_block_notification)
|
||||||
.value("performance_warning", alert::performance_warning)
|
.value("performance_warning", alert::performance_warning)
|
||||||
|
.value("dht_notification", alert::dht_notification)
|
||||||
.value("stats_notification", alert::stats_notification)
|
.value("stats_notification", alert::stats_notification)
|
||||||
.value("session_log_notification", alert::session_log_notification)
|
.value("session_log_notification", alert::session_log_notification)
|
||||||
.value("torrent_log_notification", alert::torrent_log_notification)
|
.value("torrent_log_notification", alert::torrent_log_notification)
|
||||||
.value("peer_log_notification", alert::peer_log_notification)
|
.value("peer_log_notification", alert::peer_log_notification)
|
||||||
|
.value("incoming_request_notification", alert::incoming_request_notification)
|
||||||
|
.value("dht_log_notification", alert::dht_log_notification)
|
||||||
|
.value("dht_operation_notification", alert::dht_operation_notification)
|
||||||
|
.value("port_mapping_log_notification", alert::port_mapping_log_notification)
|
||||||
|
.value("picker_log_notification", alert::picker_log_notification)
|
||||||
// deliberately not INT_MAX. Arch linux crash while throwing an exception
|
// deliberately not INT_MAX. Arch linux crash while throwing an exception
|
||||||
.value("all_categories", (alert::category_t)0xfffffff)
|
.value("all_categories", (alert::category_t)0xfffffff)
|
||||||
;
|
;
|
||||||
|
@ -723,4 +744,11 @@ void bind_alert()
|
||||||
"session_stats_alert", no_init)
|
"session_stats_alert", no_init)
|
||||||
.add_property("values", &session_stats_values)
|
.add_property("values", &session_stats_values)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
class_<dht_get_peers_reply_alert, bases<alert>, noncopyable>(
|
||||||
|
"dht_get_peers_reply_alert", no_init)
|
||||||
|
.def_readonly("info_hash", &dht_get_peers_reply_alert::info_hash)
|
||||||
|
.def("num_peers", &dht_get_peers_reply_alert::num_peers)
|
||||||
|
.def("peers", &dht_get_peers_reply_alert_peers)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
|
@ -862,7 +862,7 @@ void bind_session()
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
.def("add_feed", &add_feed)
|
.def("add_feed", &add_feed)
|
||||||
.def("status", allow_threads(<::session::status))
|
.def("status", allow_threads(<::session::status))
|
||||||
.def("settings", &session_get_settings)
|
.def("settings", <::session::settings)
|
||||||
.def("set_settings", &session_set_settings)
|
.def("set_settings", &session_set_settings)
|
||||||
#endif
|
#endif
|
||||||
.def("get_settings", &session_get_settings)
|
.def("get_settings", &session_get_settings)
|
||||||
|
|
|
@ -536,8 +536,6 @@ AM_CONDITIONAL([WITH_OPENSSL], [test "x$ARG_ENABLE_ENCRYPTION" = "xyes" -o "x$AR
|
||||||
AC_DEFINE([BOOST_ASIO_HASH_MAP_BUCKETS],[1021],[Define to fix a wrong behavior in boost 1.39.])
|
AC_DEFINE([BOOST_ASIO_HASH_MAP_BUCKETS],[1021],[Define to fix a wrong behavior in boost 1.39.])
|
||||||
COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DBOOST_ASIO_HASH_MAP_BUCKETS=1021 "
|
COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DBOOST_ASIO_HASH_MAP_BUCKETS=1021 "
|
||||||
|
|
||||||
COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -msse4.2 "
|
|
||||||
|
|
||||||
AC_DEFINE([BOOST_EXCEPTION_DISABLE],[1],[Define to disable the boost.exception features.])
|
AC_DEFINE([BOOST_EXCEPTION_DISABLE],[1],[Define to disable the boost.exception features.])
|
||||||
COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DBOOST_EXCEPTION_DISABLE "
|
COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DBOOST_EXCEPTION_DISABLE "
|
||||||
|
|
||||||
|
|
|
@ -245,16 +245,13 @@ Build features:
|
||||||
| | * ``shared`` - links dynamically against the boost |
|
| | * ``shared`` - links dynamically against the boost |
|
||||||
| | libraries. |
|
| | libraries. |
|
||||||
+--------------------------+----------------------------------------------------+
|
+--------------------------+----------------------------------------------------+
|
||||||
| ``logging`` | * ``off`` - logging alerts disabled. |
|
| ``logging`` | * ``off`` - logging alerts disabled. The |
|
||||||
| | * ``on`` - default. logging alerts available, |
|
|
||||||
| | still need to be enabled by the alert mask. The |
|
|
||||||
| | reason to disable logging is to keep the binary |
|
| | reason to disable logging is to keep the binary |
|
||||||
| | size down. |
|
| | size low where that matters. |
|
||||||
|
| | * ``on`` - default. logging alerts available, |
|
||||||
|
| | still need to be enabled by the alert mask. |
|
||||||
+--------------------------+----------------------------------------------------+
|
+--------------------------+----------------------------------------------------+
|
||||||
| ``dht`` | * ``on`` - build with support for tracker less |
|
| ``dht`` | * ``on`` - build with DHT support |
|
||||||
| | torrents and DHT support. |
|
|
||||||
| | * ``logging`` - build with DHT support and verbose |
|
|
||||||
| | logging of the DHT protocol traffic. |
|
|
||||||
| | * ``off`` - build without DHT support. |
|
| | * ``off`` - build without DHT support. |
|
||||||
+--------------------------+----------------------------------------------------+
|
+--------------------------+----------------------------------------------------+
|
||||||
| ``asserts`` | * ``auto`` - asserts are on if in debug mode |
|
| ``asserts`` | * ``auto`` - asserts are on if in debug mode |
|
||||||
|
|
|
@ -2403,7 +2403,12 @@ namespace libtorrent
|
||||||
sha1_hash info_hash;
|
sha1_hash info_hash;
|
||||||
|
|
||||||
int num_peers() const;
|
int num_peers() const;
|
||||||
void peers(std::vector<tcp::endpoint>& peers) const;
|
|
||||||
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
|
TORRENT_DEPRECATED
|
||||||
|
void peers(std::vector<tcp::endpoint>& v) const;
|
||||||
|
#endif
|
||||||
|
std::vector<tcp::endpoint> peers() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
aux::stack_allocator& m_alloc;
|
aux::stack_allocator& m_alloc;
|
||||||
|
|
|
@ -63,7 +63,7 @@ namespace aux {
|
||||||
// set to authenticate with the proxy.
|
// set to authenticate with the proxy.
|
||||||
std::string hostname;
|
std::string hostname;
|
||||||
|
|
||||||
// when using a proy type that requires authentication, the username
|
// when using a proxy type that requires authentication, the username
|
||||||
// and password fields must be set to the credentials for the proxy.
|
// and password fields must be set to the credentials for the proxy.
|
||||||
std::string username;
|
std::string username;
|
||||||
std::string password;
|
std::string password;
|
||||||
|
@ -128,7 +128,7 @@ namespace aux {
|
||||||
// This is only supported by SOCKS5 and HTTP.
|
// This is only supported by SOCKS5 and HTTP.
|
||||||
bool proxy_hostnames;
|
bool proxy_hostnames;
|
||||||
|
|
||||||
// determines whether or not to excempt peer and web seed connections
|
// determines whether or not to exempt peer and web seed connections
|
||||||
// from using the proxy. This defaults to true, i.e. peer connections are
|
// from using the proxy. This defaults to true, i.e. peer connections are
|
||||||
// proxied by default.
|
// proxied by default.
|
||||||
bool proxy_peer_connections;
|
bool proxy_peer_connections;
|
||||||
|
|
|
@ -986,12 +986,15 @@ namespace libtorrent
|
||||||
void recalculate_optimistic_unchoke_slots();
|
void recalculate_optimistic_unchoke_slots();
|
||||||
|
|
||||||
time_point m_created;
|
time_point m_created;
|
||||||
boost::int64_t session_time() const TORRENT_OVERRIDE
|
boost::uint16_t session_time() const TORRENT_OVERRIDE
|
||||||
{
|
{
|
||||||
// +1 is here to make it possible to distinguish uninitialized (to
|
// +1 is here to make it possible to distinguish uninitialized (to
|
||||||
// 0) timestamps and timestamps of things that happend during the
|
// 0) timestamps and timestamps of things that happend during the
|
||||||
// first second after the session was constructed
|
// first second after the session was constructed
|
||||||
return total_seconds(aux::time_now() - m_created) + 1;
|
boost::int64_t const ret = total_seconds(aux::time_now() - m_created) + 1;
|
||||||
|
TORRENT_ASSERT(ret >= 0);
|
||||||
|
TORRENT_ASSERT(ret <= (std::numeric_limits<boost::uint16_t>::max)());
|
||||||
|
return static_cast<boost::uint16_t>(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
time_point m_last_tick;
|
time_point m_last_tick;
|
||||||
|
|
|
@ -175,7 +175,7 @@ namespace libtorrent { namespace aux
|
||||||
virtual port_filter const& get_port_filter() const = 0;
|
virtual port_filter const& get_port_filter() const = 0;
|
||||||
virtual void ban_ip(address addr) = 0;
|
virtual void ban_ip(address addr) = 0;
|
||||||
|
|
||||||
virtual boost::int64_t session_time() const = 0;
|
virtual boost::uint16_t session_time() const = 0;
|
||||||
|
|
||||||
virtual bool is_paused() const = 0;
|
virtual bool is_paused() const = 0;
|
||||||
virtual bool is_aborted() const = 0;
|
virtual bool is_aborted() const = 0;
|
||||||
|
|
|
@ -36,17 +36,12 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/assert.hpp"
|
#include "libtorrent/assert.hpp"
|
||||||
#include "libtorrent/config.hpp"
|
#include "libtorrent/config.hpp"
|
||||||
#include "libtorrent/aux_/byteswap.hpp"
|
#include "libtorrent/aux_/byteswap.hpp"
|
||||||
#include "libtorrent/aux_/cpuid.hpp"
|
|
||||||
|
|
||||||
#include <cstring> // for memset and memcpy
|
#include <cstring> // for memset and memcpy
|
||||||
#include <cstdlib> // for malloc, free and realloc
|
#include <cstdlib> // for malloc, free and realloc
|
||||||
#include <boost/cstdint.hpp> // uint32_t
|
#include <boost/cstdint.hpp> // uint32_t
|
||||||
#include <algorithm> // for min()
|
#include <algorithm> // for min()
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#include <intrin.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
// The bitfiled type stores any number of bits as a bitfield
|
// The bitfiled type stores any number of bits as a bitfield
|
||||||
|
@ -116,21 +111,7 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true if all bits in the bitfield are set
|
// returns true if all bits in the bitfield are set
|
||||||
bool all_set() const
|
bool all_set() const;
|
||||||
{
|
|
||||||
const int words = size() / 32;
|
|
||||||
for (int i = 0; i < words; ++i)
|
|
||||||
{
|
|
||||||
if (m_buf[i] != 0xffffffff) return false;
|
|
||||||
}
|
|
||||||
int rest = size() & 31;
|
|
||||||
if (rest > 0)
|
|
||||||
{
|
|
||||||
boost::uint32_t mask = aux::host_to_network(0xffffffff << (32-rest));
|
|
||||||
if ((m_buf[words] & mask) != mask) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool none_set() const
|
bool none_set() const
|
||||||
{
|
{
|
||||||
|
@ -179,46 +160,7 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
// count the number of bits in the bitfield that are set to 1.
|
// count the number of bits in the bitfield that are set to 1.
|
||||||
int count() const
|
int count() const;
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
const int words = num_words();
|
|
||||||
#if TORRENT_HAS_SSE
|
|
||||||
if (aux::mmx_support)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < words; ++i)
|
|
||||||
{
|
|
||||||
#ifdef __GNUC__
|
|
||||||
ret += __builtin_popcount(m_buf[i]);
|
|
||||||
#else
|
|
||||||
ret += _mm_popcnt_u32(m_buf[i]);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#endif // TORRENT_HAS_SSE
|
|
||||||
|
|
||||||
for (int i = 0; i < words; ++i)
|
|
||||||
{
|
|
||||||
boost::uint32_t v = m_buf[i];
|
|
||||||
// from:
|
|
||||||
// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
|
|
||||||
static const int S[] = {1, 2, 4, 8, 16}; // Magic Binary Numbers
|
|
||||||
static const int B[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF};
|
|
||||||
|
|
||||||
boost::uint32_t c = v - ((v >> 1) & B[0]);
|
|
||||||
c = ((c >> S[1]) & B[1]) + (c & B[1]);
|
|
||||||
c = ((c >> S[2]) + c) & B[2];
|
|
||||||
c = ((c >> S[3]) + c) & B[3];
|
|
||||||
c = ((c >> S[4]) + c) & B[4];
|
|
||||||
ret += c;
|
|
||||||
}
|
|
||||||
|
|
||||||
TORRENT_ASSERT(ret <= size());
|
|
||||||
TORRENT_ASSERT(ret >= 0);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct const_iterator
|
struct const_iterator
|
||||||
{
|
{
|
||||||
|
@ -284,66 +226,9 @@ namespace libtorrent
|
||||||
|
|
||||||
// set the size of the bitfield to ``bits`` length. If the bitfield is extended,
|
// set the size of the bitfield to ``bits`` length. If the bitfield is extended,
|
||||||
// the new bits are initialized to ``val``.
|
// the new bits are initialized to ``val``.
|
||||||
void resize(int bits, bool val)
|
void resize(int bits, bool val);
|
||||||
{
|
|
||||||
if (bits == size()) return;
|
|
||||||
|
|
||||||
int s = size();
|
void resize(int bits);
|
||||||
int b = size() & 31;
|
|
||||||
resize(bits);
|
|
||||||
if (s >= size()) return;
|
|
||||||
int old_size_words = (s + 31) / 32;
|
|
||||||
int new_size_words = num_words();
|
|
||||||
if (val)
|
|
||||||
{
|
|
||||||
if (old_size_words && b) m_buf[old_size_words - 1] |= aux::host_to_network((0xffffffff >> b));
|
|
||||||
if (old_size_words < new_size_words)
|
|
||||||
std::memset(m_buf + old_size_words, 0xff
|
|
||||||
, size_t((new_size_words - old_size_words) * 4));
|
|
||||||
clear_trailing_bits();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (old_size_words < new_size_words)
|
|
||||||
std::memset(m_buf + old_size_words, 0x00
|
|
||||||
, size_t((new_size_words - old_size_words) * 4));
|
|
||||||
}
|
|
||||||
TORRENT_ASSERT(size() == bits);
|
|
||||||
}
|
|
||||||
|
|
||||||
void resize(int bits)
|
|
||||||
{
|
|
||||||
if (bits == size()) return;
|
|
||||||
|
|
||||||
TORRENT_ASSERT(bits >= 0);
|
|
||||||
// +1 because the first word is the size (in bits)
|
|
||||||
const int b = (bits + 31) / 32;
|
|
||||||
if (m_buf)
|
|
||||||
{
|
|
||||||
boost::uint32_t* tmp = static_cast<boost::uint32_t*>(std::realloc(m_buf-1, (b+1) * 4));
|
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
|
||||||
if (tmp == NULL) throw std::bad_alloc();
|
|
||||||
#endif
|
|
||||||
m_buf = tmp + 1;
|
|
||||||
m_buf[-1] = bits;
|
|
||||||
}
|
|
||||||
else if (bits > 0)
|
|
||||||
{
|
|
||||||
boost::uint32_t* tmp = static_cast<boost::uint32_t*>(std::malloc((b+1) * 4));
|
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
|
||||||
if (tmp == NULL) throw std::bad_alloc();
|
|
||||||
#endif
|
|
||||||
m_buf = tmp + 1;
|
|
||||||
m_buf[-1] = bits;
|
|
||||||
}
|
|
||||||
else if (m_buf != NULL)
|
|
||||||
{
|
|
||||||
std::free(m_buf-1);
|
|
||||||
m_buf = NULL;
|
|
||||||
}
|
|
||||||
clear_trailing_bits();
|
|
||||||
TORRENT_ASSERT(size() == bits);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set all bits in the bitfield to 1 (set_all) or 0 (clear_all).
|
// set all bits in the bitfield to 1 (set_all) or 0 (clear_all).
|
||||||
void set_all()
|
void set_all()
|
||||||
|
|
|
@ -226,6 +226,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
// ===== ANDROID ===== (almost linux, sort of)
|
// ===== ANDROID ===== (almost linux, sort of)
|
||||||
#if defined __ANDROID__
|
#if defined __ANDROID__
|
||||||
|
#define TORRENT_USE_PREADV 0
|
||||||
|
#define TORRENT_USE_PREAD 1
|
||||||
#define TORRENT_ANDROID
|
#define TORRENT_ANDROID
|
||||||
#define TORRENT_HAS_FALLOCATE 0
|
#define TORRENT_HAS_FALLOCATE 0
|
||||||
#define TORRENT_USE_ICONV 0
|
#define TORRENT_USE_ICONV 0
|
||||||
|
|
|
@ -344,7 +344,7 @@ namespace libtorrent
|
||||||
int upload_rate_peak;
|
int upload_rate_peak;
|
||||||
|
|
||||||
// the progress of the peer in the range [0, 1]. This is always 0 when
|
// the progress of the peer in the range [0, 1]. This is always 0 when
|
||||||
// floating point operations are diabled, instead use ``progress_ppm``.
|
// floating point operations are disabled, instead use ``progress_ppm``.
|
||||||
float progress; // [0, 1]
|
float progress; // [0, 1]
|
||||||
|
|
||||||
// indicates the download progress of the peer in the range [0, 1000000]
|
// indicates the download progress of the peer in the range [0, 1000000]
|
||||||
|
|
|
@ -135,7 +135,7 @@ namespace libtorrent
|
||||||
int whole_pieces_threshold;
|
int whole_pieces_threshold;
|
||||||
|
|
||||||
// the number of seconds to wait for any activity on the peer wire before
|
// the number of seconds to wait for any activity on the peer wire before
|
||||||
// closing the connectiong due to time out. This defaults to 120 seconds,
|
// closing the connection due to time out. This defaults to 120 seconds,
|
||||||
// since that's what's specified in the protocol specification. After
|
// since that's what's specified in the protocol specification. After
|
||||||
// half the time out, a keep alive message is sent.
|
// half the time out, a keep alive message is sent.
|
||||||
int peer_timeout;
|
int peer_timeout;
|
||||||
|
@ -170,7 +170,7 @@ namespace libtorrent
|
||||||
// connections should be rejected or not. Multiple connections from the
|
// connections should be rejected or not. Multiple connections from the
|
||||||
// same IP address is not allowed by default, to prevent abusive behavior
|
// same IP address is not allowed by default, to prevent abusive behavior
|
||||||
// by peers. It may be useful to allow such connections in cases where
|
// by peers. It may be useful to allow such connections in cases where
|
||||||
// simulations are run on the same machie, and all peers in a swarm has
|
// simulations are run on the same machine, and all peers in a swarm has
|
||||||
// the same IP address.
|
// the same IP address.
|
||||||
bool allow_multiple_connections_per_ip;
|
bool allow_multiple_connections_per_ip;
|
||||||
|
|
||||||
|
@ -280,7 +280,7 @@ namespace libtorrent
|
||||||
//
|
//
|
||||||
// When this limit is reached, the peer connections will stop reading
|
// When this limit is reached, the peer connections will stop reading
|
||||||
// data from their sockets, until the disk thread catches up. Setting
|
// data from their sockets, until the disk thread catches up. Setting
|
||||||
// this too low will severly limit your download rate.
|
// this too low will severely limit your download rate.
|
||||||
int max_queued_disk_bytes;
|
int max_queued_disk_bytes;
|
||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
|
@ -497,7 +497,7 @@ namespace libtorrent
|
||||||
// from growing its file cache indefinitely. Since some OSes only allow
|
// from growing its file cache indefinitely. Since some OSes only allow
|
||||||
// aligned files to be opened in unbuffered mode, It is recommended to
|
// aligned files to be opened in unbuffered mode, It is recommended to
|
||||||
// make the largest file in a torrent the first file (with offset 0) or
|
// make the largest file in a torrent the first file (with offset 0) or
|
||||||
// use pad files to align all files to piece boundries.
|
// use pad files to align all files to piece boundaries.
|
||||||
int disk_io_write_mode;
|
int disk_io_write_mode;
|
||||||
int disk_io_read_mode;
|
int disk_io_read_mode;
|
||||||
|
|
||||||
|
@ -634,7 +634,7 @@ namespace libtorrent
|
||||||
int peer_turnover_interval;
|
int peer_turnover_interval;
|
||||||
|
|
||||||
// the percentage of peers to disconnect every
|
// the percentage of peers to disconnect every
|
||||||
// turnoever interval (if we're at the peer limit)
|
// turnover interval (if we're at the peer limit)
|
||||||
// defaults to 4%
|
// defaults to 4%
|
||||||
// this is specified in percent
|
// this is specified in percent
|
||||||
float peer_turnover;
|
float peer_turnover;
|
||||||
|
@ -760,7 +760,7 @@ namespace libtorrent
|
||||||
// complete and needs to be verified against the piece hash. This happens
|
// complete and needs to be verified against the piece hash. This happens
|
||||||
// if some blocks were flushed to the disk out of order. Everything that
|
// if some blocks were flushed to the disk out of order. Everything that
|
||||||
// is flushed in order is hashed as it goes along. Optimizing for speed
|
// is flushed in order is hashed as it goes along. Optimizing for speed
|
||||||
// will allocate space to fit all the the remaingin, unhashed, part of
|
// will allocate space to fit all the remaining, unhashed, part of
|
||||||
// the piece, reads the data into it in a single call and hashes it. This
|
// the piece, reads the data into it in a single call and hashes it. This
|
||||||
// is the default. If ``optimizing_hashing_for_speed`` is false, a single
|
// is the default. If ``optimizing_hashing_for_speed`` is false, a single
|
||||||
// block will be allocated (16 kB), and the unhashed parts of the piece
|
// block will be allocated (16 kB), and the unhashed parts of the piece
|
||||||
|
@ -785,7 +785,7 @@ namespace libtorrent
|
||||||
lru,
|
lru,
|
||||||
|
|
||||||
// will flush the largest sequences of contiguous blocks from the
|
// will flush the largest sequences of contiguous blocks from the
|
||||||
// write cache, regarless of the piece's last use time.
|
// write cache, regardless of the piece's last use time.
|
||||||
largest_contiguous,
|
largest_contiguous,
|
||||||
|
|
||||||
// will prioritize flushing blocks that will avoid having to read them
|
// will prioritize flushing blocks that will avoid having to read them
|
||||||
|
@ -802,7 +802,7 @@ namespace libtorrent
|
||||||
// the number of blocks to read into the read cache when a read cache
|
// the number of blocks to read into the read cache when a read cache
|
||||||
// miss occurs. Setting this to 0 is essentially the same thing as
|
// miss occurs. Setting this to 0 is essentially the same thing as
|
||||||
// disabling read cache. The number of blocks read into the read cache is
|
// disabling read cache. The number of blocks read into the read cache is
|
||||||
// always capped by the piece boundry.
|
// always capped by the piece boundary.
|
||||||
//
|
//
|
||||||
// When a piece in the write cache has ``write_cache_line_size``
|
// When a piece in the write cache has ``write_cache_line_size``
|
||||||
// contiguous blocks in it, they will be flushed. Setting this to 1
|
// contiguous blocks in it, they will be flushed. Setting this to 1
|
||||||
|
@ -929,7 +929,7 @@ namespace libtorrent
|
||||||
// waste finding the true reciprocation rate.
|
// waste finding the true reciprocation rate.
|
||||||
int default_est_reciprocation_rate;
|
int default_est_reciprocation_rate;
|
||||||
|
|
||||||
// specifies how many percent the extimated reciprocation rate should be
|
// specifies how many percent the estimated reciprocation rate should be
|
||||||
// increased by each unchoke interval a peer is still choking us back.
|
// increased by each unchoke interval a peer is still choking us back.
|
||||||
// This defaults to 20%. This only applies to the BitTyrant choker.
|
// This defaults to 20%. This only applies to the BitTyrant choker.
|
||||||
int increase_est_reciprocation_rate;
|
int increase_est_reciprocation_rate;
|
||||||
|
@ -950,8 +950,8 @@ namespace libtorrent
|
||||||
bool incoming_starts_queued_torrents;
|
bool incoming_starts_queued_torrents;
|
||||||
|
|
||||||
// when set to true, the downloaded counter sent to trackers will include
|
// when set to true, the downloaded counter sent to trackers will include
|
||||||
// the actual number of payload bytes donwnloaded including redundant
|
// the actual number of payload bytes downloaded including redundant
|
||||||
// bytes. If set to false, it will not include any redundany bytes
|
// bytes. If set to false, it will not include any redundancy bytes
|
||||||
bool report_true_downloaded;
|
bool report_true_downloaded;
|
||||||
|
|
||||||
// defaults to true, and controls when a block may be requested twice. If
|
// defaults to true, and controls when a block may be requested twice. If
|
||||||
|
@ -981,7 +981,7 @@ namespace libtorrent
|
||||||
|
|
||||||
// the max number of peers we accept from pex messages from a single peer.
|
// the max number of peers we accept from pex messages from a single peer.
|
||||||
// this limits the number of concurrent peers any of our peers claims to
|
// this limits the number of concurrent peers any of our peers claims to
|
||||||
// be connected to. If they clain to be connected to more than this, we'll
|
// be connected to. If they claim to be connected to more than this, we'll
|
||||||
// ignore any peer that exceeds this limit
|
// ignore any peer that exceeds this limit
|
||||||
int max_pex_peers;
|
int max_pex_peers;
|
||||||
|
|
||||||
|
@ -998,7 +998,7 @@ namespace libtorrent
|
||||||
// determines if the storage should check the whole files when resume
|
// determines if the storage should check the whole files when resume
|
||||||
// data is incomplete or missing or whether it should simply assume we
|
// data is incomplete or missing or whether it should simply assume we
|
||||||
// don't have any of the data. By default, this is determined by the
|
// don't have any of the data. By default, this is determined by the
|
||||||
// existance of any of the files. By setting this setting to true, the
|
// existence of any of the files. By setting this setting to true, the
|
||||||
// files won't be checked, but will go straight to download mode.
|
// files won't be checked, but will go straight to download mode.
|
||||||
bool no_recheck_incomplete_resume;
|
bool no_recheck_incomplete_resume;
|
||||||
|
|
||||||
|
@ -1216,7 +1216,7 @@ namespace libtorrent
|
||||||
bool seeding_outgoing_connections;
|
bool seeding_outgoing_connections;
|
||||||
|
|
||||||
// if true (which is the default), libtorrent will not connect to any
|
// if true (which is the default), libtorrent will not connect to any
|
||||||
// peers on priviliged ports (<= 1023). This can mitigate using
|
// peers on privileged ports (<= 1023). This can mitigate using
|
||||||
// bittorrent swarms for certain DDoS attacks.
|
// bittorrent swarms for certain DDoS attacks.
|
||||||
bool no_connect_privileged_ports;
|
bool no_connect_privileged_ports;
|
||||||
|
|
||||||
|
@ -1233,7 +1233,7 @@ namespace libtorrent
|
||||||
// second may be limited to below the ``connection_speed``, in case we're
|
// second may be limited to below the ``connection_speed``, in case we're
|
||||||
// close to bump up against the limit of number of connections. The
|
// close to bump up against the limit of number of connections. The
|
||||||
// intention of this setting is to more evenly distribute our connection
|
// intention of this setting is to more evenly distribute our connection
|
||||||
// attempts over time, instead of attempting to connectin in batches, and
|
// attempts over time, instead of attempting to connect in batches, and
|
||||||
// timing them out in batches.
|
// timing them out in batches.
|
||||||
bool smooth_connects;
|
bool smooth_connects;
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,7 @@ namespace libtorrent
|
||||||
// connections should be rejected or not. Multiple connections from
|
// connections should be rejected or not. Multiple connections from
|
||||||
// the same IP address is not allowed by default, to prevent abusive
|
// the same IP address is not allowed by default, to prevent abusive
|
||||||
// behavior by peers. It may be useful to allow such connections in
|
// behavior by peers. It may be useful to allow such connections in
|
||||||
// cases where simulations are run on the same machie, and all peers
|
// cases where simulations are run on the same machine, and all peers
|
||||||
// in a swarm has the same IP address.
|
// in a swarm has the same IP address.
|
||||||
allow_multiple_connections_per_ip = bool_type_base,
|
allow_multiple_connections_per_ip = bool_type_base,
|
||||||
|
|
||||||
|
@ -1047,7 +1047,7 @@ namespace libtorrent
|
||||||
//
|
//
|
||||||
// ``active_loaded_limit`` is the number of torrents that are allowed
|
// ``active_loaded_limit`` is the number of torrents that are allowed
|
||||||
// to be *loaded* at any given time. Note that a torrent can be active
|
// to be *loaded* at any given time. Note that a torrent can be active
|
||||||
// even though it's not loaded. if an unloaded torrents finds a peer
|
// even though it's not loaded. If an unloaded torrents finds a peer
|
||||||
// that wants to access it, the torrent will be loaded on demand,
|
// that wants to access it, the torrent will be loaded on demand,
|
||||||
// using a user-supplied callback function. If the feature of
|
// using a user-supplied callback function. If the feature of
|
||||||
// unloading torrents is not enabled, this setting have no effect. If
|
// unloading torrents is not enabled, this setting have no effect. If
|
||||||
|
|
|
@ -215,7 +215,7 @@ namespace libtorrent
|
||||||
// made synchronously. This means it has to wait for the main thread to
|
// made synchronously. This means it has to wait for the main thread to
|
||||||
// complete the query before it can return. This might potentially be
|
// complete the query before it can return. This might potentially be
|
||||||
// expensive if done from within a GUI thread that needs to stay
|
// expensive if done from within a GUI thread that needs to stay
|
||||||
// responsive. Try to avoid quering for information you don't need, and
|
// responsive. Try to avoid querying for information you don't need, and
|
||||||
// try to do it in as few calls as possible. You can get most of the
|
// try to do it in as few calls as possible. You can get most of the
|
||||||
// interesting information about a torrent from the
|
// interesting information about a torrent from the
|
||||||
// torrent_handle::status() call.
|
// torrent_handle::status() call.
|
||||||
|
@ -227,7 +227,7 @@ namespace libtorrent
|
||||||
//
|
//
|
||||||
// .. warning::
|
// .. warning::
|
||||||
// All operations on a torrent_handle may throw libtorrent_exception
|
// All operations on a torrent_handle may throw libtorrent_exception
|
||||||
// exception, in case the handle is no longer refering to a torrent.
|
// exception, in case the handle is no longer referring to a torrent.
|
||||||
// There is one exception is_valid() will never throw. Since the torrents
|
// There is one exception is_valid() will never throw. Since the torrents
|
||||||
// are processed by a background thread, there is no guarantee that a
|
// are processed by a background thread, there is no guarantee that a
|
||||||
// handle will remain valid between two calls.
|
// handle will remain valid between two calls.
|
||||||
|
@ -285,7 +285,7 @@ namespace libtorrent
|
||||||
// specified piece before calling this function.
|
// specified piece before calling this function.
|
||||||
//
|
//
|
||||||
// When the read operation is completed, it is passed back through an
|
// When the read operation is completed, it is passed back through an
|
||||||
// alert, read_piece_alert. Since this alert is a reponse to an explicit
|
// alert, read_piece_alert. Since this alert is a response to an explicit
|
||||||
// call, it will always be posted, regardless of the alert mask.
|
// call, it will always be posted, regardless of the alert mask.
|
||||||
//
|
//
|
||||||
// Note that if you read multiple pieces, the read operations are not
|
// Note that if you read multiple pieces, the read operations are not
|
||||||
|
@ -397,7 +397,7 @@ namespace libtorrent
|
||||||
// To query the priority of a torrent, use the
|
// To query the priority of a torrent, use the
|
||||||
// ``torrent_handle::status()`` call.
|
// ``torrent_handle::status()`` call.
|
||||||
//
|
//
|
||||||
// Torrents with higher priority will not nececcarily get as much
|
// Torrents with higher priority will not necessarily get as much
|
||||||
// bandwidth as they can consume, even if there's is more quota. Other
|
// bandwidth as they can consume, even if there's is more quota. Other
|
||||||
// peers will still be weighed in when bandwidth is being distributed.
|
// peers will still be weighed in when bandwidth is being distributed.
|
||||||
// With other words, bandwidth is not distributed strictly in order of
|
// With other words, bandwidth is not distributed strictly in order of
|
||||||
|
@ -709,7 +709,7 @@ namespace libtorrent
|
||||||
// resume data saved when they complete and on exit, since their
|
// resume data saved when they complete and on exit, since their
|
||||||
// statistics might be updated.
|
// statistics might be updated.
|
||||||
//
|
//
|
||||||
// In full allocation mode the reume data is never invalidated by
|
// In full allocation mode the resume data is never invalidated by
|
||||||
// subsequent writes to the files, since pieces won't move around. This
|
// subsequent writes to the files, since pieces won't move around. This
|
||||||
// means that you don't need to pause before writing resume data in full
|
// means that you don't need to pause before writing resume data in full
|
||||||
// or sparse mode. If you don't, however, any data written to disk after
|
// or sparse mode. If you don't, however, any data written to disk after
|
||||||
|
@ -835,7 +835,7 @@ namespace libtorrent
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
// deprecated in 1.1
|
// deprecated in 1.1
|
||||||
|
|
||||||
// Sets or gets the flag that derermines if countries should be resolved
|
// Sets or gets the flag that determines if countries should be resolved
|
||||||
// for the peers of this torrent. It defaults to false. If it is set to
|
// for the peers of this torrent. It defaults to false. If it is set to
|
||||||
// true, the peer_info structure for the peers in this torrent will have
|
// true, the peer_info structure for the peers in this torrent will have
|
||||||
// their ``country`` member set. See peer_info for more information on
|
// their ``country`` member set. See peer_info for more information on
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 0151d5c17fa3f4cf0ce518d0b8f90a23792c9b24
|
Subproject commit ad23c932ecd852f89c7d8b29dfe162e9ee073a1b
|
|
@ -663,7 +663,7 @@ TORRENT_TEST(try_next)
|
||||||
|
|
||||||
TEST_EQUAL(tr.size(), 3);
|
TEST_EQUAL(tr.size(), 3);
|
||||||
|
|
||||||
for (int i = 0; i < tr.size(); ++i)
|
for (int i = 0; i < int(tr.size()); ++i)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "tracker \"%s\"\n", tr[i].url.c_str());
|
fprintf(stderr, "tracker \"%s\"\n", tr[i].url.c_str());
|
||||||
if (tr[i].url == "http://tracker.com:8080/announce")
|
if (tr[i].url == "http://tracker.com:8080/announce")
|
||||||
|
@ -734,7 +734,7 @@ TORRENT_TEST(tracker_ipv6_argument)
|
||||||
got_announce = true;
|
got_announce = true;
|
||||||
bool const stop_event = req.find("&event=stopped") != std::string::npos;
|
bool const stop_event = req.find("&event=stopped") != std::string::npos;
|
||||||
// stop events don't need to advertise the IPv6 address
|
// stop events don't need to advertise the IPv6 address
|
||||||
int pos = req.find("&ipv6=");
|
std::string::size_type pos = req.find("&ipv6=");
|
||||||
TEST_CHECK(pos != std::string::npos || stop_event);
|
TEST_CHECK(pos != std::string::npos || stop_event);
|
||||||
got_ipv6 |= pos != std::string::npos;
|
got_ipv6 |= pos != std::string::npos;
|
||||||
return sim::send_response(200, "OK", 11) + "d5:peers0:e";
|
return sim::send_response(200, "OK", 11) + "d5:peers0:e";
|
||||||
|
@ -764,7 +764,7 @@ TORRENT_TEST(tracker_ipv6_argument_non_private)
|
||||||
, std::map<std::string, std::string>& headers)
|
, std::map<std::string, std::string>& headers)
|
||||||
{
|
{
|
||||||
got_announce = true;
|
got_announce = true;
|
||||||
int pos = req.find("&ipv6=");
|
std::string::size_type pos = req.find("&ipv6=");
|
||||||
TEST_CHECK(pos == std::string::npos);
|
TEST_CHECK(pos == std::string::npos);
|
||||||
got_ipv6 |= pos != std::string::npos;
|
got_ipv6 |= pos != std::string::npos;
|
||||||
return sim::send_response(200, "OK", 11) + "d5:peers0:e";
|
return sim::send_response(200, "OK", 11) + "d5:peers0:e";
|
||||||
|
@ -792,7 +792,7 @@ TORRENT_TEST(tracker_ipv6_argument_privacy_mode)
|
||||||
, std::map<std::string, std::string>& headers)
|
, std::map<std::string, std::string>& headers)
|
||||||
{
|
{
|
||||||
got_announce = true;
|
got_announce = true;
|
||||||
int pos = req.find("&ipv6=");
|
std::string::size_type pos = req.find("&ipv6=");
|
||||||
TEST_CHECK(pos == std::string::npos);
|
TEST_CHECK(pos == std::string::npos);
|
||||||
got_ipv6 |= pos != std::string::npos;
|
got_ipv6 |= pos != std::string::npos;
|
||||||
return sim::send_response(200, "OK", 11) + "d5:peers0:e";
|
return sim::send_response(200, "OK", 11) + "d5:peers0:e";
|
||||||
|
|
|
@ -43,6 +43,7 @@ libtorrent_rasterbar_la_SOURCES = \
|
||||||
bandwidth_manager.cpp \
|
bandwidth_manager.cpp \
|
||||||
bandwidth_queue_entry.cpp \
|
bandwidth_queue_entry.cpp \
|
||||||
bdecode.cpp \
|
bdecode.cpp \
|
||||||
|
bitfield.cpp \
|
||||||
bloom_filter.cpp \
|
bloom_filter.cpp \
|
||||||
broadcast_socket.cpp \
|
broadcast_socket.cpp \
|
||||||
block_cache.cpp \
|
block_cache.cpp \
|
||||||
|
|
|
@ -1236,6 +1236,11 @@ namespace libtorrent {
|
||||||
return torrent_alert::message() + msg;
|
return torrent_alert::message() + msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char const* torrent_error_alert::filename() const
|
||||||
|
{
|
||||||
|
return m_alloc.ptr(m_file_idx);
|
||||||
|
}
|
||||||
|
|
||||||
torrent_added_alert::torrent_added_alert(aux::stack_allocator& alloc
|
torrent_added_alert::torrent_added_alert(aux::stack_allocator& alloc
|
||||||
, torrent_handle const& h)
|
, torrent_handle const& h)
|
||||||
: torrent_alert(alloc, h)
|
: torrent_alert(alloc, h)
|
||||||
|
@ -1778,11 +1783,7 @@ namespace libtorrent {
|
||||||
|
|
||||||
char const* file_error_alert::filename() const
|
char const* file_error_alert::filename() const
|
||||||
{
|
{
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
|
||||||
return file.c_str();
|
|
||||||
#else
|
|
||||||
return m_alloc.ptr(m_file_idx);
|
return m_alloc.ptr(m_file_idx);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string file_error_alert::message() const
|
std::string file_error_alert::message() const
|
||||||
|
@ -1913,17 +1914,24 @@ namespace libtorrent {
|
||||||
return m_num_peers;
|
return m_num_peers;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dht_get_peers_reply_alert::peers(std::vector<tcp::endpoint>& peers) const
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
{
|
void dht_get_peers_reply_alert::peers(std::vector<tcp::endpoint> &v) const {
|
||||||
peers.resize(m_num_peers);
|
std::vector<tcp::endpoint> p(peers());
|
||||||
|
v.reserve(p.size());
|
||||||
|
std::copy(p.begin(), p.end(), std::back_inserter(v));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
std::vector<tcp::endpoint> dht_get_peers_reply_alert::peers() const {
|
||||||
|
std::vector<tcp::endpoint> peers(m_num_peers);
|
||||||
|
|
||||||
const char *ptr = m_alloc.ptr(m_peers_idx);
|
const char *ptr = m_alloc.ptr(m_peers_idx);
|
||||||
for (int i = 0; i < m_num_peers; i++) {
|
for (int i = 0; i < m_num_peers; i++) {
|
||||||
|
|
||||||
std::size_t size = detail::read_uint8(ptr);
|
std::size_t size = detail::read_uint8(ptr);
|
||||||
memcpy(peers[i].data(), ptr, size);
|
memcpy(peers[i].data(), ptr, size);
|
||||||
ptr += size;
|
ptr += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return peers;
|
||||||
}
|
}
|
||||||
|
|
||||||
dht_direct_response_alert::dht_direct_response_alert(
|
dht_direct_response_alert::dht_direct_response_alert(
|
||||||
|
|
|
@ -0,0 +1,160 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
Copyright (c) 2008-2016, Arvid Norberg
|
||||||
|
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 "libtorrent/bitfield.hpp"
|
||||||
|
#include "libtorrent/aux_/cpuid.hpp"
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#include <intrin.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace libtorrent
|
||||||
|
{
|
||||||
|
bool bitfield::all_set() const
|
||||||
|
{
|
||||||
|
const int words = size() / 32;
|
||||||
|
for (int i = 0; i < words; ++i)
|
||||||
|
{
|
||||||
|
if (m_buf[i] != 0xffffffff) return false;
|
||||||
|
}
|
||||||
|
int rest = size() & 31;
|
||||||
|
if (rest > 0)
|
||||||
|
{
|
||||||
|
boost::uint32_t mask = aux::host_to_network(0xffffffff << (32-rest));
|
||||||
|
if ((m_buf[words] & mask) != mask) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int bitfield::count() const
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
const int words = num_words();
|
||||||
|
#if TORRENT_HAS_SSE
|
||||||
|
if (aux::mmx_support)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < words; ++i)
|
||||||
|
{
|
||||||
|
#ifdef __GNUC__
|
||||||
|
ret += __builtin_popcount(m_buf[i]);
|
||||||
|
#else
|
||||||
|
ret += _mm_popcnt_u32(m_buf[i]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif // TORRENT_HAS_SSE
|
||||||
|
|
||||||
|
for (int i = 0; i < words; ++i)
|
||||||
|
{
|
||||||
|
boost::uint32_t v = m_buf[i];
|
||||||
|
// from:
|
||||||
|
// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
|
||||||
|
static const int S[] = {1, 2, 4, 8, 16}; // Magic Binary Numbers
|
||||||
|
static const int B[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF};
|
||||||
|
|
||||||
|
boost::uint32_t c = v - ((v >> 1) & B[0]);
|
||||||
|
c = ((c >> S[1]) & B[1]) + (c & B[1]);
|
||||||
|
c = ((c >> S[2]) + c) & B[2];
|
||||||
|
c = ((c >> S[3]) + c) & B[3];
|
||||||
|
c = ((c >> S[4]) + c) & B[4];
|
||||||
|
ret += c;
|
||||||
|
}
|
||||||
|
|
||||||
|
TORRENT_ASSERT(ret <= size());
|
||||||
|
TORRENT_ASSERT(ret >= 0);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bitfield::resize(int bits, bool val)
|
||||||
|
{
|
||||||
|
if (bits == size()) return;
|
||||||
|
|
||||||
|
int s = size();
|
||||||
|
int b = size() & 31;
|
||||||
|
resize(bits);
|
||||||
|
if (s >= size()) return;
|
||||||
|
int old_size_words = (s + 31) / 32;
|
||||||
|
int new_size_words = num_words();
|
||||||
|
if (val)
|
||||||
|
{
|
||||||
|
if (old_size_words && b) m_buf[old_size_words - 1] |= aux::host_to_network((0xffffffff >> b));
|
||||||
|
if (old_size_words < new_size_words)
|
||||||
|
std::memset(m_buf + old_size_words, 0xff
|
||||||
|
, size_t((new_size_words - old_size_words) * 4));
|
||||||
|
clear_trailing_bits();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (old_size_words < new_size_words)
|
||||||
|
std::memset(m_buf + old_size_words, 0x00
|
||||||
|
, size_t((new_size_words - old_size_words) * 4));
|
||||||
|
}
|
||||||
|
TORRENT_ASSERT(size() == bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
void bitfield::resize(int bits)
|
||||||
|
{
|
||||||
|
if (bits == size()) return;
|
||||||
|
|
||||||
|
TORRENT_ASSERT(bits >= 0);
|
||||||
|
// +1 because the first word is the size (in bits)
|
||||||
|
const int b = (bits + 31) / 32;
|
||||||
|
if (m_buf)
|
||||||
|
{
|
||||||
|
boost::uint32_t* tmp = static_cast<boost::uint32_t*>(std::realloc(m_buf-1, (b+1) * 4));
|
||||||
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
|
if (tmp == NULL) throw std::bad_alloc();
|
||||||
|
#endif
|
||||||
|
m_buf = tmp + 1;
|
||||||
|
m_buf[-1] = bits;
|
||||||
|
}
|
||||||
|
else if (bits > 0)
|
||||||
|
{
|
||||||
|
boost::uint32_t* tmp = static_cast<boost::uint32_t*>(std::malloc((b+1) * 4));
|
||||||
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
|
if (tmp == NULL) throw std::bad_alloc();
|
||||||
|
#endif
|
||||||
|
m_buf = tmp + 1;
|
||||||
|
m_buf[-1] = bits;
|
||||||
|
}
|
||||||
|
else if (m_buf != NULL)
|
||||||
|
{
|
||||||
|
std::free(m_buf-1);
|
||||||
|
m_buf = NULL;
|
||||||
|
}
|
||||||
|
clear_trailing_bits();
|
||||||
|
TORRENT_ASSERT(size() == bits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -172,7 +172,7 @@ namespace libtorrent
|
||||||
|| (e.mode & file::random_access) != (m & file::random_access))
|
|| (e.mode & file::random_access) != (m & file::random_access))
|
||||||
{
|
{
|
||||||
// close the file before we open it with
|
// close the file before we open it with
|
||||||
// the new read/write privilages, since windows may
|
// the new read/write privileges, since windows may
|
||||||
// file opening a file twice. However, since there may
|
// file opening a file twice. However, since there may
|
||||||
// be outstanding operations on it, we can't close the
|
// be outstanding operations on it, we can't close the
|
||||||
// file, we can only delete our reference to it.
|
// file, we can only delete our reference to it.
|
||||||
|
|
|
@ -167,7 +167,7 @@ namespace libtorrent
|
||||||
TORRENT_ASSERT_VAL(!tmp, tmp.message());
|
TORRENT_ASSERT_VAL(!tmp, tmp.message());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
m_sock.send(ep, p, len, ec);
|
m_sock.send(ep, p, len, ec, udp_socket::peer_connection);
|
||||||
#ifdef TORRENT_HAS_DONT_FRAGMENT
|
#ifdef TORRENT_HAS_DONT_FRAGMENT
|
||||||
if (flags & utp_socket_manager::dont_fragment)
|
if (flags & utp_socket_manager::dont_fragment)
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,10 +30,14 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef MAKE_TORRENT_HPP
|
||||||
|
#define MAKE_TORRENT_HPP
|
||||||
|
|
||||||
#include "libtorrent/torrent_info.hpp"
|
#include "libtorrent/torrent_info.hpp"
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "test.hpp"
|
||||||
|
|
||||||
enum flags_t
|
enum flags_t
|
||||||
{
|
{
|
||||||
|
@ -56,7 +60,10 @@ struct torrent_args
|
||||||
std::string m_http_seed;
|
std::string m_http_seed;
|
||||||
};
|
};
|
||||||
|
|
||||||
boost::shared_ptr<libtorrent::torrent_info> make_test_torrent(torrent_args const& args);
|
EXPORT boost::shared_ptr<libtorrent::torrent_info>
|
||||||
|
make_test_torrent(torrent_args const& args);
|
||||||
|
|
||||||
void generate_files(libtorrent::torrent_info const& ti, std::string const& path, bool random = false);
|
EXPORT void generate_files(libtorrent::torrent_info const& ti, std::string const& path, bool random = false);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,18 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef PEER_SERVER_HPP
|
||||||
|
#define PEER_SERVER_HPP
|
||||||
|
|
||||||
#include "test.hpp" // for EXPORT
|
#include "test.hpp" // for EXPORT
|
||||||
|
|
||||||
// returns the port the peer is running on
|
// returns the port the peer is running on
|
||||||
int EXPORT start_peer();
|
EXPORT int start_peer();
|
||||||
|
|
||||||
// the number of incoming connections to this peer
|
// the number of incoming connections to this peer
|
||||||
int EXPORT num_peer_hits();
|
EXPORT int num_peer_hits();
|
||||||
|
|
||||||
void EXPORT stop_peer();
|
EXPORT void stop_peer();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/session.hpp"
|
#include "libtorrent/session.hpp"
|
||||||
#include "test.hpp" // for EXPORT
|
#include "test.hpp" // for EXPORT
|
||||||
|
|
||||||
void EXPORT print_alerts(libtorrent::session* ses, libtorrent::time_point start_time);
|
EXPORT void print_alerts(libtorrent::session* ses, libtorrent::time_point start_time);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue