diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index bf4ade69..f9715a88 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -182,8 +182,6 @@ static bool TestCreateSpamMsgTx() exit(1); } - - extern void GenesisMiner(); extern void noui_connect(); int main(int argc, char* argv[]) diff --git a/src/init.cpp b/src/init.cpp index b57564d4..23fb5e9b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -32,6 +32,8 @@ using namespace boost; CWallet* pwalletMain; CClientUIInterface uiInterface; +void startSessionTorrent(boost::thread_group& threadGroup); + #ifdef WIN32 // Win32 LevelDB doesn't use filedescriptors, and the ones used for // accessing block files, don't count towards to fd_set size limit @@ -947,5 +949,57 @@ bool AppInit2(boost::thread_group& threadGroup) // Run a thread to flush wallet periodically threadGroup.create_thread(boost::bind(&ThreadFlushWalletDB, boost::ref(pwalletMain->strWalletFile))); + startSessionTorrent(threadGroup); + return !fRequestShutdown; } + +// ===================== LIBTORRENT & DHT =========================== + +#include "libtorrent/config.hpp" +#include "libtorrent/entry.hpp" +#include "libtorrent/bencode.hpp" +#include "libtorrent/session.hpp" + +using namespace libtorrent; +static session *ses; + +void startSessionTorrent(boost::thread_group& threadGroup) +{ + error_code ec; + int listen_port = GetListenPort() + 1000; + std::string bind_to_interface = ""; + + printf("startSessionTorrent port=%d\n", 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)); + + /* + std::vector 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"); +} + diff --git a/twister-qt.pro b/twister-qt.pro index 894901b8..ea282078 100644 --- a/twister-qt.pro +++ b/twister-qt.pro @@ -119,6 +119,13 @@ QMAKE_EXTRA_TARGETS += genleveldb # Gross ugly hack that depends on qmake internals, unfortunately there is no other way to do it. QMAKE_CLEAN += $$PWD/src/leveldb/libleveldb.a; cd $$PWD/src/leveldb ; $(MAKE) clean +# libtorrent hack +INCLUDEPATH += libtorrent/include +LIBS += $$PWD/libtorrent/src/.libs/libtorrent-rasterbar.a +DEFINES += TORRENT_DEBUG +DEFINES += BOOST_ASIO_SEPARATE_COMPILATION +#DEFINES += BOOST_ASIO_DYN_LINK + # regenerate src/build.h !win32|contains(USE_BUILD_INFO, 1) { genbuild.depends = FORCE