本文整理匯總了C++中Allocator_free函數的典型用法代碼示例。如果您正苦於以下問題:C++ Allocator_free函數的具體用法?C++ Allocator_free怎麽用?C++ Allocator_free使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Allocator_free函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: handleUnexpectedIncoming
/**
* Incoming message from someone we don't know, maybe someone responding to a beacon?
* expects: [ struct LLAddress ][ content ]
*/
static Iface_DEFUN handleUnexpectedIncoming(struct Message* msg,
struct InterfaceController_Iface_pvt* ici)
{
struct InterfaceController_pvt* ic = ici->ic;
struct Sockaddr* lladdr = (struct Sockaddr*) msg->bytes;
Message_shift(msg, -lladdr->addrLen, NULL);
if (msg->length < CryptoHeader_SIZE) {
return NULL;
}
struct Allocator* epAlloc = Allocator_child(ici->alloc);
lladdr = Sockaddr_clone(lladdr, epAlloc);
Assert_true(!((uintptr_t)msg->bytes % 4) && "alignment fault");
struct Peer* ep = Allocator_calloc(epAlloc, sizeof(struct Peer), 1);
Identity_set(ep);
ep->alloc = epAlloc;
ep->ici = ici;
ep->lladdr = lladdr;
ep->alloc = epAlloc;
ep->peerLink = PeerLink_new(ic->eventBase, epAlloc);
struct CryptoHeader* ch = (struct CryptoHeader*) msg->bytes;
ep->caSession = CryptoAuth_newSession(ic->ca, epAlloc, ch->publicKey, true, "outer");
if (CryptoAuth_decrypt(ep->caSession, msg)) {
// If the first message is a dud, drop all state for this peer.
// probably some random crap that wandered in the socket.
Allocator_free(epAlloc);
return NULL;
}
Assert_true(!Bits_isZero(ep->caSession->herPublicKey, 32));
Assert_true(Map_EndpointsBySockaddr_indexForKey(&lladdr, &ici->peerMap) == -1);
int index = Map_EndpointsBySockaddr_put(&lladdr, &ep, &ici->peerMap);
Assert_true(index >= 0);
ep->handle = ici->peerMap.handles[index];
Allocator_onFree(epAlloc, closeInterface, ep);
ep->state = InterfaceController_PeerState_UNAUTHENTICATED;
ep->isIncomingConnection = true;
ep->switchIf.send = sendFromSwitch;
if (SwitchCore_addInterface(ic->switchCore, &ep->switchIf, epAlloc, &ep->addr.path)) {
Log_debug(ic->logger, "handleUnexpectedIncoming() SwitchCore out of space");
Allocator_free(epAlloc);
return NULL;
}
// We want the node to immedietly be pinged but we don't want it to appear unresponsive because
// the pinger will only ping every (PING_INTERVAL * 8) so we set timeOfLastMessage to
// (now - pingAfterMilliseconds - 1) so it will be considered a "lazy node".
ep->timeOfLastMessage =
Time_currentTimeMilliseconds(ic->eventBase) - ic->pingAfterMilliseconds - 1;
Bits_memcpy(ep->addr.key, ep->caSession->herPublicKey, 32);
Bits_memcpy(ep->addr.ip6.bytes, ep->caSession->herIp6, 16);
Log_info(ic->logger, "Added peer [%s] from incoming message",
Address_toString(&ep->addr, msg->alloc)->bytes);
return receivedPostCryptoAuth(msg, ep, ic);
}
示例2: waitUntilPong
static void waitUntilPong(struct Context* ctx)
{
for (int i = 0; i < 10; i++) {
struct Allocator* temp = Allocator_child(ctx->alloc);
if (tryPing(temp, ctx)) {
Allocator_free(temp);
return;
}
sleep(200, ctx, temp);
Allocator_free(temp);
}
Assert_failure("Failed connecting to core (perhaps you have a firewall on loopback device?)");
}
示例3: search
static void search(Dict* args, void* vctx, String* txid, struct Allocator* reqAlloc)
{
struct Context* ctx = Identity_check((struct Context*) vctx);
String* addrStr = Dict_getStringC(args, "ipv6");
int maxRequests = -1;
uint64_t* maxRequestsPtr = Dict_getIntC(args, "maxRequests");
if (maxRequestsPtr) { maxRequests = *maxRequestsPtr; }
uint8_t addr[16];
if (AddrTools_parseIp(addr, (uint8_t*) addrStr->bytes)) {
Dict* resp = Dict_new(reqAlloc);
Dict_putStringCC(resp, "error", "ipv6 invalid", reqAlloc);
Admin_sendMessage(resp, txid, ctx->admin);
} else {
struct Allocator* alloc = Allocator_child(ctx->allocator);
struct Search* s = Allocator_calloc(alloc, sizeof(struct Search), 1);
s->promise = SearchRunner_search(addr, maxRequests, maxRequests, ctx->runner, alloc);
s->ctx = ctx;
s->txid = String_clone(txid, alloc);
s->alloc = alloc;
Identity_set(s);
if (!s->promise) {
Dict* resp = Dict_new(reqAlloc);
Dict_putStringCC(resp, "error", "creating search", reqAlloc);
Admin_sendMessage(resp, txid, ctx->admin);
Allocator_free(alloc);
return;
}
s->promise->userData = s;
s->promise->callback = searchResponse;
}
}
示例4: newInterface2
static void newInterface2(struct Context* ctx,
struct Sockaddr* addr,
String* txid,
struct Allocator* requestAlloc)
{
struct Allocator* const alloc = Allocator_child(ctx->alloc);
struct UDPAddrIface* udpIf = NULL;
struct Jmp jmp;
Jmp_try(jmp) {
udpIf = UDPAddrIface_new(ctx->eventBase, addr, alloc, &jmp.handler, ctx->logger);
} Jmp_catch {
String* errStr = String_CONST(jmp.message);
Dict out = Dict_CONST(String_CONST("error"), String_OBJ(errStr), NULL);
Admin_sendMessage(&out, txid, ctx->admin);
Allocator_free(alloc);
return;
}
struct AddrIface* ai = ctx->udpIf = &udpIf->generic;
struct InterfaceController_Iface* ici =
InterfaceController_newIface(ctx->ic, String_CONST("UDP"), alloc);
Iface_plumb(&ici->addrIf, &ai->iface);
Dict* out = Dict_new(requestAlloc);
Dict_putString(out, String_CONST("error"), String_CONST("none"), requestAlloc);
Dict_putInt(out, String_CONST("interfaceNumber"), ici->ifNum, requestAlloc);
char* printedAddr = Sockaddr_print(ai->addr, requestAlloc);
Dict_putString(out,
String_CONST("bindAddress"),
String_CONST(printedAddr),
requestAlloc);
Admin_sendMessage(out, txid, ctx->admin);
}
示例5: main
int main()
{
struct Allocator* alloc = MallocAllocator_new(1<<22);
struct Random* rand = Random_new(alloc, NULL, NULL);
struct Log* log = FileWriterLog_new(stdout, alloc);
uint8_t ip[16];
uint8_t printedIp[40];
uint8_t printedShortIp[40];
uint8_t ipFromFull[16];
uint8_t ipFromShort[16];
for (int i = 0; i < 1024; ++i) {
Random_bytes(rand, ip, 16);
for (int j = 0; j < 16; j++) {
// make the random result have lots of zeros since that's what we're looking for.
ip[j] = (ip[j] % 2) ? 0 : ip[j];
}
AddrTools_printIp(printedIp, ip);
AddrTools_printShortIp(printedShortIp, ip);
//printf("%s\n%s\n\n", printedIp, printedShortIp);
AddrTools_parseIp(ipFromFull, printedIp);
AddrTools_parseIp(ipFromShort, printedShortIp);
Log_debug(log, "print/parse %s", printedIp);
Assert_true(0 == Bits_memcmp(ip, ipFromFull, 16));
Assert_true(0 == Bits_memcmp(ipFromFull, ipFromShort, 16));
}
Allocator_free(alloc);
return 0;
}
示例6: main
int main(int argc, char** argv)
{
struct Allocator* alloc = MallocAllocator_new(1<<20);
struct EventBase* base = EventBase_new(alloc);
struct Log* log = FileWriterLog_new(stdout, alloc);
struct Sockaddr* addrA = Sockaddr_fromBytes(TUNTools_testIP6AddrA, Sockaddr_AF_INET6, alloc);
struct Sockaddr* addrB = Sockaddr_fromBytes(TUNTools_testIP6AddrB, Sockaddr_AF_INET6, alloc);
char assignedIfName[TUNInterface_IFNAMSIZ];
struct Iface* tap = TUNInterface_new(NULL, assignedIfName, 1, base, log, NULL, alloc);
struct TAPWrapper* tapWrapper = TAPWrapper_new(tap, log, alloc);
// Now setup the NDP server so the tun will work correctly.
struct NDPServer* ndp = NDPServer_new(&tapWrapper->internal, log, TAPWrapper_LOCAL_MAC, alloc);
struct ARPServer* arp = ARPServer_new(&ndp->internal, log, TAPWrapper_LOCAL_MAC, alloc);
addrA->flags |= Sockaddr_flags_PREFIX;
addrA->prefix = 126;
NetDev_addAddress(assignedIfName, addrA, log, NULL);
TUNTools_echoTest(addrA, addrB, TUNTools_genericIP6Echo, &arp->internal, base, log, alloc);
Allocator_free(alloc);
return 0;
}
示例7: addServer
static void addServer(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc)
{
struct Context* context = vcontext;
struct Allocator* alloc = Allocator_child(context->alloc);
String* addrStr = Dict_getString(args, String_CONST("addr"));
int ret;
struct Sockaddr_storage ss;
char* err = "none";
if (Sockaddr_parse(addrStr->bytes, &ss)) {
err = "could not parse address";
} else if ((ret = RainflyClient_addServer(context->rainfly, &ss.addr))) {
if (ret == RainflyClient_addServer_WRONG_ADDRESS_TYPE) {
err = "RainflyClient_addServer_WRONG_ADDRESS_TYPE";
} else {
err = "unknown error";
}
}
Dict* response = Dict_new(alloc);
Dict_putString(response, String_CONST("error"), String_CONST(err), alloc);
Admin_sendMessage(response, txid, context->admin);
Allocator_free(alloc);
}
示例8: ReachabilityCollector_change
void ReachabilityCollector_change(struct ReachabilityCollector* rc, struct Address* nodeAddr)
{
struct ReachabilityCollector_pvt* rcp = Identity_check((struct ReachabilityCollector_pvt*) rc);
struct Allocator* tempAlloc = Allocator_child(rcp->alloc);
change0(rcp, nodeAddr, tempAlloc);
Allocator_free(tempAlloc);
}
示例9: genReverseHandshake
/**
* If we don't know her key, the handshake has to be done backwards.
* Reverse handshake requests are signaled by sending a non-obfuscated zero nonce.
*/
static uint8_t genReverseHandshake(struct Message* message,
struct CryptoAuth_Wrapper* wrapper,
union Headers_CryptoAuth* header)
{
reset(wrapper);
Message_shift(message, -Headers_CryptoAuth_SIZE, NULL);
// Buffer the packet so it can be sent ASAP
if (wrapper->bufferedMessage != NULL) {
// Not exactly a drop but a message is not going to reach the destination.
cryptoAuthDebug0(wrapper,
"DROP Expelled a message because a session has not yet been setup");
Allocator_free(wrapper->bufferedMessage->alloc);
}
cryptoAuthDebug0(wrapper, "Buffered a message");
struct Allocator* bmalloc = Allocator_child(wrapper->externalInterface.allocator);
wrapper->bufferedMessage = Message_clone(message, bmalloc);
Assert_ifParanoid(wrapper->nextNonce == 0);
Message_shift(message, Headers_CryptoAuth_SIZE, NULL);
header = (union Headers_CryptoAuth*) message->bytes;
header->nonce = UINT32_MAX;
message->length = Headers_CryptoAuth_SIZE;
// sessionState must be 0, auth and 24 byte nonce are garbaged and public key is set
// now garbage the authenticator and the encrypted key which are not used.
Random_bytes(wrapper->context->rand, (uint8_t*) &header->handshake.authenticator, 48);
// This is a special packet which the user should never see.
Headers_setSetupPacket(&header->handshake.auth, 1);
return wrapper->wrappedInterface->sendMessage(message, wrapper->wrappedInterface);
}
示例10: addKey
static void addKey(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc)
{
struct Context* context = vcontext;
struct Allocator* alloc = Allocator_child(context->alloc);
String* identStr = Dict_getString(args, String_CONST("ident"));
int ret;
uint8_t key[32];
char* err = "none";
if (identStr->len < 52) {
err = "too short";
} else if (Base32_decode(key, 32, identStr->bytes, 52) != 32) {
err = "failed to parse";
} else if ((ret = RainflyClient_addKey(context->rainfly, key))) {
if (ret == RainflyClient_addKey_TOO_MANY_KEYS) {
err = "RainflyClient_addKey_TOO_MANY_KEYS";
} else {
err = "unknown error";
}
}
Dict* response = Dict_new(alloc);
Dict_putString(response, String_CONST("error"), String_CONST(err), alloc);
Admin_sendMessage(response, txid, context->admin);
Allocator_free(alloc);
}
示例11: InterfaceWaiter_waitForData
struct Message* InterfaceWaiter_waitForData(struct Interface* iface,
struct EventBase* eventBase,
struct Allocator* alloc,
struct Except* eh)
{
struct Context ctx = {
.eventBase = eventBase,
.alloc = alloc
};
struct Allocator* tempAlloc = Allocator_child(alloc);
iface->receiverContext = &ctx;
iface->receiveMessage = receiveMessage;
ctx.timeout = Timeout_setTimeout(timeout, &ctx, 2000, eventBase, tempAlloc);
EventBase_beginLoop(eventBase);
iface->receiveMessage = NULL;
Allocator_free(tempAlloc);
if (ctx.timedOut) {
Except_raise(eh, InterfaceWaiter_waitForData_TIMEOUT,
"InterfaceWaiter Timed out waiting for data.");
}
Assert_true(ctx.message);
return ctx.message;
}
示例12: checkRunningInstance
static void checkRunningInstance(struct Allocator* allocator,
struct EventBase* base,
String* addr,
String* password,
struct Log* logger,
struct Except* eh)
{
struct Allocator* alloc = Allocator_child(allocator);
struct Sockaddr_storage pingAddrStorage;
if (Sockaddr_parse(addr->bytes, &pingAddrStorage)) {
Except_raise(eh, -1, "Unable to parse [%s] as an ip address port, eg: 127.0.0.1:11234",
addr->bytes);
}
struct AdminClient* adminClient =
AdminClient_new(&pingAddrStorage.addr, password, base, logger, alloc);
// 100 milliseconds is plenty to wait for a process to respond on the same machine.
adminClient->millisecondsToWait = 100;
Dict* pingArgs = Dict_new(alloc);
struct AdminClient_Result* pingResult =
AdminClient_rpcCall(String_new("ping", alloc), pingArgs, adminClient, alloc);
if (pingResult->err == AdminClient_Error_NONE) {
Except_raise(eh, -1, "Startup failed: cjdroute is already running.");
}
Allocator_free(alloc);
}
示例13: cryptoAuth
static void cryptoAuth(struct Context* ctx)
{
Log_info(ctx->log, "Setting up salsa20/poly1305 benchmark (encryption and decryption only)");
struct Allocator* alloc = Allocator_child(ctx->alloc);
struct CryptoAuth* ca1 = CryptoAuth_new(alloc, NULL, ctx->base, ctx->log, ctx->rand);
struct CryptoAuth* ca2 = CryptoAuth_new(alloc, NULL, ctx->base, ctx->log, ctx->rand);
struct CryptoAuth_Session* sess1 =
CryptoAuth_newSession(ca1, alloc, ca2->publicKey, NULL, false, "bench");
struct CryptoAuth_Session* sess2 =
CryptoAuth_newSession(ca2, alloc, ca1->publicKey, NULL, false, "bench");
int size = 1500;
int count = 100000;
struct Message* msg = Message_new(size, 256, alloc);
Random_bytes(ctx->rand, msg->bytes, msg->length);
// setup session
for (int i = 0; i < 2; i++) {
Assert_true(!CryptoAuth_encrypt(sess1, msg));
Assert_true(!CryptoAuth_decrypt(sess2, msg));
Assert_true(!CryptoAuth_encrypt(sess2, msg));
Assert_true(!CryptoAuth_decrypt(sess1, msg));
}
begin(ctx, "salsa20/poly1305", (count * size * 8) / 1024, "kilobits");
for (int i = 0; i < count; i++) {
Assert_true(!CryptoAuth_encrypt(sess1, msg));
Assert_true(!CryptoAuth_decrypt(sess2, msg));
}
done(ctx);
Allocator_free(alloc);
}
示例14: getHandles
static void getHandles(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc)
{
struct Context* context = Identity_check((struct Context*) vcontext);
struct Allocator* alloc = Allocator_child(context->alloc);
int64_t* page = Dict_getInt(args, String_CONST("page"));
int i = (page) ? *page * ENTRIES_PER_PAGE : 0;
struct SessionManager_HandleList* hList = SessionManager_getHandleList(context->sm, alloc);
List* list = List_new(alloc);
for (int counter = 0; i < hList->length && counter++ < ENTRIES_PER_PAGE; i++) {
List_addInt(list, hList->handles[i], alloc);
}
Dict* r = Dict_new(alloc);
Dict_putList(r, String_CONST("handles"), list, alloc);
Dict_putInt(r, String_CONST("total"), hList->length, alloc);
String* more = String_CONST("more");
if (i < hList->length) {
Dict_putInt(r, more, 1, alloc);
}
Admin_sendMessage(r, txid, context->admin);
Allocator_free(alloc);
}
示例15: timeout
static void timeout(void* vrequest)
{
struct Request* req = Identity_check((struct Request*) vrequest);
Dict resp = Dict_CONST(String_CONST("error"), String_OBJ(String_CONST("timeout")), NULL);
req->onResponse(&resp, req->onResponseContext);
Allocator_free(req->alloc);
}