mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-03-10 04:21:18 +00:00
initialize libtorrent session with external ip set
This commit is contained in:
parent
fb00bb154e
commit
71e0da6705
@ -215,7 +215,8 @@ namespace libtorrent
|
|||||||
std::pair<int, int> listen_port_range
|
std::pair<int, int> listen_port_range
|
||||||
, fingerprint const& cl_fprint
|
, fingerprint const& cl_fprint
|
||||||
, char const* listen_interface
|
, char const* listen_interface
|
||||||
, boost::uint32_t alert_mask);
|
, boost::uint32_t alert_mask
|
||||||
|
, char const* ext_ip);
|
||||||
virtual ~session_impl();
|
virtual ~session_impl();
|
||||||
void update_dht_announce_interval();
|
void update_dht_announce_interval();
|
||||||
void init();
|
void init();
|
||||||
|
@ -139,10 +139,11 @@ namespace libtorrent
|
|||||||
, LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0)
|
, LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0)
|
||||||
, int flags = start_default_features | add_default_plugins
|
, int flags = start_default_features | add_default_plugins
|
||||||
, boost::uint32_t alert_mask = alert::error_notification
|
, boost::uint32_t alert_mask = alert::error_notification
|
||||||
|
, char const* ext_ip = NULL
|
||||||
TORRENT_LOGPATH_ARG_DEFAULT)
|
TORRENT_LOGPATH_ARG_DEFAULT)
|
||||||
{
|
{
|
||||||
TORRENT_CFG();
|
TORRENT_CFG();
|
||||||
init(std::make_pair(0, 0), "0.0.0.0", print, alert_mask);
|
init(std::make_pair(0, 0), "0.0.0.0", print, alert_mask, ext_ip);
|
||||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||||
set_log_path(logpath);
|
set_log_path(logpath);
|
||||||
#endif
|
#endif
|
||||||
@ -153,12 +154,13 @@ namespace libtorrent
|
|||||||
, char const* listen_interface = "0.0.0.0"
|
, char const* listen_interface = "0.0.0.0"
|
||||||
, int flags = start_default_features | add_default_plugins
|
, int flags = start_default_features | add_default_plugins
|
||||||
, int alert_mask = alert::error_notification
|
, int alert_mask = alert::error_notification
|
||||||
|
, char const* ext_ip = NULL
|
||||||
TORRENT_LOGPATH_ARG_DEFAULT)
|
TORRENT_LOGPATH_ARG_DEFAULT)
|
||||||
{
|
{
|
||||||
TORRENT_CFG();
|
TORRENT_CFG();
|
||||||
TORRENT_ASSERT(listen_port_range.first > 0);
|
TORRENT_ASSERT(listen_port_range.first > 0);
|
||||||
TORRENT_ASSERT(listen_port_range.first < listen_port_range.second);
|
TORRENT_ASSERT(listen_port_range.first < listen_port_range.second);
|
||||||
init(listen_port_range, listen_interface, print, alert_mask);
|
init(listen_port_range, listen_interface, print, alert_mask, ext_ip);
|
||||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||||
set_log_path(logpath);
|
set_log_path(logpath);
|
||||||
#endif
|
#endif
|
||||||
@ -851,7 +853,7 @@ namespace libtorrent
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
void init(std::pair<int, int> listen_range, char const* listen_interface
|
void init(std::pair<int, int> listen_range, char const* listen_interface
|
||||||
, fingerprint const& id, boost::uint32_t alert_mask);
|
, fingerprint const& id, boost::uint32_t alert_mask, char const* ext_ip);
|
||||||
void set_log_path(std::string const& p);
|
void set_log_path(std::string const& p);
|
||||||
void start(int flags);
|
void start(int flags);
|
||||||
|
|
||||||
|
@ -398,7 +398,7 @@ namespace libtorrent
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void session::init(std::pair<int, int> listen_range, char const* listen_interface
|
void session::init(std::pair<int, int> listen_range, char const* listen_interface
|
||||||
, fingerprint const& id, boost::uint32_t alert_mask)
|
, fingerprint const& id, boost::uint32_t alert_mask, char const* ext_ip)
|
||||||
{
|
{
|
||||||
#if defined _MSC_VER && defined TORRENT_DEBUG
|
#if defined _MSC_VER && defined TORRENT_DEBUG
|
||||||
// workaround for microsofts
|
// workaround for microsofts
|
||||||
@ -407,7 +407,7 @@ namespace libtorrent
|
|||||||
::_set_se_translator(straight_to_debugger);
|
::_set_se_translator(straight_to_debugger);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_impl.reset(new session_impl(listen_range, id, listen_interface, alert_mask));
|
m_impl.reset(new session_impl(listen_range, id, listen_interface, alert_mask, ext_ip));
|
||||||
|
|
||||||
#ifdef TORRENT_MEMDEBUG
|
#ifdef TORRENT_MEMDEBUG
|
||||||
start_malloc_debug();
|
start_malloc_debug();
|
||||||
|
@ -597,6 +597,7 @@ namespace aux {
|
|||||||
, fingerprint const& cl_fprint
|
, fingerprint const& cl_fprint
|
||||||
, char const* listen_interface
|
, char const* listen_interface
|
||||||
, boost::uint32_t alert_mask
|
, boost::uint32_t alert_mask
|
||||||
|
, char const* ext_ip
|
||||||
)
|
)
|
||||||
: m_ipv4_peer_pool(500)
|
: m_ipv4_peer_pool(500)
|
||||||
#if TORRENT_USE_IPV6
|
#if TORRENT_USE_IPV6
|
||||||
@ -711,6 +712,10 @@ namespace aux {
|
|||||||
m_listen_interface = tcp::endpoint(address::from_string(listen_interface, ec), listen_port_range.first);
|
m_listen_interface = tcp::endpoint(address::from_string(listen_interface, ec), listen_port_range.first);
|
||||||
TORRENT_ASSERT_VAL(!ec, ec);
|
TORRENT_ASSERT_VAL(!ec, ec);
|
||||||
|
|
||||||
|
if (ext_ip) {
|
||||||
|
m_external_ip.cast_vote(address::from_string(ext_ip), source_router, address());
|
||||||
|
}
|
||||||
|
|
||||||
// ---- generate a peer id ----
|
// ---- generate a peer id ----
|
||||||
static seed_random_generator seeder;
|
static seed_random_generator seeder;
|
||||||
|
|
||||||
|
32
src/init.cpp
32
src/init.cpp
@ -961,16 +961,34 @@ bool AppInit2(boost::thread_group& threadGroup)
|
|||||||
#include "libtorrent/bencode.hpp"
|
#include "libtorrent/bencode.hpp"
|
||||||
#include "libtorrent/session.hpp"
|
#include "libtorrent/session.hpp"
|
||||||
|
|
||||||
|
#define TORRENT_DISABLE_GEO_IP
|
||||||
|
#include "libtorrent/aux_/session_impl.hpp"
|
||||||
|
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
static session *ses;
|
static session *ses;
|
||||||
|
|
||||||
void startSessionTorrent(boost::thread_group& threadGroup)
|
void ThreadWaitExtIP()
|
||||||
{
|
{
|
||||||
|
RenameThread("wait-extip");
|
||||||
|
|
||||||
|
std::string ipStr;
|
||||||
|
|
||||||
|
// wait up to 5 seconds for bitcoin to get the external IP
|
||||||
|
for( int i = 0; i < 10; i++ ) {
|
||||||
|
const CNetAddr paddrPeer("8.8.8.8");
|
||||||
|
CAddress addr( GetLocalAddress(&paddrPeer) );
|
||||||
|
if( addr != CAddress() ) {
|
||||||
|
ipStr = addr.ToStringIP();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
MilliSleep(500);
|
||||||
|
}
|
||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
int listen_port = GetListenPort() + 1000;
|
int listen_port = GetListenPort() + 1000;
|
||||||
std::string bind_to_interface = "";
|
std::string bind_to_interface = "";
|
||||||
|
|
||||||
printf("startSessionTorrent port=%d\n", listen_port);
|
printf("Creating new libtorrent session ext_ip=%s port=%d\n", ipStr.c_str(), listen_port);
|
||||||
|
|
||||||
ses = new session(fingerprint("LT", LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0)
|
ses = new session(fingerprint("LT", LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0)
|
||||||
, session::add_default_plugins
|
, session::add_default_plugins
|
||||||
@ -978,7 +996,8 @@ void startSessionTorrent(boost::thread_group& threadGroup)
|
|||||||
& ~(alert::dht_notification
|
& ~(alert::dht_notification
|
||||||
+ alert::progress_notification
|
+ alert::progress_notification
|
||||||
+ alert::debug_notification
|
+ alert::debug_notification
|
||||||
+ alert::stats_notification));
|
+ alert::stats_notification)
|
||||||
|
, ipStr.size() ? ipStr.c_str() : NULL );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
std::vector<char> in;
|
std::vector<char> in;
|
||||||
@ -1003,3 +1022,10 @@ void startSessionTorrent(boost::thread_group& threadGroup)
|
|||||||
printf("libtorrent + dht started\n");
|
printf("libtorrent + dht started\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void startSessionTorrent(boost::thread_group& threadGroup)
|
||||||
|
{
|
||||||
|
printf("startSessionTorrent (waiting for external IP)\n");
|
||||||
|
|
||||||
|
threadGroup.create_thread(boost::bind(&ThreadWaitExtIP));
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user