From 2c5994c322c315d92d56dfbe2b679f9f612aef4c Mon Sep 17 00:00:00 2001 From: Yury Pikhtarev Date: Sun, 5 Mar 2023 21:48:22 +0300 Subject: [PATCH 1/4] Cleanup Clearing the code base before actualization --- .gitignore | 1 + CHANGES | 88 --------------------------------------------- config.cpp | 10 ++---- config.cpp.template | 16 ++++++--- ocelot.conf.dist | 17 ++++----- site_comm.cpp | 10 ++---- site_comm.h | 3 -- worker.cpp | 13 ------- worker.h | 1 - 9 files changed, 25 insertions(+), 134 deletions(-) delete mode 100644 CHANGES diff --git a/.gitignore b/.gitignore index 0cbe898..a6c308a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ build/ +config.log ocelot.conf diff --git a/CHANGES b/CHANGES deleted file mode 100644 index 97dc028..0000000 --- a/CHANGES +++ /dev/null @@ -1,88 +0,0 @@ --- 1.0 (2015-01-26) -NOTE: This version requires the following database change: -ALTER TABLE xbt_files_users DROP PRIMARY KEY, ADD PRIMARY KEY (peer_id,fid,uid) - -Add a 'deleted' flag to user object to stop including removed users in returned peer lists -Add a prefix to the peer list keys for randomization and smaller chance of peer id collisions -Add HTTP Keep-Alive support and show request rate in the tracker stats -Add readonly mode for easier testing -Catch exceptions in the mysql::load_* functions -Configurable max/default numwant parameter -Don't disable binlogs in the peer flush sessions -Don't start a reaper thread if it's already running -Inline peer_is_visible and user functions -Mark nonchanging parameter as const -Mark users with IP = 127.0.0.1 as protected -Read settings from a config file instead of a compiled object -Reload torrent list, user list and client whitelist on SIGUSR1 -Use atomic variables for stats -Use consistent integer widths where it matters -Use std::lock_guard instead of std::unique_lock for mutex - --- 0.8 (2014-03-27) -Add setting for maximum request size -Get client IP from the x-forwarded-for header if it is provided -Read/write full requests even if they are split into several recv/send calls - --- 0.7 (2013-12-05) -Add bintohex function to use when printing binary data to stdout -Check if compiler supports -std=c++11 -Collect some stats and add a method that prints them -Create a function for adding peers -Fix a potential problem where a deleted pointer was being accessed -Improve the anti-web crawler code -Make use of the peer iterator for faster deletions -Remove most of the dependencies on boost and move all thread-related calls to the STL components provided in C++11 -Run the reaper routines in a single thread to clean up stdout -Separate the sections responsible for output to make it easier to change http headers if needed -Update the db's torrents table when the peer reaper deletes the last peer on a torrent - --- 0.6 (2013-03-19) -Add --with-tcmalloc option to the configure script to enable Google's high-performance multi-threaded malloc() implementation -Configurable site path -Expire multiple tokens in a single request to the web server -Less spammy output unless a -v switch is passed when starting Ocelot -Make flush queries slightly less spammy by moving them to the functions that invoke flush threads -Print warning instead of error if someone submits an IPv6 or otherwise invalid address -Remove unused logger class -Send special data to search engine crawlers (and other odd clients) in an attempt to prevent indexing of announce URLs -Use a lighter query to update peer records in xbt_files_users if a peer's data has not changed since its previous announcement - --- 0.5 (2012-10-08) -Add ability to show reasons why a torrent was deleted on unregistered torrents -Add gzip compression support for announces and scrapes -Autotools build system -Fix incorrect handling of "corrupt" stat -Make Ocelot clear stale peer data out of the db on startup -Track transfer stats from users without leech privs - --- 0.4 (2012-06-20) -Convert all headers to lowercase -Don't show users to themselves (patch by GrecKo) -Don't write peer updates to the binlog -Search for peer in leecher list if not found in seeders list -Sort response dictionary according to BitTorrent specs - --- 0.3 (2012-02-03) -Add tokens -Added a logging function -Added DB_LOCK_TIMEOUT constant -Added info command -Added neutral leech -Added transactions and backups around the peer/user queries -Added working makefile -Adding more debug to query outputs -Changed flushing logic to prevent buildups -Clean shutdown -Don't print complete query if an error occurred -Fixed thread visibility -Flush every schedule -More debug output -New DB class with queue -Nicer schedule display - --- 0.2 alpha (2011-01-11) -Bug fixes - --- 0.1 alpha (2010-10-27) -First release diff --git a/config.cpp b/config.cpp index e1f8057..9e29c6b 100644 --- a/config.cpp +++ b/config.cpp @@ -1,6 +1,5 @@ #include #include -#include #include "config.h" #include "misc_functions.h" @@ -75,16 +74,13 @@ void config::init() { add("schedule_interval", 3u); // MySQL - add("mysql_db", "gazelle"); + add("mysql_db", "torrentpier"); add("mysql_host", "localhost"); add("mysql_username", ""); add("mysql_password", ""); - // Site communication - add("site_host", "127.0.0.1"); - add("site_path", ""); - add("site_password", "00000000000000000000000000000000"); - add("report_password", "00000000000000000000000000000000"); + // Statistical capture + add("report_password", "0000000000"); // Debugging add("readonly", false); diff --git a/config.cpp.template b/config.cpp.template index c209578..c62879e 100644 --- a/config.cpp.template +++ b/config.cpp.template @@ -1,6 +1,7 @@ #include "config.h" config::config() { + // Internal stuff host = "127.0.0.1"; port = 2710; max_connections = 512; @@ -10,18 +11,23 @@ config::config() { schedule_interval = 3; max_middlemen = 5000; + // Tracker requests announce_interval = 1800; - peers_timeout = 2700; //Announce interval * 1.5 + peers_timeout = 2700; // announce interval * 1.5 + // Timers reap_peers_interval = 1800; del_reason_lifetime = 604800; // MySQL - mysql_db = "gazelle"; + mysql_db = "torrentpier"; mysql_host = "127.0.0.1:3306"; mysql_username = "***"; mysql_password = "***"; - site_password = "**********"; // MUST BE 10 CHARS - // Key to use for /report?get=stats and /report?get=user&key= requests - report_password = "**********"; // MUST BE 10 CHARS + + // Statistical capture + report_password = "**********"; // 10-chars key for /report?get=stats and /report?get=user&key= + + // Debugging + readonly = false; } diff --git a/ocelot.conf.dist b/ocelot.conf.dist index 4f6f567..fac5253 100644 --- a/ocelot.conf.dist +++ b/ocelot.conf.dist @@ -7,7 +7,6 @@ max_connections = 128 max_middlemen = 20000 max_read_buffer = 4096 connection_timeout = 10 -# Keepalive is mostly useful if the tracker runs behind reverse proxies keepalive_timeout = 0 announce_interval = 1800 @@ -15,18 +14,16 @@ max_request_size = 4096 numwant_limit = 50 request_log_size = 500 -mysql_host = -mysql_username = -mysql_password = -mysql_db = - -# The passwords must be 32 characters and match the Gazelle config -report_password = 00000000000000000000000000000000 -site_password = 00000000000000000000000000000000 - peers_timeout = 7200 del_reason_lifetime = 86400 reap_peers_interval = 1800 schedule_interval = 3 +mysql_host = +mysql_username = +mysql_password = +mysql_db = + +report_password = 0000000000 + readonly = false diff --git a/site_comm.cpp b/site_comm.cpp index ceaebf9..81bd077 100644 --- a/site_comm.cpp +++ b/site_comm.cpp @@ -18,9 +18,6 @@ site_comm::site_comm(config * conf) : t_active(false) { } void site_comm::load_config(config * conf) { - site_host = conf->get_str("site_host"); - site_path = conf->get_str("site_path"); - site_password = conf->get_str("site_password"); readonly = conf->get_bool("readonly"); } @@ -79,7 +76,6 @@ void site_comm::do_flush_tokens() boost::asio::io_service io_service; tcp::resolver resolver(io_service); - tcp::resolver::query query(site_host, "http"); tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); tcp::resolver::iterator end; @@ -95,9 +91,9 @@ void site_comm::do_flush_tokens() boost::asio::streambuf request; std::ostream request_stream(&request); - request_stream << "GET " << site_path << "/tools.php?key=" << site_password + request_stream << "GET " << "/tools.php?key=" << "&type=expiretoken&action=ocelot&tokens=" << token_queue.front() << " HTTP/1.0\r\n" - << "Host: " << site_host << "\r\n" + << "Host: " << "\r\n" << "Accept: */*\r\n" << "Connection: close\r\n\r\n"; @@ -123,7 +119,7 @@ void site_comm::do_flush_tokens() std::lock_guard lock(expire_queue_lock); token_queue.pop(); } else { - std::cout << "Response returned with status code " << status_code << " when trying to expire a token!" << std::endl;; + std::cout << "Response returned with status code " << status_code << " when trying to expire a token!" << std::endl; } } } catch (std::exception &e) { diff --git a/site_comm.h b/site_comm.h index 798154f..036b328 100644 --- a/site_comm.h +++ b/site_comm.h @@ -11,9 +11,6 @@ using boost::asio::ip::tcp; class site_comm { private: - std::string site_host; - std::string site_path; - std::string site_password; std::mutex expire_queue_lock; std::string expire_token_buffer; std::queue token_queue; diff --git a/worker.cpp b/worker.cpp index 2aa2655..36f9ebc 100644 --- a/worker.cpp +++ b/worker.cpp @@ -1,12 +1,9 @@ #include -#include #include #include #include #include #include -#include -#include #include #include "ocelot.h" @@ -33,7 +30,6 @@ void worker::load_config(config * conf) { peers_timeout = conf->get_uint("peers_timeout"); numwant_limit = conf->get_uint("numwant_limit"); keepalive_enabled = conf->get_uint("keepalive_timeout") != 0; - site_password = conf->get_str("site_password"); report_password = conf->get_str("report_password"); } @@ -45,7 +41,6 @@ void worker::reload_lists() { status = PAUSED; db->load_torrents(torrents_list); db->load_users(users_list); - //db->load_whitelist(whitelist); status = OPEN; } @@ -222,14 +217,6 @@ std::string worker::work(const std::string &input, std::string &ip, client_opts_ return error("Invalid action", client_opts); } - if (action == UPDATE) { - if (passkey == site_password) { - return update(params, client_opts); - } else { - return error("Authentication failure", client_opts); - } - } - if (action == REPORT) { if (passkey == report_password) { std::lock_guard ul_lock(db->user_list_mutex); diff --git a/worker.h b/worker.h index 63f8973..5a0302e 100644 --- a/worker.h +++ b/worker.h @@ -31,7 +31,6 @@ class worker { unsigned int peers_timeout; unsigned int numwant_limit; bool keepalive_enabled; - std::string site_password; std::string report_password; std::mutex del_reasons_lock; From c85041a6d18b0d46fd80b083ab6378128b5029ff Mon Sep 17 00:00:00 2001 From: Yury Pikhtarev Date: Sun, 5 Mar 2023 21:58:25 +0300 Subject: [PATCH 2/4] Remove changes from extra dist --- Makefile.am | 2 +- Makefile.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index f9f654a..f1bc4ef 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,7 +8,7 @@ ocelot_SOURCES = config.cpp config.h db.cpp db.h events.cpp events.h misc_functi AM_CXXFLAGS = -std=c++11 -march=native -O2 -fvisibility=hidden -fvisibility-inlines-hidden -fomit-frame-pointer -fno-ident -Wall -Wfatal-errors $(PTHREAD_CFLAGS) $(BOOST_CPPFLAGS) ocelot_LDADD = $(PTHREAD_LIBS) $(BOOST_IOSTREAMS_LIB) $(BOOST_SYSTEM_LIB) AM_LDFLAGS = -Wl,-O1 -Wl,--as-needed -EXTRA_DIST = CHANGES LICENSE README.md ocelot.conf.dist +EXTRA_DIST = LICENSE README.md ocelot.conf.dist dist-hook: touch ${distdir}/configure patch -p2 -d ${distdir} --no-backup-if-mismatch < ../dist.patch diff --git a/Makefile.in b/Makefile.in index e0cbacf..c228a76 100644 --- a/Makefile.in +++ b/Makefile.in @@ -327,7 +327,7 @@ ocelot_SOURCES = config.cpp config.h db.cpp db.h events.cpp events.h misc_functi AM_CXXFLAGS = -std=c++11 -march=native -O2 -fvisibility=hidden -fvisibility-inlines-hidden -fomit-frame-pointer -fno-ident -Wall -Wfatal-errors $(PTHREAD_CFLAGS) $(BOOST_CPPFLAGS) ocelot_LDADD = $(PTHREAD_LIBS) $(BOOST_IOSTREAMS_LIB) $(BOOST_SYSTEM_LIB) AM_LDFLAGS = -Wl,-O1 -Wl,--as-needed -EXTRA_DIST = CHANGES LICENSE README.md ocelot.conf.dist +EXTRA_DIST = LICENSE README.md ocelot.conf.dist all: all-am .SUFFIXES: From 0464fff99622ff7da08907393f170ac7c706e4fd Mon Sep 17 00:00:00 2001 From: Yury Pikhtarev Date: Sun, 5 Mar 2023 22:04:51 +0300 Subject: [PATCH 3/4] Used includes --- config.cpp | 1 + worker.cpp | 3 +++ 2 files changed, 4 insertions(+) diff --git a/config.cpp b/config.cpp index 9e29c6b..e3c8378 100644 --- a/config.cpp +++ b/config.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "config.h" #include "misc_functions.h" diff --git a/worker.cpp b/worker.cpp index 36f9ebc..ca6ae53 100644 --- a/worker.cpp +++ b/worker.cpp @@ -1,9 +1,12 @@ #include +#include #include #include #include #include #include +#include +#include #include #include "ocelot.h" From 14a799b9681ea5de174db911e81f125a961866ba Mon Sep 17 00:00:00 2001 From: Yury Pikhtarev Date: Sun, 5 Mar 2023 22:22:16 +0300 Subject: [PATCH 4/4] Remove old code --- config.cpp | 1 - site_comm.cpp | 55 --------------------------------------------------- worker.cpp | 3 --- 3 files changed, 59 deletions(-) diff --git a/config.cpp b/config.cpp index e3c8378..9e29c6b 100644 --- a/config.cpp +++ b/config.cpp @@ -1,6 +1,5 @@ #include #include -#include #include "config.h" #include "misc_functions.h" diff --git a/site_comm.cpp b/site_comm.cpp index 81bd077..ce093d9 100644 --- a/site_comm.cpp +++ b/site_comm.cpp @@ -70,61 +70,6 @@ void site_comm::flush_tokens() void site_comm::do_flush_tokens() { - t_active = true; - try { - while (token_queue.size() > 0) { - boost::asio::io_service io_service; - - tcp::resolver resolver(io_service); - tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); - tcp::resolver::iterator end; - - tcp::socket socket(io_service); - boost::system::error_code error = boost::asio::error::host_not_found; - while (error && endpoint_iterator != end) { - socket.close(); - socket.connect(*endpoint_iterator++, error); - } - if (error) { - throw boost::system::system_error(error); - } - - boost::asio::streambuf request; - std::ostream request_stream(&request); - request_stream << "GET " << "/tools.php?key=" - << "&type=expiretoken&action=ocelot&tokens=" << token_queue.front() << " HTTP/1.0\r\n" - << "Host: " << "\r\n" - << "Accept: */*\r\n" - << "Connection: close\r\n\r\n"; - - boost::asio::write(socket, request); - - boost::asio::streambuf response; - boost::asio::read_until(socket, response, "\r\n"); - - std::istream response_stream(&response); - std::string http_version; - response_stream >> http_version; - unsigned int status_code; - response_stream >> status_code; - std::string status_message; - std::getline(response_stream, status_message); - - if (!response_stream || http_version.substr(0, 5) != "HTTP/") { - std::cout << "Invalid response" << std::endl; - continue; - } - - if (status_code == 200) { - std::lock_guard lock(expire_queue_lock); - token_queue.pop(); - } else { - std::cout << "Response returned with status code " << status_code << " when trying to expire a token!" << std::endl; - } - } - } catch (std::exception &e) { - std::cout << "Exception: " << e.what() << std::endl; - } t_active = false; } diff --git a/worker.cpp b/worker.cpp index ca6ae53..36f9ebc 100644 --- a/worker.cpp +++ b/worker.cpp @@ -1,12 +1,9 @@ #include -#include #include #include #include #include #include -#include -#include #include #include "ocelot.h"