int main() { struct Allocator* alloc = MallocAllocator_new(1<<20); struct Writer* logwriter = FileWriter_new(stdout, alloc); struct Log* logger = &(struct Log) { .writer = logwriter }; struct event_base* eventBase = event_base_new(); struct CryptoAuth* ca = CryptoAuth_new(NULL, alloc, NULL, eventBase, logger); uint8_t publicKey[32]; CryptoAuth_getPublicKey(publicKey, ca); CryptoAuth_addUser(String_CONST("passwd"), 1, (void*)0x01, ca); struct SwitchCore* switchCore = SwitchCore_new(logger, alloc); struct Message* message; struct Interface iface = { .sendMessage = messageFromInterface, .senderContext = &message, .allocator = alloc }; SwitchCore_setRouterInterface(&iface, switchCore); // These are unused. struct DHTModuleRegistry* registry = DHTModuleRegistry_new(alloc); struct RouterModule* rm = RouterModule_register(registry, alloc, publicKey, eventBase, logger, NULL); struct InterfaceController* ifController = DefaultInterfaceController_new(ca, switchCore, rm, logger, eventBase, NULL, alloc); //////////////////////// return reconnectionNewEndpointTest(ifController, publicKey, &message, alloc, eventBase, logger, &iface); }
struct Ducttape* Ducttape_register(Dict* config, uint8_t privateKey[32], struct DHTModuleRegistry* registry, struct RouterModule* routerModule, struct Interface* routerIf, struct SwitchCore* switchCore, struct event_base* eventBase, struct Allocator* allocator, struct Log* logger, struct Admin* admin) { struct Ducttape* context = allocator->calloc(sizeof(struct Ducttape), 1, allocator); context->registry = registry; context->routerModule = routerModule; context->logger = logger; context->forwardTo = NULL; AddressMapper_init(&context->addrMap); struct CryptoAuth* cryptoAuth = CryptoAuth_new(config, allocator, privateKey, eventBase, logger); CryptoAuth_getPublicKey(context->myAddr.key, cryptoAuth); Address_getPrefix(&context->myAddr); context->sm = SessionManager_new(16, incomingFromCryptoAuth, outgoingFromCryptoAuth, context, eventBase, cryptoAuth, allocator); if (routerIf) { context->routerIf = routerIf; routerIf->receiveMessage = ip6FromTun; routerIf->receiverContext = context; } Bits_memcpyConst(&context->module, (&(struct DHTModule) { .name = "Ducttape", .context = context, .handleOutgoing = handleOutgoing }), sizeof(struct DHTModule));