From f757db71a4ac636b24145991ab5e8ec3f72440be Mon Sep 17 00:00:00 2001 From: Naim A Date: Sat, 23 Mar 2013 21:54:25 +0200 Subject: [PATCH] Small changes; Added "is_dynamic" setting; Changed stuff with Database (I guess i was sleeping when i programmed that part...). --- src/db/driver_sqlite.cpp | 7 ++++--- src/main.cpp | 5 +++-- src/udpTracker.cpp | 12 ++++++++++-- src/udpTracker.hpp | 1 + 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/db/driver_sqlite.cpp b/src/db/driver_sqlite.cpp index b3956fa..47dcba8 100644 --- a/src/db/driver_sqlite.cpp +++ b/src/db/driver_sqlite.cpp @@ -242,7 +242,7 @@ namespace UDPT sqlite3_stmt *stmt; sqlite3_prepare(this->db, "INSERT INTO torrents (info_hash,created) VALUES (?,?)", -1, &stmt, NULL); sqlite3_bind_blob(stmt, 1, info_hash, 20, NULL); - sqlite3_bind_int(stmt, 1, time(NULL)); + sqlite3_bind_int(stmt, 2, time(NULL)); sqlite3_step(stmt); sqlite3_finalize(stmt); @@ -266,7 +266,7 @@ namespace UDPT return (r == SQLITE_OK); } - bool SQLite3Driver::isTorrentAllowed(uint8_t info_hash[20]) + bool SQLite3Driver::isTorrentAllowed(uint8_t *info_hash) { if (this->isDynamic()) return true; @@ -275,8 +275,9 @@ namespace UDPT sqlite3_bind_blob(stmt, 1, info_hash, 20, NULL); sqlite3_step(stmt); - int n = sqlite3_column_int(stmt, 1); + int n = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); + return (n == 1); } diff --git a/src/main.cpp b/src/main.cpp index 32e83f0..cb72cb9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -103,10 +103,11 @@ int main(int argc, char *argv[]) settings->set (strDATABASE, "driver", "sqlite3"); settings->set (strDATABASE, "file", "tracker.db"); + settings->set (strTRACKER, "is_dynamic", "0"); settings->set (strTRACKER, "port", "6969"); // UDP PORT settings->set (strTRACKER, "threads", "5"); - settings->set (strTRACKER, "allow_remotes", "yes"); - settings->set (strTRACKER, "allow_iana_ips", "yes"); + settings->set (strTRACKER, "allow_remotes", "1"); + settings->set (strTRACKER, "allow_iana_ips", "1"); settings->set (strTRACKER, "announce_interval", "1800"); settings->set (strTRACKER, "cleanup_interval", "120"); diff --git a/src/udpTracker.cpp b/src/udpTracker.cpp index d9e0a34..f288952 100644 --- a/src/udpTracker.cpp +++ b/src/udpTracker.cpp @@ -71,7 +71,8 @@ namespace UDPT s_allow_remotes, // remotes allowed? s_allow_iana_ip, // IANA IPs allowed? s_int_announce, // announce interval - s_int_cleanup; // cleanup interval + s_int_cleanup, // cleanup interval + s_is_dynamic; sc_tracker = settings->getClass("tracker"); @@ -81,6 +82,7 @@ namespace UDPT s_allow_iana_ip = sc_tracker->get ("allow_iana_ips"); s_int_announce = sc_tracker->get ("announce_interval"); s_int_cleanup = sc_tracker-> get ("cleanup_interval"); + s_is_dynamic = sc_tracker->get("is_dynamic"); if (_isTrue(s_allow_remotes) == 1) n_settings |= UDPT_ALLOW_REMOTE_IP; @@ -88,6 +90,11 @@ namespace UDPT if (_isTrue(s_allow_iana_ip) != 0) n_settings |= UDPT_ALLOW_IANA_IP; + if (_isTrue(s_is_dynamic) == 1) + this->isDynamic = true; + else + this->isDynamic = false; + this->announce_interval = (s_int_announce == "" ? 1800 : atoi (s_int_announce.c_str())); this->cleanup_interval = (s_int_cleanup == "" ? 120 : atoi (s_int_cleanup.c_str())); this->port = (s_port == "" ? 6969 : atoi (s_port.c_str())); @@ -169,7 +176,8 @@ namespace UDPT this->sock = sock; - this->conn = new Data::SQLite3Driver (this->o_settings->getClass("database"), true); + this->conn = new Data::SQLite3Driver (this->o_settings->getClass("database"), + this->isDynamic); this->isRunning = true; cout << "Starting maintenance thread (1/" << ((int)this->thread_count) << ")" << endl; diff --git a/src/udpTracker.hpp b/src/udpTracker.hpp index 282020f..1466e4b 100644 --- a/src/udpTracker.hpp +++ b/src/udpTracker.hpp @@ -137,6 +137,7 @@ namespace UDPT uint16_t port; uint8_t thread_count; bool isRunning; + bool isDynamic; HANDLE *threads; uint32_t announce_interval; uint32_t cleanup_interval;