diff options
Diffstat (limited to 'src/ocelot.cpp')
-rw-r--r-- | src/ocelot.cpp | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/src/ocelot.cpp b/src/ocelot.cpp index 05f1823..b7a484d 100644 --- a/src/ocelot.cpp +++ b/src/ocelot.cpp @@ -4,19 +4,21 @@ #include "worker.h" #include "events.h" #include "schedule.h" +#include "logger.h" +#include "site_comm.h" static mysql *db_ptr; static connection_mother *mother; +static worker *work; +static logger *log_ptr; +static site_comm *sc_ptr; static void sig_handler(int sig) { std::cout << "Caught SIGINT/SIGTERM" << std::endl; - delete(mother); - db_ptr->flush_torrents(); - db_ptr->flush_users(); - db_ptr->flush_snatches(); - db_ptr->flush_peers(); - exit(0); + if (work->signal(sig)) { + exit(0); + } } int main() { @@ -24,28 +26,37 @@ int main() { signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); - + + log_ptr = new logger("debug.log"); + mysql db(conf.mysql_db, conf.mysql_host, conf.mysql_username, conf.mysql_password); db_ptr = &db; + + site_comm sc(conf); + sc_ptr = ≻ - std::unordered_map<std::string, torrent> torrents_list; - db.load_torrents(torrents_list); - std::cout << "Loaded " << torrents_list.size() << " torrents" << std::endl; + std::vector<std::string> whitelist; + db.load_whitelist(whitelist); + std::cout << "Loaded " << whitelist.size() << " clients into the whitelist" << std::endl; + if(whitelist.size() == 0) { + std::cout << "Assuming no whitelist desired, disabling" << std::endl; + } std::unordered_map<std::string, user> users_list; db.load_users(users_list); std::cout << "Loaded " << users_list.size() << " users" << std::endl; - std::vector<std::string> whitelist; - db.load_whitelist(whitelist); - std::cout << "Loaded " << whitelist.size() << " clients into the whitelist" << std::endl; - + std::unordered_map<std::string, torrent> torrents_list; + db.load_torrents(torrents_list); + std::cout << "Loaded " << torrents_list.size() << " torrents" << std::endl; + + db.load_tokens(torrents_list); // Create worker object, which handles announces and scrapes and all that jazz - worker work(torrents_list, users_list, whitelist, &conf, &db); + work = new worker(torrents_list, users_list, whitelist, &conf, &db, sc); // Create connection mother, which binds to its socket and handles the event stuff - mother = new connection_mother(&work, &conf, &db); + mother = new connection_mother(work, &conf, &db); return 0; } |