mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-05 16:08:40 +00:00
libtorrent upnp fix, compilation fix 1577
This commit is contained in:
parent
4fbef5d94a
commit
a93c236e0e
10 changed files with 78 additions and 32 deletions
|
@ -33,12 +33,14 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
#if defined __linux__ && defined __GNUC__
|
#if (defined __linux__ || defined __MACH__) && defined __GNUC__
|
||||||
#ifdef assert
|
#ifdef assert
|
||||||
#undef assert
|
#undef assert
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void assert_fail(const char* expr, int line, char const* file, char const* function);
|
#include "libtorrent/config.hpp"
|
||||||
|
|
||||||
|
TORRENT_EXPORT void assert_fail(const char* expr, int line, char const* file, char const* function);
|
||||||
|
|
||||||
#define assert(x) if (x) {} else assert_fail(#x, __LINE__, __FILE__, __PRETTY_FUNCTION__)
|
#define assert(x) if (x) {} else assert_fail(#x, __LINE__, __FILE__, __PRETTY_FUNCTION__)
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#define TORRENT_CONFIG_HPP_INCLUDED
|
#define TORRENT_CONFIG_HPP_INCLUDED
|
||||||
|
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include "libtorrent/assert.hpp"
|
|
||||||
|
|
||||||
#if defined(__GNUC__) && __GNUC__ >= 4
|
#if defined(__GNUC__) && __GNUC__ >= 4
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef TORRENT_DISK_STATS
|
||||||
|
#include <fstream>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "libtorrent/storage.hpp"
|
#include "libtorrent/storage.hpp"
|
||||||
#include <boost/thread/thread.hpp>
|
#include <boost/thread/thread.hpp>
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
|
@ -122,6 +126,10 @@ namespace libtorrent
|
||||||
int m_block_size;
|
int m_block_size;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef TORRENT_DISK_STATS
|
||||||
|
std::ofstream m_log;
|
||||||
|
#endif
|
||||||
|
|
||||||
// thread for performing blocking disk io operations
|
// thread for performing blocking disk io operations
|
||||||
boost::thread m_disk_io_thread;
|
boost::thread m_disk_io_thread;
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,7 +42,7 @@ namespace libtorrent
|
||||||
template<class T>
|
template<class T>
|
||||||
struct intrusive_ptr_base
|
struct intrusive_ptr_base
|
||||||
{
|
{
|
||||||
intrusive_ptr_base(const intrusive_ptr_base<T>& b)
|
intrusive_ptr_base(intrusive_ptr_base<T> const&)
|
||||||
: m_refs(0) {}
|
: m_refs(0) {}
|
||||||
|
|
||||||
friend void intrusive_ptr_add_ref(intrusive_ptr_base<T> const* s)
|
friend void intrusive_ptr_add_ref(intrusive_ptr_base<T> const* s)
|
||||||
|
|
|
@ -13,7 +13,7 @@ kademlia/traversal_algorithm.cpp
|
||||||
endif
|
endif
|
||||||
|
|
||||||
libtorrent_la_SOURCES = entry.cpp escape_string.cpp \
|
libtorrent_la_SOURCES = entry.cpp escape_string.cpp \
|
||||||
enum_net.cpp broadcast_socket.cpp \
|
assert.cpp enum_net.cpp broadcast_socket.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 \
|
||||||
|
@ -28,6 +28,7 @@ $(kademlia_sources)
|
||||||
noinst_HEADERS = \
|
noinst_HEADERS = \
|
||||||
$(top_srcdir)/include/libtorrent/alert.hpp \
|
$(top_srcdir)/include/libtorrent/alert.hpp \
|
||||||
$(top_srcdir)/include/libtorrent/alert_types.hpp \
|
$(top_srcdir)/include/libtorrent/alert_types.hpp \
|
||||||
|
$(top_srcdir)/include/libtorrent/assert.hpp \
|
||||||
$(top_srcdir)/include/libtorrent/aux_/session_impl.hpp \
|
$(top_srcdir)/include/libtorrent/aux_/session_impl.hpp \
|
||||||
$(top_srcdir)/include/libtorrent/bandwidth_manager.hpp \
|
$(top_srcdir)/include/libtorrent/bandwidth_manager.hpp \
|
||||||
$(top_srcdir)/include/libtorrent/bencode.hpp \
|
$(top_srcdir)/include/libtorrent/bencode.hpp \
|
||||||
|
|
|
@ -34,7 +34,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#if defined __linux__ && defined __GNUC__
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void assert_fail(char const* expr, int line, char const* file, char const* function)
|
void assert_fail(char const* expr, int line, char const* file, char const* function)
|
||||||
{
|
{
|
||||||
|
@ -48,6 +51,7 @@ void assert_fail(char const* expr, int line, char const* file, char const* funct
|
||||||
"expression: %s\n"
|
"expression: %s\n"
|
||||||
"stack:\n", file, line, function, expr);
|
"stack:\n", file, line, function, expr);
|
||||||
|
|
||||||
|
#if defined __linux__ && defined __GNUC__
|
||||||
void* stack[50];
|
void* stack[50];
|
||||||
int size = backtrace(stack, 50);
|
int size = backtrace(stack, 50);
|
||||||
char** symbols = backtrace_symbols(stack, size);
|
char** symbols = backtrace_symbols(stack, size);
|
||||||
|
@ -58,7 +62,11 @@ void assert_fail(char const* expr, int line, char const* file, char const* funct
|
||||||
}
|
}
|
||||||
|
|
||||||
free(symbols);
|
free(symbols);
|
||||||
exit(1);
|
#endif
|
||||||
|
// send SIGINT to the current process
|
||||||
|
// to break into the debugger
|
||||||
|
raise(SIGINT);
|
||||||
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -34,6 +34,24 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include "libtorrent/disk_io_thread.hpp"
|
#include "libtorrent/disk_io_thread.hpp"
|
||||||
|
|
||||||
|
#ifdef TORRENT_DISK_STATS
|
||||||
|
|
||||||
|
#include "libtorrent/time.hpp"
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
std::string log_time()
|
||||||
|
{
|
||||||
|
using namespace libtorrent;
|
||||||
|
static ptime start = time_now();
|
||||||
|
return boost::lexical_cast<std::string>(
|
||||||
|
total_milliseconds(time_now() - start));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -45,7 +63,12 @@ namespace libtorrent
|
||||||
, m_block_size(block_size)
|
, m_block_size(block_size)
|
||||||
#endif
|
#endif
|
||||||
, m_disk_io_thread(boost::ref(*this))
|
, m_disk_io_thread(boost::ref(*this))
|
||||||
{}
|
{
|
||||||
|
|
||||||
|
#ifdef TORRENT_DISK_STATS
|
||||||
|
m_log.open("disk_io_thread.log", std::ios::trunc);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
disk_io_thread::~disk_io_thread()
|
disk_io_thread::~disk_io_thread()
|
||||||
{
|
{
|
||||||
|
@ -172,6 +195,9 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
#ifdef TORRENT_DISK_STATS
|
||||||
|
m_log << log_time() << " idle" << std::endl;
|
||||||
|
#endif
|
||||||
boost::mutex::scoped_lock l(m_mutex);
|
boost::mutex::scoped_lock l(m_mutex);
|
||||||
while (m_jobs.empty() && !m_abort)
|
while (m_jobs.empty() && !m_abort)
|
||||||
m_signal.wait(l);
|
m_signal.wait(l);
|
||||||
|
@ -189,10 +215,16 @@ namespace libtorrent
|
||||||
bool free_buffer = true;
|
bool free_buffer = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
#ifdef TORRENT_DISK_STATS
|
||||||
|
ptime start = time_now();
|
||||||
|
#endif
|
||||||
// std::cerr << "DISK THREAD: executing job: " << j.action << std::endl;
|
// std::cerr << "DISK THREAD: executing job: " << j.action << std::endl;
|
||||||
switch (j.action)
|
switch (j.action)
|
||||||
{
|
{
|
||||||
case disk_io_job::read:
|
case disk_io_job::read:
|
||||||
|
#ifdef TORRENT_DISK_STATS
|
||||||
|
m_log << log_time() << " read " << j.buffer_size << std::endl;
|
||||||
|
#endif
|
||||||
if (j.buffer == 0)
|
if (j.buffer == 0)
|
||||||
{
|
{
|
||||||
l.lock();
|
l.lock();
|
||||||
|
@ -217,6 +249,9 @@ namespace libtorrent
|
||||||
// usleep(300);
|
// usleep(300);
|
||||||
break;
|
break;
|
||||||
case disk_io_job::write:
|
case disk_io_job::write:
|
||||||
|
#ifdef TORRENT_DISK_STATS
|
||||||
|
m_log << log_time() << " write " << j.buffer_size << std::endl;
|
||||||
|
#endif
|
||||||
assert(j.buffer);
|
assert(j.buffer);
|
||||||
assert(j.buffer_size <= m_block_size);
|
assert(j.buffer_size <= m_block_size);
|
||||||
j.storage->write_impl(j.buffer, j.piece, j.offset
|
j.storage->write_impl(j.buffer, j.piece, j.offset
|
||||||
|
@ -227,16 +262,25 @@ namespace libtorrent
|
||||||
break;
|
break;
|
||||||
case disk_io_job::hash:
|
case disk_io_job::hash:
|
||||||
{
|
{
|
||||||
|
#ifdef TORRENT_DISK_STATS
|
||||||
|
m_log << log_time() << " hash" << std::endl;
|
||||||
|
#endif
|
||||||
sha1_hash h = j.storage->hash_for_piece_impl(j.piece);
|
sha1_hash h = j.storage->hash_for_piece_impl(j.piece);
|
||||||
j.str.resize(20);
|
j.str.resize(20);
|
||||||
std::memcpy(&j.str[0], &h[0], 20);
|
std::memcpy(&j.str[0], &h[0], 20);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case disk_io_job::move_storage:
|
case disk_io_job::move_storage:
|
||||||
|
#ifdef TORRENT_DISK_STATS
|
||||||
|
m_log << log_time() << " move" << std::endl;
|
||||||
|
#endif
|
||||||
ret = j.storage->move_storage_impl(j.str) ? 1 : 0;
|
ret = j.storage->move_storage_impl(j.str) ? 1 : 0;
|
||||||
j.str = j.storage->save_path().string();
|
j.str = j.storage->save_path().string();
|
||||||
break;
|
break;
|
||||||
case disk_io_job::release_files:
|
case disk_io_job::release_files:
|
||||||
|
#ifdef TORRENT_DISK_STATS
|
||||||
|
m_log << log_time() << " release" << std::endl;
|
||||||
|
#endif
|
||||||
j.storage->release_files_impl();
|
j.storage->release_files_impl();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2915,11 +2915,6 @@ namespace libtorrent
|
||||||
// TODO: the timeout should be called by an event
|
// TODO: the timeout should be called by an event
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
// allow step debugging without timing out
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ptime now(time_now());
|
ptime now(time_now());
|
||||||
|
|
||||||
// if the socket is still connecting, don't
|
// if the socket is still connecting, don't
|
||||||
|
@ -2933,6 +2928,10 @@ namespace libtorrent
|
||||||
d = now - m_last_receive;
|
d = now - m_last_receive;
|
||||||
if (d > seconds(m_timeout)) return true;
|
if (d > seconds(m_timeout)) return true;
|
||||||
|
|
||||||
|
// if it takes more than 5 seconds to receive
|
||||||
|
// handshake, disconnect
|
||||||
|
if (in_handshake() && d > seconds(5)) return true;
|
||||||
|
|
||||||
// disconnect peers that we unchoked, but
|
// disconnect peers that we unchoked, but
|
||||||
// they didn't send a request within 20 seconds.
|
// they didn't send a request within 20 seconds.
|
||||||
// but only if we're a seed
|
// but only if we're a seed
|
||||||
|
|
|
@ -1478,7 +1478,7 @@ namespace libtorrent
|
||||||
|
|
||||||
k = std::find(backup_blocks.begin()
|
k = std::find(backup_blocks.begin()
|
||||||
, backup_blocks.end(), piece_block(i->index, j));
|
, backup_blocks.end(), piece_block(i->index, j));
|
||||||
if (k != interesting_blocks.end()) continue;
|
if (k != backup_blocks.end()) continue;
|
||||||
|
|
||||||
std::cerr << "interesting blocks:" << std::endl;
|
std::cerr << "interesting blocks:" << std::endl;
|
||||||
for (k = interesting_blocks.begin(); k != interesting_blocks.end(); ++k)
|
for (k = interesting_blocks.begin(); k != interesting_blocks.end(); ++k)
|
||||||
|
@ -1911,4 +1911,3 @@ namespace libtorrent
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -258,7 +258,7 @@ try
|
||||||
{
|
{
|
||||||
#ifdef TORRENT_UPNP_LOGGING
|
#ifdef TORRENT_UPNP_LOGGING
|
||||||
m_log << time_now_string()
|
m_log << time_now_string()
|
||||||
<< " <== Rootdevice responded with incorrect HTTP packet. Ignoring device" << std::endl;
|
<< " <== Rootdevice responded with incorrect HTTP packet. Ignoring device (" << e.what() << ")" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -760,22 +760,8 @@ void upnp::on_upnp_map_response(asio::error_code const& e
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.status_code() != 200)
|
// We don't want to ignore responses with return codes other than 200
|
||||||
{
|
// since those might contain valid UPnP error codes
|
||||||
#ifdef TORRENT_UPNP_LOGGING
|
|
||||||
m_log << time_now_string()
|
|
||||||
<< " <== error while adding portmap: " << p.status_code() << " " << p.message() << std::endl;
|
|
||||||
#endif
|
|
||||||
for (int i = 0; i < num_mappings; ++i)
|
|
||||||
{
|
|
||||||
if (d.mapping[i].need_update)
|
|
||||||
{
|
|
||||||
map_port(d, i);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_code_parse_state s;
|
error_code_parse_state s;
|
||||||
xml_parse((char*)p.get_body().begin, (char*)p.get_body().end
|
xml_parse((char*)p.get_body().begin, (char*)p.get_body().end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue