out->eventBase = eventBase; out->logger = logger; out->allocator = allocator; out->admin = admin; out->rand = rand; out->pinger = Pinger_new(eventBase, rand, logger, allocator); out->janitor = Janitor_new(LOCAL_MAINTENANCE_SEARCH_MILLISECONDS, GLOBAL_MAINTENANCE_SEARCH_MILLISECONDS, out, out->nodeStore, logger, allocator, eventBase, rand); out->searchRunner = SearchRunner_new(out->nodeStore, logger, eventBase, out, out->address.ip6.bytes, allocator); out->routeTracer = RouteTracer_new(out->nodeStore, out, myAddress, eventBase, logger, allocator); NodeStore_admin_register(out->nodeStore, admin, allocator); Identity_set(out); return out; } /** * The amount of time to wait before skipping over the first node and trying another in a search. * Any node which can't beat this time will have its reach set to 0. * * @param module this module.
static Iface_DEFUN connected(struct Pathfinder_pvt* pf, struct Message* msg) { Log_debug(pf->log, "INIT"); struct PFChan_Core_Connect conn; Message_pop(msg, &conn, PFChan_Core_Connect_SIZE, NULL); Assert_true(!msg->length); Bits_memcpy(pf->myAddr.key, conn.publicKey, 32); Address_getPrefix(&pf->myAddr); pf->myAddr.path = 1; // begin pf->registry = DHTModuleRegistry_new(pf->alloc); ReplyModule_register(pf->registry, pf->alloc); pf->rumorMill = RumorMill_new(pf->alloc, &pf->myAddr, RUMORMILL_CAPACITY, pf->log, "extern"); pf->nodeStore = NodeStore_new(&pf->myAddr, pf->alloc, pf->base, pf->log, pf->rumorMill); if (pf->pub.fullVerify) { NodeStore_setFullVerify(pf->nodeStore, true); } pf->nodeStore->onBestPathChange = onBestPathChange; pf->nodeStore->onBestPathChangeCtx = pf; struct RouterModule* routerModule = RouterModule_register(pf->registry, pf->alloc, pf->myAddr.key, pf->base, pf->log, pf->rand, pf->nodeStore); pf->searchRunner = SearchRunner_new(pf->nodeStore, pf->log, pf->base, routerModule, pf->myAddr.ip6.bytes, pf->rumorMill, pf->alloc); pf->janitor = Janitor_new(routerModule, pf->nodeStore, pf->searchRunner, pf->rumorMill, pf->log, pf->alloc, pf->base, pf->rand); EncodingSchemeModule_register(pf->registry, pf->log, pf->alloc); SerializationModule_register(pf->registry, pf->log, pf->alloc); DHTModuleRegistry_register(&pf->dhtModule, pf->registry); pf->router = Router_new(routerModule, pf->nodeStore, pf->searchRunner, pf->alloc); // Now the admin stuff... if (pf->admin) { NodeStore_admin_register(pf->nodeStore, pf->admin, pf->alloc); RouterModule_admin_register(routerModule, pf->router, pf->admin, pf->alloc); SearchRunner_admin_register(pf->searchRunner, pf->admin, pf->alloc); Janitor_admin_register(pf->janitor, pf->admin, pf->alloc); } pf->state = Pathfinder_pvt_state_RUNNING; return NULL; }
struct TestFramework* TestFramework_setUp(char* privateKey, struct Allocator* allocator, struct Log* logger) { if (!logger) { struct Writer* logwriter = FileWriter_new(stdout, allocator); logger = WriterLog_new(logwriter, allocator); } struct Random* rand = Random_new(allocator, logger, NULL); struct EventBase* base = EventBase_new(allocator); uint64_t pks[4]; if (!privateKey) { Random_longs(rand, pks, 4); privateKey = (char*)pks; } uint8_t* publicKey = Allocator_malloc(allocator, 32); crypto_scalarmult_curve25519_base(publicKey, (uint8_t*)privateKey); struct Address* myAddress = Allocator_calloc(allocator, sizeof(struct Address), 1); Bits_memcpyConst(myAddress->key, publicKey, 32); AddressCalc_addressForPublicKey(myAddress->ip6.bytes, publicKey); struct SwitchCore* switchCore = SwitchCore_new(logger, allocator); struct CryptoAuth* ca = CryptoAuth_new(allocator, (uint8_t*)privateKey, base, logger, rand); struct DHTModuleRegistry* registry = DHTModuleRegistry_new(allocator); ReplyModule_register(registry, allocator); struct NodeStore* nodeStore = NodeStore_new(myAddress, 128, allocator, logger, rand); struct RouterModule* routerModule = RouterModule_register(registry, allocator, publicKey, base, logger, rand, nodeStore); struct SearchRunner* searchRunner = SearchRunner_new(nodeStore, logger, base, routerModule, myAddress->ip6.bytes, allocator); SerializationModule_register(registry, logger, allocator); struct IpTunnel* ipTun = IpTunnel_new(logger, base, allocator, rand, NULL); struct Ducttape* dt = Ducttape_register((uint8_t*)privateKey, registry, routerModule, searchRunner, switchCore, base, allocator, logger, ipTun, rand); struct SwitchPinger* sp = SwitchPinger_new(&dt->switchPingerIf, base, rand, logger, allocator); // Interfaces. struct InterfaceController* ifController = DefaultInterfaceController_new(ca, switchCore, routerModule, logger, base, sp, rand, allocator); struct TestFramework* tf = Allocator_clone(allocator, (&(struct TestFramework) { .alloc = allocator, .rand = rand, .eventBase = base, .logger = logger, .switchCore = switchCore, .ducttape = dt, .cryptoAuth = ca, .router = routerModule, .switchPinger = sp, .ifController = ifController, .publicKey = publicKey, .ip = myAddress->ip6.bytes }));