mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-11 15:27:57 +00:00
create new twister.cpp with libtorrent initialization
This commit is contained in:
parent
71e0da6705
commit
187904d1e8
79
src/init.cpp
79
src/init.cpp
@ -14,6 +14,7 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "ui_interface.h"
|
#include "ui_interface.h"
|
||||||
#include "checkpoints.h"
|
#include "checkpoints.h"
|
||||||
|
#include "twister.h"
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/filesystem/fstream.hpp>
|
#include <boost/filesystem/fstream.hpp>
|
||||||
@ -32,8 +33,6 @@ using namespace boost;
|
|||||||
CWallet* pwalletMain;
|
CWallet* pwalletMain;
|
||||||
CClientUIInterface uiInterface;
|
CClientUIInterface uiInterface;
|
||||||
|
|
||||||
void startSessionTorrent(boost::thread_group& threadGroup);
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// Win32 LevelDB doesn't use filedescriptors, and the ones used for
|
// Win32 LevelDB doesn't use filedescriptors, and the ones used for
|
||||||
// accessing block files, don't count towards to fd_set size limit
|
// accessing block files, don't count towards to fd_set size limit
|
||||||
@ -949,83 +948,9 @@ bool AppInit2(boost::thread_group& threadGroup)
|
|||||||
// Run a thread to flush wallet periodically
|
// Run a thread to flush wallet periodically
|
||||||
threadGroup.create_thread(boost::bind(&ThreadFlushWalletDB, boost::ref(pwalletMain->strWalletFile)));
|
threadGroup.create_thread(boost::bind(&ThreadFlushWalletDB, boost::ref(pwalletMain->strWalletFile)));
|
||||||
|
|
||||||
|
// Start libtorrent + dht
|
||||||
startSessionTorrent(threadGroup);
|
startSessionTorrent(threadGroup);
|
||||||
|
|
||||||
return !fRequestShutdown;
|
return !fRequestShutdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===================== LIBTORRENT & DHT ===========================
|
|
||||||
|
|
||||||
#include "libtorrent/config.hpp"
|
|
||||||
#include "libtorrent/entry.hpp"
|
|
||||||
#include "libtorrent/bencode.hpp"
|
|
||||||
#include "libtorrent/session.hpp"
|
|
||||||
|
|
||||||
#define TORRENT_DISABLE_GEO_IP
|
|
||||||
#include "libtorrent/aux_/session_impl.hpp"
|
|
||||||
|
|
||||||
using namespace libtorrent;
|
|
||||||
static session *ses;
|
|
||||||
|
|
||||||
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;
|
|
||||||
int listen_port = GetListenPort() + 1000;
|
|
||||||
std::string bind_to_interface = "";
|
|
||||||
|
|
||||||
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)
|
|
||||||
, session::add_default_plugins
|
|
||||||
, alert::all_categories
|
|
||||||
& ~(alert::dht_notification
|
|
||||||
+ alert::progress_notification
|
|
||||||
+ alert::debug_notification
|
|
||||||
+ alert::stats_notification)
|
|
||||||
, ipStr.size() ? ipStr.c_str() : NULL );
|
|
||||||
|
|
||||||
/*
|
|
||||||
std::vector<char> in;
|
|
||||||
if (load_file(".ses_state", in, ec) == 0)
|
|
||||||
{
|
|
||||||
lazy_entry e;
|
|
||||||
if (lazy_bdecode(&in[0], &in[0] + in.size(), e, ec) == 0)
|
|
||||||
ses.load_state(e);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
ses->listen_on(std::make_pair(listen_port, listen_port)
|
|
||||||
, ec, bind_to_interface.c_str());
|
|
||||||
if (ec)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "failed to listen%s%s on ports %d-%d: %s\n"
|
|
||||||
, bind_to_interface.empty() ? "" : " on ", bind_to_interface.c_str()
|
|
||||||
, listen_port, listen_port+1, ec.message().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
ses->start_dht();
|
|
||||||
printf("libtorrent + dht started\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void startSessionTorrent(boost::thread_group& threadGroup)
|
|
||||||
{
|
|
||||||
printf("startSessionTorrent (waiting for external IP)\n");
|
|
||||||
|
|
||||||
threadGroup.create_thread(boost::bind(&ThreadWaitExtIP));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
83
src/twister.cpp
Normal file
83
src/twister.cpp
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
#include "twister.h"
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
twister::twister()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===================== LIBTORRENT & DHT ===========================
|
||||||
|
|
||||||
|
#include "libtorrent/config.hpp"
|
||||||
|
#include "libtorrent/entry.hpp"
|
||||||
|
#include "libtorrent/bencode.hpp"
|
||||||
|
#include "libtorrent/session.hpp"
|
||||||
|
|
||||||
|
#define TORRENT_DISABLE_GEO_IP
|
||||||
|
#include "libtorrent/aux_/session_impl.hpp"
|
||||||
|
|
||||||
|
using namespace libtorrent;
|
||||||
|
static session *ses;
|
||||||
|
|
||||||
|
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.IsValid() ) {
|
||||||
|
ipStr = addr.ToStringIP();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
MilliSleep(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
error_code ec;
|
||||||
|
int listen_port = GetListenPort() + LIBTORRENT_PORT_OFFSET;
|
||||||
|
std::string bind_to_interface = "";
|
||||||
|
|
||||||
|
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)
|
||||||
|
, session::add_default_plugins
|
||||||
|
, alert::all_categories
|
||||||
|
& ~(alert::dht_notification
|
||||||
|
+ alert::progress_notification
|
||||||
|
+ alert::debug_notification
|
||||||
|
+ alert::stats_notification)
|
||||||
|
, ipStr.size() ? ipStr.c_str() : NULL );
|
||||||
|
|
||||||
|
/*
|
||||||
|
std::vector<char> in;
|
||||||
|
if (load_file(".ses_state", in, ec) == 0)
|
||||||
|
{
|
||||||
|
lazy_entry e;
|
||||||
|
if (lazy_bdecode(&in[0], &in[0] + in.size(), e, ec) == 0)
|
||||||
|
ses.load_state(e);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
ses->listen_on(std::make_pair(listen_port, listen_port)
|
||||||
|
, ec, bind_to_interface.c_str());
|
||||||
|
if (ec)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "failed to listen%s%s on ports %d-%d: %s\n"
|
||||||
|
, bind_to_interface.empty() ? "" : " on ", bind_to_interface.c_str()
|
||||||
|
, listen_port, listen_port+1, ec.message().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
ses->start_dht();
|
||||||
|
printf("libtorrent + dht started\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void startSessionTorrent(boost::thread_group& threadGroup)
|
||||||
|
{
|
||||||
|
printf("startSessionTorrent (waiting for external IP)\n");
|
||||||
|
|
||||||
|
threadGroup.create_thread(boost::bind(&ThreadWaitExtIP));
|
||||||
|
}
|
||||||
|
|
17
src/twister.h
Normal file
17
src/twister.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef TWISTER_H
|
||||||
|
#define TWISTER_H
|
||||||
|
|
||||||
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
|
#define LIBTORRENT_PORT_OFFSET 1000
|
||||||
|
|
||||||
|
class twister
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
twister();
|
||||||
|
};
|
||||||
|
|
||||||
|
void startSessionTorrent(boost::thread_group& threadGroup);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // TWISTER_H
|
@ -187,6 +187,7 @@ HEADERS += \
|
|||||||
src/leveldb.h \
|
src/leveldb.h \
|
||||||
src/threadsafety.h \
|
src/threadsafety.h \
|
||||||
src/limitedmap.h \
|
src/limitedmap.h \
|
||||||
|
src/twister.h
|
||||||
|
|
||||||
# src/qt/bitcoingui.h
|
# src/qt/bitcoingui.h
|
||||||
# src/qt/transactiontablemodel.h \
|
# src/qt/transactiontablemodel.h \
|
||||||
@ -259,6 +260,7 @@ SOURCES += \ #src/qt/bitcoin.cpp \
|
|||||||
src/noui.cpp \
|
src/noui.cpp \
|
||||||
src/leveldb.cpp \
|
src/leveldb.cpp \
|
||||||
src/txdb.cpp \
|
src/txdb.cpp \
|
||||||
|
src/twister.cpp
|
||||||
|
|
||||||
# src/qt/guiutil.cpp \
|
# src/qt/guiutil.cpp \
|
||||||
# src/qt/bitcoingui.cpp \
|
# src/qt/bitcoingui.cpp \
|
||||||
|
Loading…
Reference in New Issue
Block a user