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

Cleanup #22

Open
wants to merge 5 commits into
base: main
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
build/
config.log
ocelot.conf
88 changes: 0 additions & 88 deletions CHANGES

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 3 additions & 7 deletions config.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <iostream>
#include <fstream>
#include <string>
#include "config.h"
#include "misc_functions.h"

Expand Down Expand Up @@ -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);
Expand Down
16 changes: 11 additions & 5 deletions config.cpp.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "config.h"

config::config() {
// Internal stuff
host = "127.0.0.1";
port = 2710;
max_connections = 512;
Expand All @@ -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=<passkey> requests
report_password = "**********"; // MUST BE 10 CHARS

// Statistical capture
report_password = "**********"; // 10-chars key for /report?get=stats and /report?get=user&key=<passkey>

// Debugging
readonly = false;
}
17 changes: 7 additions & 10 deletions ocelot.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,23 @@ 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
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
59 changes: 0 additions & 59 deletions site_comm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down Expand Up @@ -73,62 +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::query query(site_host, "http");
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 " << site_path << "/tools.php?key=" << site_password
<< "&type=expiretoken&action=ocelot&tokens=" << token_queue.front() << " HTTP/1.0\r\n"
<< "Host: " << site_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<std::mutex> 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;
}

Expand Down
3 changes: 0 additions & 3 deletions site_comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> token_queue;
Expand Down
13 changes: 0 additions & 13 deletions worker.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#include <iostream>
#include <string>
#include <map>
#include <sstream>
#include <list>
#include <vector>
#include <set>
#include <algorithm>
#include <mutex>
#include <thread>

#include "ocelot.h"
Expand All @@ -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");
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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<std::mutex> ul_lock(db->user_list_mutex);
Expand Down
1 change: 0 additions & 1 deletion worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading