int main(int argc,char* argv[]) { if(argc<2) return 1; FILE* f=fopen("whitelist.wdb","rb"); init_whitelist(); printf("%d,",load_whitelist(f)); struct timeval tv0,tv01; gettimeofday(&tv0,NULL); build_whitelist(); gettimeofday(&tv01,NULL); show_time(tv0,tv01); fclose(f); FILE* f2=fopen(argv[1],"rb"); fseek(f2,0,SEEK_END); long p=ftell(f2); fseek(f2,0,SEEK_SET); char* x = malloc(p+1); if(fread(x,p,1,f2)!=1) return 2; x[p]=0; fclose(f2); struct timeval tv1,tv2,diff; gettimeofday(&tv1,NULL); int rc=whitelist_match(x,"test",0); gettimeofday(&tv2,NULL); show_time(tv1,tv2); printf("%d\n",rc); free(x); whitelist_done(); /* const char* real = "http://pics.ebaystatic.com/"; const char* display = "http://www.ebay.com/"; printf("%d\n",whitelist_match(real,display,0));*/ return 0; }
void load_config(config_type& config, boost::filesystem::path& config_path) { // Load values from config file. echo() << "Using config file: " << config_path; libconfig::Config configuration; set_config_path(configuration, config_path); // Read off values. // libconfig is ANSI/MBCS on Windows - no Unicode support. // This reads ANSI/MBCS values from XML. If they are UTF-8 (and above the // ASCII band) the values will be misinterpreted upon use. const libconfig::Setting& root = configuration.getRoot(); root.lookupValue("output-file", config.output_file); root.lookupValue("error-file", config.error_file); root.lookupValue("blockchain-path", config.blockchain_path); root.lookupValue("hosts-file", config.hosts_file); root.lookupValue("service", config.service); root.lookupValue("heartbeat", config.heartbeat); root.lookupValue("publisher_enabled", config.publisher_enabled); root.lookupValue("block-publish", config.block_publish); root.lookupValue("tx-publish", config.tx_publish); root.lookupValue("certificate", config.certificate); root.lookupValue("client-allowed-certs", config.client_allowed_certs); load_whitelist(root, config); root.lookupValue("name", config.name); root.lookupValue("outgoing-connections", config.outgoing_connections); root.lookupValue("listener_enabled", config.listener_enabled); load_nodes(root, config); root.lookupValue("log_requests", config.log_requests); root.lookupValue("history_db_active_height", config.history_db_active_height); }
int ocelot_main(int argc, char **argv) { // we don't use printf so make cout/cerr a little bit faster std::ios_base::sync_with_stdio(false); Logger::set_log_level( LogLevel::INFO ); signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); bool verbose = false; for (int i = argc; i > 1; i--) { if (!strcmp(argv[1], "-v")) { verbose = true; } } auto db = mysql::get_instance(); if (!db->connected()) { Logger::fail("Cannot connect to database!"); return 0; } db->m_verbose_flush = verbose; config conf; site_comm sc; sc.verbose_flush = verbose; std::vector<std::string> whitelist; db->load_whitelist(whitelist); Logger::info("Loaded " + std::to_string( whitelist.size() ) + " clients into the whitelist"); if (whitelist.size() == 0) { Logger::info("Assuming no whitelist desired, disabling"); } user_list users_list; db->load_users(users_list); Logger::info("Loaded " + std::to_string( users_list.size() ) + " users"); torrent_list torrents_list; db->load_torrents(torrents_list); Logger::info("Loaded " + std::to_string( torrents_list.size() ) + " torrents"); db->load_tokens(torrents_list); stats.open_connections = 0; stats.opened_connections = 0; stats.connection_rate = 0; stats.leechers = 0; stats.seeders = 0; stats.announcements = 0; stats.succ_announcements = 0; stats.scrapes = 0; stats.bytes_read = 0; stats.bytes_written = 0; stats.start_time = time(NULL); // Set Cache TorrentListCache::set( torrents_list ); UserListCache::set( users_list ); WhitelistCache::set( whitelist ); // Create worker object, which handles announces and scrapes and all that jazz work = new worker(torrents_list, users_list, whitelist, &conf, &sc); // Create connection mother, which binds to its socket and handles the event stuff mother = new connection_mother(work); return 0; }