static void _scalliontor_secondCallback(ScallionTor* stor) { scalliontor_notify(stor); /* call Tor's second elapsed function */ second_elapsed_callback(NULL, NULL); /* make sure we handle any event creations that happened in Tor */ scalliontor_notify(stor); /* schedule the next callback */ if(stor) { stor->shadowlibFuncs->createCallback((ShadowPluginCallbackFunc)_scalliontor_secondCallback, stor, 1000); } }
static void _scalliontor_refillCallback(ScallionTor* stor) { scalliontor_notify(stor); /* call Tor's refill function */ refill_callback(NULL, NULL); /* notify stream BW events */ control_event_stream_bandwidth_used(); /* make sure we handle any event creations that happened in Tor */ scalliontor_notify(stor); /* schedule the next callback */ if(stor) { stor->shadowlibFuncs->createCallback((ShadowPluginCallbackFunc)_scalliontor_refillCallback, stor, stor->refillmsecs); } }
/* * normally tor calls event_base_loopexit so control returns from the libevent * event loop back to the tor main loop. tor then activates "linked" socket * connections before returning back to the libevent event loop. * * we hijack and use the libevent loop in nonblock mode, so when tor calls * the loopexit, we basically just need to do the linked connection activation. * that is extracted to scalliontor_loopexitCallback, which we need to execute * as a callback so we don't invoke event_base_loop while it is currently being * executed. */ static void scalliontor_loopexitCallback(ScallionTor* stor) { update_approx_time(time(NULL)); scalliontor_notify(stor); while(1) { /* All active linked conns should get their read events activated. */ SMARTLIST_FOREACH(active_linked_connection_lst, connection_t *, conn, event_active(conn->read_event, EV_READ, 1)); /* if linked conns are still active, enter libevent loop using EVLOOP_ONCE */ called_loop_once = smartlist_len(active_linked_connection_lst) ? 1 : 0; if(called_loop_once) { event_base_loop(tor_libevent_get_base(), EVLOOP_ONCE|EVLOOP_NONBLOCK); } else { /* linked conns are done */ break; } } /* make sure we handle any new events caused by the linked conns */ scalliontor_notify(stor); }
static void _scallion_notify() { scallion.shadowlibFuncs->log(SHADOW_LOG_LEVEL_DEBUG, __FUNCTION__, "_scallion_notify called"); scalliontor_notify(scallion.stor); }
gint scalliontor_start(ScallionTor* stor, gint argc, gchar *argv[]) { time_t now = time(NULL); update_approx_time(now); tor_threads_init(); init_logging(); /* tor_init() loses our logging, so set it before AND after */ scalliontor_setLogging(); if (tor_init(argc, argv) < 0) { return -1; } // scalliontor_setLogging(); /* load the private keys, if we're supposed to have them, and set up the * TLS context. */ gpointer idkey; #ifdef SCALLION_NEWIDKEYNAME idkey = client_identitykey; #else idkey = identitykey; #endif if (idkey == NULL) { if (init_keys() < 0) { log_err(LD_BUG,"Error initializing keys; exiting"); return -1; } } /* Set up the packed_cell_t memory pool. */ init_cell_pool(); /* Set up our buckets */ connection_bucket_init(); stats_prev_global_read_bucket = global_read_bucket; stats_prev_global_write_bucket = global_write_bucket; /* initialize the bootstrap status events to know we're starting up */ control_event_bootstrap(BOOTSTRAP_STATUS_STARTING, 0); if (trusted_dirs_reload_certs()) { log_warn(LD_DIR, "Couldn't load all cached v3 certificates. Starting anyway."); } #ifndef SCALLION_NOV2DIR if (router_reload_v2_networkstatus()) { return -1; } #endif if (router_reload_consensus_networkstatus()) { return -1; } /* load the routers file, or assign the defaults. */ if (router_reload_router_list()) { return -1; } /* load the networkstatuses. (This launches a download for new routers as * appropriate.) */ directory_info_has_arrived(now, 1); /* !note that scallion intercepts the cpuworker functionality (rob) */ if (server_mode(get_options())) { /* launch cpuworkers. Need to do this *after* we've read the onion key. */ cpu_init(); } /* set up once-a-second callback. */ if (! second_timer) { // struct timeval one_second; // one_second.tv_sec = 1; // one_second.tv_usec = 0; // // second_timer = periodic_timer_new(tor_libevent_get_base(), // &one_second, // second_elapsed_callback, // NULL); // tor_assert(second_timer); _scalliontor_secondCallback(stor); } #ifdef SCALLION_DOREFILLCALLBACKS #ifndef USE_BUFFEREVENTS if (!refill_timer) { int msecs = get_options()->TokenBucketRefillInterval; // struct timeval refill_interval; // // refill_interval.tv_sec = msecs/1000; // refill_interval.tv_usec = (msecs%1000)*1000; // // refill_timer = periodic_timer_new(tor_libevent_get_base(), // &refill_interval, // refill_callback, // NULL); // tor_assert(refill_timer); stor->refillmsecs = msecs; _scalliontor_refillCallback(stor); } #endif #endif /* run the startup events */ scalliontor_notify(stor); return 0; }