libtorrent sync 1442

This commit is contained in:
Marcos Pinto 2007-08-10 06:22:28 +00:00
parent 51376bd2be
commit 28ad94ea6e
7 changed files with 93 additions and 90 deletions

View File

@ -90,47 +90,47 @@ struct bandwidth_limit
{
static const int inf = boost::integer_traits<int>::const_max;
bandwidth_limit()
bandwidth_limit() throw()
: m_quota_left(0)
, m_local_limit(inf)
, m_current_rate(0)
{}
void throttle(int limit)
void throttle(int limit) throw()
{
m_local_limit = limit;
}
int throttle() const
int throttle() const throw()
{
return m_local_limit;
}
void assign(int amount)
void assign(int amount) throw()
{
assert(amount > 0);
m_current_rate += amount;
m_quota_left += amount;
}
void use_quota(int amount)
void use_quota(int amount) throw()
{
assert(amount <= m_quota_left);
m_quota_left -= amount;
}
int quota_left() const
int quota_left() const throw()
{
return (std::max)(m_quota_left, 0);
}
void expire(int amount)
void expire(int amount) throw()
{
assert(amount >= 0);
m_current_rate -= amount;
}
int max_assignable() const
int max_assignable() const throw()
{
if (m_local_limit == inf) return inf;
if (m_local_limit <= m_current_rate) return 0;
@ -160,7 +160,7 @@ private:
};
template<class T>
T clamp(T val, T ceiling, T floor)
T clamp(T val, T ceiling, T floor) throw()
{
assert(ceiling >= floor);
if (val >= ceiling) return ceiling;
@ -171,7 +171,7 @@ T clamp(T val, T ceiling, T floor)
template<class PeerConnection, class Torrent>
struct bandwidth_manager
{
bandwidth_manager(io_service& ios, int channel)
bandwidth_manager(io_service& ios, int channel) throw()
: m_ios(ios)
, m_history_timer(m_ios)
, m_limit(bandwidth_limit::inf)
@ -179,14 +179,14 @@ struct bandwidth_manager
, m_channel(channel)
{}
void throttle(int limit)
void throttle(int limit) throw()
{
mutex_t::scoped_lock l(m_mutex);
assert(limit >= 0);
m_limit = limit;
}
int throttle() const
int throttle() const throw()
{
mutex_t::scoped_lock l(m_mutex);
return m_limit;
@ -197,7 +197,7 @@ struct bandwidth_manager
// this is used by web seeds
void request_bandwidth(intrusive_ptr<PeerConnection> peer
, int blk
, bool non_prioritized)
, bool non_prioritized) throw()
{
INVARIANT_CHECK;
assert(blk > 0);
@ -257,8 +257,11 @@ struct bandwidth_manager
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;
m_history.push_front(e);
m_current_quota += e.amount;
@ -268,11 +271,17 @@ private:
m_history_timer.expires_at(e.expires_at);
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;
if (e) return;
@ -303,14 +312,20 @@ private:
// means we can hand out more (in case there
// are still consumers in line)
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;
ptime now(time_now());
@ -404,9 +419,12 @@ private:
add_history_entry(history_entry<PeerConnection, Torrent>(
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;

View File

@ -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_regex.m4 \
$(top_srcdir)/m4/ax_boost_thread.m4 \
$(top_srcdir)/m4/check_ssl.m4 $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/configure.in
$(top_srcdir)/m4/check_ssl.m4 $(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
@ -65,9 +63,8 @@ am__installdirs = "$(DESTDIR)$(libdir)"
libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES)
libtorrent_la_DEPENDENCIES =
am__libtorrent_la_SOURCES_DIST = allocate_resources.cpp \
bandwidth_manager.cpp entry.cpp escape_string.cpp \
peer_connection.cpp bt_peer_connection.cpp \
am__libtorrent_la_SOURCES_DIST = allocate_resources.cpp entry.cpp \
escape_string.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 stat.cpp storage.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@ routing_table.lo rpc_manager.lo \
@USE_DHT_TRUE@ traversal_algorithm.lo
am_libtorrent_la_OBJECTS = allocate_resources.lo bandwidth_manager.lo \
entry.lo escape_string.lo peer_connection.lo \
bt_peer_connection.lo web_peer_connection.lo natpmp.lo \
piece_picker.lo policy.lo session.lo session_impl.lo sha1.lo \
stat.lo storage.lo torrent.lo torrent_handle.lo pe_crypto.lo \
torrent_info.lo tracker_manager.lo http_connection.lo \
am_libtorrent_la_OBJECTS = allocate_resources.lo entry.lo \
escape_string.lo peer_connection.lo bt_peer_connection.lo \
web_peer_connection.lo natpmp.lo piece_picker.lo policy.lo \
session.lo session_impl.lo sha1.lo stat.lo storage.lo \
torrent.lo torrent_handle.lo pe_crypto.lo torrent_info.lo \
tracker_manager.lo http_connection.lo \
http_tracker_connection.lo udp_tracker_connection.lo alert.lo \
identify_client.lo ip_filter.lo file.lo metadata_transfer.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
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 \
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 \
@ -332,7 +329,7 @@ $(top_srcdir)/include/libtorrent/version.hpp
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@
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@
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)/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)/closest_nodes.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/connection_queue.Plo@am__quote@

View File

@ -248,17 +248,11 @@ namespace libtorrent
void set_size(size_type s)
{
size_type pos = tell();
// Only set size if current file size not equals s.
// 2 as "m" argument is to be sure seek() sets SEEK_END on
// all compilers.
if(s != seek(0, 2))
{
seek(s - 1);
char dummy = 0;
read(&dummy, 1);
seek(s - 1);
write(&dummy, 1);
}
seek(s - 1);
char dummy = 0;
read(&dummy, 1);
seek(s - 1);
write(&dummy, 1);
seek(pos);
}

View File

@ -1019,6 +1019,7 @@ namespace libtorrent
return true;
}
// workaround for bugs in Mac OS X where zero run is not reported
if (!strcmp(fsinfo.f_fstypename, "hfs")
|| !strcmp(fsinfo.f_fstypename, "ufs"))
return true;
@ -1026,7 +1027,7 @@ namespace libtorrent
return false;
#endif
#if defined(__linux__)
#if defined(__linux__) || defined(__FreeBSD__)
struct statfs buf;
int err = statfs(query_path.native_directory_string().c_str(), &buf);
if (err == 0)
@ -1059,11 +1060,7 @@ namespace libtorrent
#endif
// TODO: POSIX implementation
#if defined(__FreeBSD__)
return true;
#else
return false;
#endif
}
// -- piece_manager -----------------------------------------------------
@ -1575,16 +1572,12 @@ namespace libtorrent
}
if (m_unallocated_slots.empty())
{
m_state = state_create_files;
return false;
}
if (m_compact_mode)
{
else if (m_compact_mode)
m_state = state_create_files;
return false;
}
else
m_state = state_allocating;
return false;
}
m_state = state_full_check;
@ -1604,7 +1597,7 @@ namespace libtorrent
| |
| v
| +------------+
| | allocating |
|->| allocating |
| +------------+
| |
| v

