本文整理匯總了C++中Allocator_calloc函數的典型用法代碼示例。如果您正苦於以下問題:C++ Allocator_calloc函數的具體用法?C++ Allocator_calloc怎麽用?C++ Allocator_calloc使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Allocator_calloc函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: DHTModuleRegistry_new
struct DHTModuleRegistry* DHTModuleRegistry_new(struct Allocator* allocator)
{
struct DHTModuleRegistry* reg =
Allocator_calloc(allocator, sizeof(struct DHTModuleRegistry), 1);
reg->allocator = allocator;
reg->members = Allocator_calloc(allocator, sizeof(char*), 1);
return reg;
}
示例2: NetCore_new
struct NetCore* NetCore_new(uint8_t* privateKey,
struct Allocator* allocator,
struct EventBase* base,
struct Random* rand,
struct Log* log)
{
struct Allocator* alloc = Allocator_child(allocator);
struct NetCore* nc = Allocator_calloc(alloc, sizeof(struct NetCore), 1);
nc->alloc = alloc;
nc->base = base;
nc->rand = rand;
nc->log = log;
struct CryptoAuth* ca = nc->ca = CryptoAuth_new(alloc, privateKey, base, log, rand);
struct EventEmitter* ee = nc->ee = EventEmitter_new(alloc, log, ca->publicKey);
struct Address* myAddress = nc->myAddress = Allocator_calloc(alloc, sizeof(struct Address), 1);
Bits_memcpy(myAddress->key, ca->publicKey, 32);
Address_getPrefix(myAddress);
myAddress->protocolVersion = Version_CURRENT_PROTOCOL;
myAddress->path = 1;
// lower half
struct SwitchCore* switchCore = nc->switchCore = SwitchCore_new(log, alloc, base);
struct SwitchAdapter* switchAdapter = nc->switchAdapter = SwitchAdapter_new(alloc, log);
Iface_plumb(&switchAdapter->switchIf, switchCore->routerIf);
struct ControlHandler* controlHandler = nc->controlHandler =
ControlHandler_new(alloc, log, ee, ca->publicKey);
Iface_plumb(&controlHandler->coreIf, &switchAdapter->controlIf);
struct SwitchPinger* sp = nc->sp = SwitchPinger_new(base, rand, log, myAddress, alloc);
Iface_plumb(&controlHandler->switchPingerIf, &sp->controlHandlerIf);
nc->ifController = InterfaceController_new(ca, switchCore, log, base, sp, rand, alloc, ee);
// session manager
struct SessionManager* sm = nc->sm = SessionManager_new(alloc, base, ca, rand, log, ee);
Iface_plumb(&switchAdapter->sessionManagerIf, &sm->switchIf);
// upper half
struct UpperDistributor* upper = nc->upper = UpperDistributor_new(alloc, log, ee, myAddress);
Iface_plumb(&sm->insideIf, &upper->sessionManagerIf);
struct TUNAdapter* tunAdapt = nc->tunAdapt = TUNAdapter_new(alloc, log, myAddress->ip6.bytes);
Iface_plumb(&tunAdapt->upperDistributorIf, &upper->tunAdapterIf);
return nc;
}
示例3: SupernodeHunter_new
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;
}
示例4: GlobalConfig_new
struct GlobalConfig* GlobalConfig_new(struct Allocator* alloc)
{
struct GlobalConfig_pvt* gcp = Allocator_calloc(alloc, sizeof(struct GlobalConfig_pvt), 1);
Identity_set(gcp);
gcp->alloc = alloc;
return &gcp->pub;
}
示例5: CryptoAuth_newSession
struct CryptoAuth_Session* CryptoAuth_newSession(struct CryptoAuth* ca,
struct Allocator* alloc,
const uint8_t herPublicKey[32],
const uint8_t herIp6[16],
const bool requireAuth,
char* displayName)
{
struct CryptoAuth_pvt* context = Identity_check((struct CryptoAuth_pvt*) ca);
struct CryptoAuth_Session_pvt* session =
Allocator_calloc(alloc, sizeof(struct CryptoAuth_Session_pvt), 1);
Identity_set(session);
session->context = context;
session->requireAuth = requireAuth;
session->pub.displayName = String_new(displayName, alloc);
session->timeOfLastPacket = Time_currentTimeSeconds(context->eventBase);
session->alloc = alloc;
if (herPublicKey != NULL) {
Bits_memcpyConst(session->pub.herPublicKey, herPublicKey, 32);
uint8_t calculatedIp6[16];
AddressCalc_addressForPublicKey(calculatedIp6, herPublicKey);
Bits_memcpyConst(session->pub.herIp6, calculatedIp6, 16);
if (herIp6 != NULL) {
Assert_true(!Bits_memcmp(calculatedIp6, herIp6, 16));
}
} else if (herIp6) {
Bits_memcpyConst(session->pub.herIp6, herIp6, 16);
}
return &session->pub;
}
示例6: RandomSeed_new
struct RandomSeed* RandomSeed_new(RandomSeed_Provider* providers,
int providerCount,
struct Log* logger,
struct Allocator* alloc)
{
struct RandomSeed** rsList = Allocator_calloc(alloc, sizeof(struct RandomSeed), providerCount);
int i = 0;
for (int j = 0; j < providerCount; j++) {
struct RandomSeed* rs = providers[j](alloc);
if (rs) {
rsList[i++] = rs;
}
}
Assert_true(i > 0);
struct RandomSeed_pvt* out = Allocator_malloc(alloc, sizeof(struct RandomSeed_pvt));
out->rsList = rsList;
out->rsCount = i;
out->logger = logger;
out->pub.get = get;
out->pub.name = "RandomSeed conglomeration of random seed providers";
Identity_set(out);
return &out->pub;
}
示例7: Core_init
void Core_init(struct Allocator* alloc,
struct Log* logger,
struct EventBase* eventBase,
uint8_t privateKey[32],
struct Admin* admin,
struct Random* rand,
struct Except* eh,
struct FakeNetwork* fakeNet,
bool noSec)
{
struct Security* sec = NULL;
if (!noSec) {
sec = Security_new(alloc, logger, eventBase);
}
struct NetCore* nc = NetCore_new(privateKey, alloc, eventBase, rand, logger);
struct IpTunnel* ipTunnel = IpTunnel_new(logger, eventBase, alloc, rand);
Iface_plumb(&nc->tunAdapt->ipTunnelIf, &ipTunnel->tunInterface);
Iface_plumb(&nc->upper->ipTunnelIf, &ipTunnel->nodeInterface);
// The link between the Pathfinder and the core needs to be asynchronous.
struct Pathfinder* pf = Pathfinder_register(alloc, logger, eventBase, rand, admin);
struct ASynchronizer* pfAsync = ASynchronizer_new(alloc, eventBase, logger);
Iface_plumb(&pfAsync->ifA, &pf->eventIf);
EventEmitter_regPathfinderIface(nc->ee, &pfAsync->ifB);
// ------------------- Register RPC functions ----------------------- //
InterfaceController_admin_register(nc->ifController, admin, alloc);
SwitchPinger_admin_register(nc->sp, admin, alloc);
UDPInterface_admin_register(eventBase, alloc, logger, admin, nc->ifController, fakeNet);
#ifdef HAS_ETH_INTERFACE
ETHInterface_admin_register(eventBase, alloc, logger, admin, nc->ifController);
#endif
AuthorizedPasswords_init(admin, nc->ca, alloc);
Admin_registerFunction("ping", adminPing, admin, false, NULL, admin);
if (!noSec) {
Security_admin_register(alloc, logger, sec, admin);
}
IpTunnel_admin_register(ipTunnel, admin, alloc);
SessionManager_admin_register(nc->sm, admin, alloc);
Allocator_admin_register(alloc, admin);
struct Context* ctx = Allocator_calloc(alloc, sizeof(struct Context), 1);
Identity_set(ctx);
ctx->alloc = alloc;
ctx->admin = admin;
ctx->logger = logger;
ctx->base = eventBase;
ctx->ipTunnel = ipTunnel;
ctx->nc = nc;
Admin_registerFunction("Core_exit", adminExit, ctx, true, NULL, admin);
Admin_registerFunction("Core_pid", adminPid, admin, false, NULL, admin);
Admin_registerFunction("Core_initTunnel", initTunnel, ctx, true,
((struct Admin_FunctionArg[]) {
{ .name = "desiredTunName", .required = 0, .type = "String" }
}), admin);
示例8: 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;
}
}
示例9: CryptoAuth_new
struct CryptoAuth* CryptoAuth_new(struct Allocator* allocator,
const uint8_t* privateKey,
struct EventBase* eventBase,
struct Log* logger,
struct Random* rand)
{
struct CryptoAuth_pvt* ca = Allocator_calloc(allocator, sizeof(struct CryptoAuth_pvt), 1);
Identity_set(ca);
ca->allocator = allocator;
ca->eventBase = eventBase;
ca->logger = logger;
ca->pub.resetAfterInactivitySeconds = CryptoAuth_DEFAULT_RESET_AFTER_INACTIVITY_SECONDS;
ca->rand = rand;
if (privateKey != NULL) {
Bits_memcpyConst(ca->privateKey, privateKey, 32);
} else {
Random_bytes(rand, ca->privateKey, 32);
}
crypto_scalarmult_curve25519_base(ca->pub.publicKey, ca->privateKey);
if (Defined(Log_KEYS)) {
uint8_t publicKeyHex[65];
printHexKey(publicKeyHex, ca->pub.publicKey);
uint8_t privateKeyHex[65];
printHexKey(privateKeyHex, ca->privateKey);
Log_keys(logger,
"Initialized CryptoAuth:\n myPrivateKey=%s\n myPublicKey=%s\n",
privateKeyHex,
publicKeyHex);
}
return &ca->pub;
}
示例10: 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);
}
示例11: newMessage
static struct Message* newMessage(struct Allocator* alloc, int messageSize)
{
uint8_t* buff = Allocator_calloc(alloc, messageSize + 64, 1);
return Allocator_clone(alloc, (&(struct Message) {
.bytes = buff + 64,
.length = messageSize,
.padding = 64
}));
示例12: Security_new
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;
}
示例13: AddrSet_new
struct AddrSet* AddrSet_new(struct Allocator* allocator)
{
struct Allocator* alloc = Allocator_child(allocator);
struct AddrSet_pvt* out = Allocator_calloc(alloc, sizeof(struct AddrSet_pvt), 1);
out->alloc = alloc;
out->addrList = ArrayList_OfAddrs_new(alloc);
Identity_set(out);
return &out->pub;
}
示例14: RumorMill_new
struct RumorMill* RumorMill_new(struct Allocator* allocator,
struct Address* selfAddr,
int capacity,
struct Log* log,
const char* name)
{
struct Allocator* alloc = Allocator_child(allocator);
Address_getPrefix(selfAddr);
struct RumorMill_pvt* rm = Allocator_calloc(alloc, sizeof(struct RumorMill_pvt), 1);
rm->pub.addresses = Allocator_calloc(alloc, sizeof(struct Address), capacity);
rm->capacity = capacity;
rm->selfAddr = Allocator_clone(alloc, selfAddr);
rm->log = log;
rm->pub.name = name;
Identity_set(rm);
return &rm->pub;
}
示例15: PeerLink_new
struct PeerLink* PeerLink_new(struct EventBase* base, struct Allocator* allocator)
{
struct Allocator* alloc = Allocator_child(allocator);
struct PeerLink_pvt* pl = Allocator_calloc(alloc, sizeof(struct PeerLink_pvt), 1);
Identity_set(pl);
pl->base = base;
pl->alloc = alloc;
pl->queue = ArrayList_Messages_new(alloc);
return &pl->pub;
}