struct InterfaceController* InterfaceController_new(struct CryptoAuth* ca, struct SwitchCore* switchCore, struct Log* logger, struct EventBase* eventBase, struct SwitchPinger* switchPinger, struct Random* rand, struct Allocator* allocator, struct EventEmitter* ee) { struct Allocator* alloc = Allocator_child(allocator); struct InterfaceController_pvt* out = Allocator_malloc(alloc, sizeof(struct InterfaceController_pvt)); Bits_memcpy(out, (&(struct InterfaceController_pvt) { .alloc = alloc, .ca = ca, .rand = rand, .switchCore = switchCore, .logger = logger, .eventBase = eventBase, .switchPinger = switchPinger, .unresponsiveAfterMilliseconds = UNRESPONSIVE_AFTER_MILLISECONDS, .pingAfterMilliseconds = PING_AFTER_MILLISECONDS, .timeoutMilliseconds = TIMEOUT_MILLISECONDS, .forgetAfterMilliseconds = FORGET_AFTER_MILLISECONDS, .beaconInterval = BEACON_INTERVAL, .pingInterval = (switchPinger) ? Timeout_setInterval(pingCallback, out, PING_INTERVAL_MILLISECONDS, eventBase, alloc) : NULL }), sizeof(struct InterfaceController_pvt));
struct SupernodeHunter* SupernodeHunter_new(struct Allocator* allocator, struct Log* log, struct EventBase* base, struct AddrSet* peers, struct MsgCore* msgCore, struct Address* myAddress) { struct Allocator* alloc = Allocator_child(allocator); struct SupernodeHunter_pvt* out = Allocator_calloc(alloc, sizeof(struct SupernodeHunter_pvt), 1); out->authorizedSnodes = AddrSet_new(alloc); out->peers = peers; out->base = base; out->nodes = AddrSet_new(alloc); //out->timeSnodeCalled = Time_currentTimeMilliseconds(base); out->snodeCandidates = AddrSet_new(alloc); out->log = log; out->alloc = alloc; out->msgCore = msgCore; out->myAddress = myAddress; out->selfAddrStr = String_newBinary(myAddress->ip6.bytes, 16, alloc); Identity_set(out); Timeout_setInterval(pingCycle, out, CYCLE_MS, base, alloc); return &out->pub; }
struct Security* Security_new(struct Allocator* alloc, struct Log* log, struct EventBase* base) { struct Security_pvt* sec = Allocator_calloc(alloc, sizeof(struct Security_pvt), 1); Identity_set(sec); sec->setupAlloc = Allocator_child(alloc); Timeout_setInterval(fail, sec, 20000, base, sec->setupAlloc); sec->log = log; return &sec->pub; }
struct ReachabilityCollector* ReachabilityCollector_new(struct Allocator* allocator, struct MsgCore* msgCore, struct Log* log, struct EventBase* base, struct BoilerplateResponder* br, struct Address* myAddr) { struct Allocator* alloc = Allocator_child(allocator); struct ReachabilityCollector_pvt* rcp = Allocator_calloc(alloc, sizeof(struct ReachabilityCollector_pvt), 1); rcp->myAddr = myAddr; rcp->msgCore = msgCore; rcp->alloc = alloc; rcp->piList = ArrayList_OfPeerInfo_pvt_new(alloc); rcp->log = log; rcp->br = br; Identity_set(rcp); Timeout_setInterval(cycle, rcp, 2000, base, alloc); return &rcp->pub; }
static void start(struct Allocator* alloc, struct Log* logger, struct EventBase* base, struct Random* rand, RunTest* runTest) { struct TestFramework* a = TestFramework_setUp("\xad\x7e\xa3\x26\xaa\x01\x94\x0a\x25\xbc\x9e\x01\x26\x22\xdb\x69" "\x4f\xd9\xb4\x17\x7c\xf3\xf8\x91\x16\xf3\xcf\xe8\x5c\x80\xe1\x4a", alloc, base, rand, logger); //"publicKey": "kmzm4w0kj9bswd5qmx74nu7kusv5pj40vcsmp781j6xxgpd59z00.k", //"ipv6": "fc41:94b5:0925:7ba9:3959:11ab:a006:367a", struct TestFramework* b = TestFramework_setUp("\xd8\x54\x3e\x70\xb9\xae\x7c\x41\xbc\x18\xa4\x9a\x9c\xee\xca\x9c" "\xdc\x45\x01\x96\x6b\xbd\x7e\x76\xcf\x3a\x9f\xbc\x12\xed\x8b\xb4", alloc, base, rand, logger); //"publicKey": "vz21tg07061s8v9mckrvgtfds7j2u5lst8cwl6nqhp81njrh5wg0.k", //"ipv6": "fc1f:5b96:e1c5:625d:afde:2523:a7fa:383a", struct TwoNodes* out = Allocator_calloc(alloc, sizeof(struct TwoNodes), 1); Identity_set(out); out->tunB.send = incomingTunB; out->tunA.send = incomingTunA; Iface_plumb(&out->tunB, b->tunIf); Iface_plumb(&out->tunA, a->tunIf); out->nodeB = b; out->nodeA = a; out->logger = logger; out->checkLinkageTimeout = Timeout_setInterval(checkLinkage, out, 1, base, alloc); out->base = base; out->startTime = Time_currentTimeMilliseconds(base); out->runTest = runTest; Log_debug(a->logger, "Waiting for nodes to link asynchronously..."); }
void TUNTools_echoTest(struct Sockaddr* udpBindTo, struct Sockaddr* tunDestAddr, TUNTools_Callback tunMessageHandler, struct Iface* tun, struct EventBase* base, struct Log* logger, struct Allocator* allocator) { struct Allocator* alloc = Allocator_child(allocator); struct AddrIface* udp = setupUDP(base, udpBindTo, alloc, logger); struct Sockaddr* dest = Sockaddr_clone(udp->addr, alloc); uint8_t* tunDestAddrBytes = NULL; uint8_t* udpDestPointer = NULL; int len = Sockaddr_getAddress(dest, &udpDestPointer); Assert_true(len && len == Sockaddr_getAddress(tunDestAddr, &tunDestAddrBytes)); Bits_memcpy(udpDestPointer, tunDestAddrBytes, len); struct TUNTools_pvt* ctx = Allocator_calloc(alloc, sizeof(struct TUNTools_pvt), 1); Identity_set(ctx); ctx->pub.udpIface.send = receiveMessageUDP; ctx->pub.tunIface.send = receiveMessageTUN; Iface_plumb(&ctx->pub.udpIface, &udp->iface); Iface_plumb(&ctx->pub.tunIface, tun); ctx->pub.cb = tunMessageHandler; ctx->pub.tunDestAddr = Sockaddr_clone(dest, alloc); ctx->pub.udpBindTo = Sockaddr_clone(udpBindTo, alloc); ctx->pub.alloc = alloc; ctx->pub.log = logger; ctx->pub.base = base; Timeout_setInterval(sendHello, ctx, 1000, base, alloc); Timeout_setTimeout(fail, NULL, 10000, base, alloc); EventBase_beginLoop(base); }