View File

@ -1109,7 +1109,7 @@ namespace libtorrent
void torrent::set_piece_priority(int index, int priority)
{
INVARIANT_CHECK;
// INVARIANT_CHECK;
assert(valid_metadata());
if (is_seed()) return;
@ -1125,7 +1125,7 @@ namespace libtorrent
int torrent::piece_priority(int index) const
{
INVARIANT_CHECK;
// INVARIANT_CHECK;
assert(valid_metadata());
if (is_seed()) return 1;

View File

@ -62,7 +62,7 @@ namespace libtorrent
{
if (a.is_v6()) return false;
address_v4 a4 = a.to_v4();
unsigned long ip = htonl(a4.to_ulong());
unsigned long ip = a4.to_ulong();
return ((ip & 0xff000000) == 0x0a000000
|| (ip & 0xfff00000) == 0xac100000
|| (ip & 0xffff0000) == 0xc0a80000);

View File

@ -197,39 +197,41 @@ namespace libtorrent { namespace
}
virtual bool on_extended(int length, int msg, buffer::const_interval body)
try
{
if (msg != extension_index) return false;
if (m_message_index == 0) return false;
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;
entry pex_msg = bdecode(body.begin, body.end);
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)
try
{
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);
}
return true;
}
catch (std::exception&)
{
entry pex_msg = bdecode(body.begin, body.end);
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);
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;
}