Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for webseeds #164

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ AX_PTHREAD
AX_CHECK_ZLIB

PKG_CHECK_MODULES([CPPUNIT], [cppunit],, [no_cppunit="yes"])
PKG_CHECK_MODULES([LIBCURL], [libcurl >= 7.15.4], , [no_libcurl="yes"])

CFLAGS="$PTHREAD_CFLAGS $CPPUNIT_CFLAGS $CFLAGS"
CXXFLAGS="$PTHREAD_CFLAGS $CPPUNIT_CFLAGS $CXXFLAGS"
LIBS="$PTHREAD_LIBS $CPPUNIT_LIBS $LIBS"
CFLAGS="$PTHREAD_CFLAGS $CPPUNIT_CFLAGS $LIBCURL_CFLAGS $CFLAGS"
CXXFLAGS="$PTHREAD_CFLAGS $CPPUNIT_CFLAGS $LIBCURL_CXXFLAGS $CXXFLAGS"
LIBS="$PTHREAD_LIBS $CPPUNIT_LIBS $LIBCURL_LIBS $LIBS"

AC_ARG_ENABLE(openssl,
[ --disable-openssl Don't use OpenSSL's SHA1 implementation.],
Expand Down
18 changes: 18 additions & 0 deletions src/download/download_constructor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "torrent/object.h"
#include "torrent/tracker_controller.h"
#include "torrent/tracker_list.h"
#include "torrent/webseed_controller.h"
#include "torrent/data/file.h"
#include "torrent/data/file_list.h"

Expand Down Expand Up @@ -209,6 +210,9 @@ DownloadConstructor::parse_tracker(const Object& b) {
std::for_each(b.get_key_list("nodes").begin(), b.get_key_list("nodes").end(),
rak::make_mem_fun(this, &DownloadConstructor::add_dht_node));

if (b.has_key("url-list"))
add_webseed_url(b.get_key("url-list"));

m_download->main()->tracker_list()->randomize_group_entries();
}

Expand Down Expand Up @@ -248,6 +252,20 @@ DownloadConstructor::add_dht_node(const Object& b) {
manager->dht_manager()->add_node(host, el->as_value());
}

void
DownloadConstructor::add_webseed_url(const Object& b) {
if (b.is_list())
std::for_each(b.as_list().begin(), b.as_list().end(), rak::make_mem_fun(this, &DownloadConstructor::add_webseed_url));

if (!b.is_string())
return;

std::string url = b.as_string();
m_download->main()->webseed_controller()->add_url(url);
m_download->main()->tracker_list()->insert_url(m_download->main()->tracker_list()->size_group(), "webseed:" + url);
}


bool
DownloadConstructor::is_valid_path_element(const Object& b) {
return
Expand Down
1 change: 1 addition & 0 deletions src/download/download_constructor.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class DownloadConstructor {
void add_tracker_group(const Object& b);
void add_tracker_single(const Object& b, int group);
void add_dht_node(const Object& b);
void add_webseed_url(const Object& b);

static bool is_valid_path_element(const Object& b);
static bool is_invalid_path_element(const Object& b) { return !is_valid_path_element(b); }
Expand Down
3 changes: 3 additions & 0 deletions src/download/download_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "torrent/peer/peer_info.h"
#include "torrent/tracker_controller.h"
#include "torrent/tracker_list.h"
#include "torrent/webseed_controller.h"
#include "torrent/utils/log.h"

#include "available_list.h"
Expand Down Expand Up @@ -105,6 +106,8 @@ DownloadMain::DownloadMain() :
m_tracker_list = new TrackerList();
m_tracker_controller = new TrackerController(m_tracker_list);

m_webseed_controller = new WebseedController(this);

m_tracker_list->slot_success() = std::bind(&TrackerController::receive_success, m_tracker_controller, std::placeholders::_1, std::placeholders::_2);
m_tracker_list->slot_failure() = std::bind(&TrackerController::receive_failure, m_tracker_controller, std::placeholders::_1, std::placeholders::_2);
m_tracker_list->slot_scrape_success() = std::bind(&TrackerController::receive_scrape, m_tracker_controller, std::placeholders::_1);
Expand Down
5 changes: 5 additions & 0 deletions src/download/download_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class DownloadWrapper;
class HandshakeManager;
class TrackerController;
class TrackerList;
class WebseedController;
class DownloadInfo;
class ThrottleList;
class InitialSeeding;
Expand All @@ -89,6 +90,8 @@ class DownloadMain {
TrackerController* tracker_controller() { return m_tracker_controller; }
TrackerList* tracker_list() { return m_tracker_list; }

WebseedController* webseed_controller() { return m_webseed_controller; }

DownloadInfo* info() { return m_info; }

// Only retrieve writable chunks when the download is active.
Expand Down Expand Up @@ -174,6 +177,8 @@ class DownloadMain {
TrackerController* m_tracker_controller;
TrackerList* m_tracker_list;

WebseedController* m_webseed_controller;

class choke_group* m_choke_group;

group_entry m_up_group_entry;
Expand Down
7 changes: 5 additions & 2 deletions src/torrent/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ libsub_torrent_la_SOURCES = \
tracker_controller.cc \
tracker_controller.h \
tracker_list.cc \
tracker_list.h
tracker_list.h \
webseed_controller.cc \
webseed_controller.h

AM_CPPFLAGS = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir)

Expand Down Expand Up @@ -88,4 +90,5 @@ libtorrentinclude_HEADERS = \
torrent.h \
tracker.h \
tracker_controller.h \
tracker_list.h
tracker_list.h \
webseed_controller.h
1 change: 1 addition & 0 deletions src/torrent/data/file_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class LIBTORRENT_EXPORT FileList : private std::vector<File*> {
friend class DownloadMain;
friend class DownloadWrapper;
friend class Handshake;
friend class WebseedController;

typedef std::vector<File*> base_type;
typedef std::vector<std::string> path_list;
Expand Down
5 changes: 5 additions & 0 deletions src/torrent/download.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "torrent/data/file.h"
#include "torrent/peer/connection_list.h"
#include "torrent/tracker_controller.h"
#include "torrent/webseed_controller.h"
#include "torrent/tracker_list.h"
#include "torrent/utils/log.h"

Expand Down Expand Up @@ -171,6 +172,8 @@ Download::start(int flags) {

if (!(flags & start_skip_tracker))
m_ptr->main()->tracker_controller()->send_start_event();

m_ptr->main()->webseed_controller()->start();
}

void
Expand All @@ -186,6 +189,8 @@ Download::stop(int flags) {
m_ptr->main()->tracker_controller()->send_stop_event();

m_ptr->main()->tracker_controller()->disable();

m_ptr->main()->webseed_controller()->stop();
}

bool
Expand Down
1 change: 1 addition & 0 deletions src/torrent/tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class LIBTORRENT_EXPORT Tracker {
TRACKER_HTTP,
TRACKER_UDP,
TRACKER_DHT,
TRACKER_WEBSEED
} Type;

enum tracker_event {
Expand Down
4 changes: 4 additions & 0 deletions src/torrent/tracker_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "tracker/tracker_dht.h"
#include "tracker/tracker_http.h"
#include "tracker/tracker_udp.h"
#include "tracker/tracker_webseed.h"

#include "globals.h"
#include "exceptions.h"
Expand Down Expand Up @@ -203,6 +204,9 @@ TrackerList::insert_url(unsigned int group, const std::string& url, bool extra_t
} else if (std::strncmp("dht://", url.c_str(), 6) == 0 && TrackerDht::is_allowed()) {
tracker = new TrackerDht(this, url, flags);

} else if (std::strncmp("webseed:", url.c_str(), 8) == 0) {
tracker = new TrackerWebseed(this, url, flags);

} else {
LT_LOG_TRACKER(WARN, "could find matching tracker protocol (url:%s)", url.c_str());

Expand Down
Loading