本文整理汇总了C++中MallocAllocator_new函数的典型用法代码示例。如果您正苦于以下问题:C++ MallocAllocator_new函数的具体用法?C++ MallocAllocator_new怎么用?C++ MallocAllocator_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MallocAllocator_new函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
char* pingBenc = "d1:q4:ping4:txid4:abcde";
struct Allocator* alloc = MallocAllocator_new(1<<22);
struct TestFramework* tf = TestFramework_setUp("0123456789abcdefghijklmnopqrstuv", alloc, NULL);
struct Ducttape_pvt* dt = Identity_cast((struct Ducttape_pvt*) tf->ducttape);
struct Allocator* allocator = MallocAllocator_new(85000);
uint16_t buffLen = sizeof(struct Ducttape_IncomingForMe) + 8 + strlen(pingBenc);
uint8_t* buff = allocator->calloc(buffLen, 1, allocator);
struct Headers_SwitchHeader* sh = (struct Headers_SwitchHeader*) buff;
sh->label_be = Endian_hostToBigEndian64(4);
struct Headers_IP6Header* ip6 = (struct Headers_IP6Header*) &sh[1];
uint8_t herPublicKey[32];
Base32_decode(herPublicKey, 32,
(uint8_t*) "0z5tscp8td1sc6cv4htp7jbls79ltqxw9pbg190x0kbm1lguqtx0", 52);
AddressCalc_addressForPublicKey(ip6->sourceAddr, herPublicKey);
struct Headers_UDPHeader* udp = (struct Headers_UDPHeader*) &ip6[1];
ip6->hopLimit = 0;
ip6->nextHeader = 17;
udp->sourceAndDestPorts = 0;
udp->length_be = Endian_hostToBigEndian16(strlen(pingBenc));
strncpy((char*)(udp + 1), pingBenc, strlen(pingBenc));
dt->switchInterface.receiveMessage = catchResponse;
dt->switchInterface.receiverContext = NULL;
// bad checksum
udp->checksum_be = 1;
struct Message m = { .bytes = buff, .length = buffLen, .padding = 0 };
Ducttape_injectIncomingForMe(&m, &dt->public, herPublicKey);
Assert_always(!dt->switchInterface.receiverContext);
// zero checksum
udp->checksum_be = 0;
struct Message m2 = { .bytes = buff, .length = buffLen, .padding = 0 };
Ducttape_injectIncomingForMe(&m2, &dt->public, herPublicKey);
Assert_always(dt->switchInterface.receiverContext);
// good checksum
udp->checksum_be =
Checksum_udpIp6(ip6->sourceAddr, (uint8_t*) udp, strlen(pingBenc) + Headers_UDPHeader_SIZE);
struct Message m3 = { .bytes = buff, .length = buffLen, .padding = 0 };
Ducttape_injectIncomingForMe(&m3, &dt->public, herPublicKey);
Assert_always(dt->switchInterface.receiverContext);
}
示例2: main
int main()
{
struct Allocator* alloc = MallocAllocator_new(1<<20);
struct TestFramework* tf =
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, NULL, NULL, NULL);
CryptoAuth_addUser(String_CONST("passwd"), 1, String_CONST("TEST"), tf->cryptoAuth);
struct Message* message;
struct Interface iface = {
.sendMessage = messageFromInterface,
.senderContext = &message,
.allocator = alloc
};
SwitchCore_setRouterInterface(&iface, tf->switchCore);
////////////////////////
int ret = reconnectionNewEndpointTest(tf->ifController,
tf->publicKey,
&message,
alloc,
tf->eventBase,
tf->logger,
&iface,
tf->rand);
Allocator_free(alloc);
return ret;
}
示例3: repeatHello
static void repeatHello()
{
uint8_t* expectedOutput =
"0000000101641c99f7719f5700000000a693a9fd3f0e27e81ab1100b57b37259"
"4c2adca8671f1fdd050383c91e7d56ec2336c09739fa8e91d8dc5bec63e8fad0"
"74bee22a90642a6ba8555be84c5e35970c5270e8f31f2a5978e0fbdee4542882"
"97568f25a3fc2801aa707d954c78eccb970bcc8cb26867e9dbf0c9d6ef1b3f27"
"24e7e550";
struct Allocator* alloc = MallocAllocator_new(1<<20);
struct Context* ctx = setUp(NULL, HERPUBKEY, "password", alloc);
struct Message* msg = Message_new(0, CryptoHeader_SIZE + HELLOWORLDLEN, alloc);
Message_push(msg, HELLOWORLD, HELLOWORLDLEN, NULL);
Assert_true(!CryptoAuth_encrypt(ctx->sess, msg));
Message_reset(msg);
Message_push(msg, HELLOWORLD, HELLOWORLDLEN, NULL);
Assert_true(!CryptoAuth_encrypt(ctx->sess, msg));
char* actual = Hex_print(msg->bytes, msg->length, alloc);
if (CString_strcmp(actual, expectedOutput)) {
Assert_failure("Test failed.\n"
"Expected %s\n"
" Got %s\n", expectedOutput, actual);
}
Allocator_free(alloc);
}
示例4: main
int main(int argc, char** argv)
{
if (argc > 1) {
respondToPipe(argv[1]);
return 0;
}
struct Allocator* alloc = MallocAllocator_new(1<<20);
char* path = Process_getPath(alloc);
Assert_true(path != NULL);
Assert_true(strstr(path, "/Process_test"));
Assert_true(path[0] == '/');
int fds[2];
Assert_true(!Pipe_createUniPipe(fds));
char fdName[32];
snprintf(fdName, 32, "%d", fds[1]);
char* args[] = { fdName, NULL };
Assert_true(!Process_spawn(path, args));
char output[32] = {0};
ssize_t len = read(fds[0], output, 31);
Assert_true(len == strlen(MESSAGE));
Assert_true(!strcmp(MESSAGE, output));
}
示例5: testDuplicates
static void testDuplicates(struct Random* rand)
{
uint16_t randomShorts[8192];
uint16_t out[8192];
struct ReplayProtector rp = {.bitfield = 0};
Random_bytes(rand, (uint8_t*)randomShorts, sizeof(randomShorts));
uint32_t outIdx = 0;
for (uint32_t i = 0; i < 1024; i++) {
if (ReplayProtector_checkNonce((randomShorts[i] % (i + 20)), &rp)) {
out[outIdx] = (randomShorts[i] % (i + 20));
outIdx++;
}
}
for (uint32_t i = 0; i < outIdx; i++) {
for (uint32_t j = i + 1; j < outIdx; j++) {
Assert_always(out[i] != out[j]);
}
}
}
int main()
{
struct Allocator* alloc = MallocAllocator_new(4096);
struct Random* rand = Random_new(alloc, NULL, NULL);
for (int i = 0; i < CYCLES; i++) {
testDuplicates(rand);
}
return 0;
}
示例6: main
int main(int argc, char** argv)
{
printf("init test");
struct Allocator* alloc = MallocAllocator_new(1<<20);
struct Log* logger = FileWriterLog_new(stdout, alloc);
struct EventBase* base = EventBase_new(alloc);
char* ifName;
struct Iface* iface = TAPInterface_new(NULL, &ifName, NULL, logger, base, alloc);
struct NDPServer* ndp = NDPServer_new(iface, alloc);
ndp->generic.receiveMessage = receiveMessage;
ndp->generic.receiverContext = alloc;
ndp->advertisePrefix[0] = 0xfd;
ndp->prefixLen = AddressCalc_ADDRESS_PREFIX_BITS;
struct Sockaddr_storage ss;
Assert_true(!Sockaddr_parse("fd00::1", &ss));
NetDev_addAddress(ifName, &ss.addr, AddressCalc_ADDRESS_PREFIX_BITS, logger, NULL);
Timeout_setTimeout(fail, alloc, 10000, base, alloc);
EventBase_beginLoop(base);
printf("Test ended\n");
return 0;
}
示例7: main
int main()
{
struct Allocator* alloc = MallocAllocator_new(1<<22);
struct Random* rand = Random_new(alloc, NULL, NULL);
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);
AddrTools_printIp(printedIp, ip);
AddrTools_printShortIp(printedShortIp, ip);
printf("%s\n%s\n\n", printedIp, printedShortIp);
AddrTools_parseIp(ipFromFull, printedIp);
AddrTools_parseIp(ipFromShort, printedShortIp);
Assert_true(0 == Bits_memcmp(ip, ipFromFull, 16));
Assert_true(0 == Bits_memcmp(ipFromFull, ipFromShort, 16));
}
return 0;
}
示例8: 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;
}
示例9: 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;
}
示例10: main
int main()
{
struct Allocator* alloc = MallocAllocator_new(1048576);
struct Log* logger = FileWriterLog_new(stdout, alloc);
struct Random* rand = Random_new(alloc, logger, NULL);
uint8_t curve25519private[32];
Random_bytes(rand, curve25519private, 32);
uint8_t curve25519public[32];
crypto_scalarmult_curve25519_base(curve25519public, curve25519private);
uint8_t signingKeyPair[64];
Sign_signingKeyPairFromCurve25519(signingKeyPair, curve25519private);
struct Message* msg = Message_new(0, 512, alloc);
Message_push(msg, "hello world", 12, NULL);
Sign_signMsg(signingKeyPair, msg, rand);
uint8_t curve25519publicB[32];
Assert_true(!Sign_verifyMsg(&signingKeyPair[32], msg));
Assert_true(!Sign_publicSigningKeyToCurve25519(curve25519publicB, &signingKeyPair[32]));
Assert_true(!Bits_memcmp(curve25519publicB, curve25519public, 32));
Allocator_free(alloc);
return 0;
}
示例11: main
int main(int argc, char** argv)
{
if (isatty(STDIN_FILENO)) {
printf("Usage: %s < cjdroute.conf > compliant.json\n", argv[0]);
printf("Cjdns accepts configuration which is not valid json but only outputs json\n"
"which is valid. This tool deserialies and reserialized a conf file or other "
"json file.\n");
printf("In honor of thefinn93, thanks for all of your hard work helping people.\n");
return 0;
}
struct Allocator* allocator = MallocAllocator_new(1<<20);
struct Reader* stdinReader = FileReader_new(stdin, allocator);
Dict config;
if (JsonBencSerializer_get()->parseDictionary(stdinReader, allocator, &config)) {
fprintf(stderr, "Failed to parse configuration.\n");
return -1;
}
struct Writer* stdoutWriter = FileWriter_new(stdout, allocator);
JsonBencSerializer_get()->serializeDictionary(stdoutWriter, &config);
printf("\n");
Allocator_free(allocator);
}
示例12: AdminTestFramework_setUp
struct AdminTestFramework* AdminTestFramework_setUp()
{
struct Allocator* alloc = MallocAllocator_new(1<<20);
struct Writer* logwriter = FileWriter_new(stdout, alloc);
Assert_always(logwriter);
struct Log* logger =
alloc->clone(sizeof(struct Log), alloc, &(struct Log) { .writer = logwriter });
示例13: fromName
static void fromName()
{
struct Allocator* alloc = MallocAllocator_new(20000);
Sockaddr_fromName("localhost", alloc);
// This will fail in some cases (eg dns hijacking)
//Assert_always(!Sockaddr_fromName("hasjklgyolgbvlbiogi", alloc));
Allocator_free(alloc);
}
示例14: AdminTestFramework_setUp
struct AdminTestFramework* AdminTestFramework_setUp(int argc, char** argv, char* testName)
{
if (argc > 2 && !strcmp(testName, argv[1]) && !strcmp("angel", argv[2])) {
exit(AngelInit_main(argc-1, &argv[1]));
}
struct Allocator* alloc = MallocAllocator_new(1<<20);
struct Writer* logwriter = FileWriter_new(stdout, alloc);
Assert_true(logwriter);
struct Log* logger = WriterLog_new(logwriter, alloc);
struct EventBase* eventBase = EventBase_new(alloc);
struct Random* rand = Random_new(alloc, logger, NULL);
char asClientPipeName[32] = {0};
Random_base32(rand, (uint8_t*)asClientPipeName, 31);
struct Pipe* asClientPipe = Pipe_named(asClientPipeName, eventBase, NULL, alloc);
asClientPipe->logger = logger;
char asCorePipeName[32] = {0};
Random_base32(rand, (uint8_t*)asCorePipeName, 31);
struct Pipe* asCorePipe = Pipe_named(asCorePipeName, eventBase, NULL, alloc);
asCorePipe->logger = logger;
struct Interface* asCoreIface = FramingInterface_new(65535, &asCorePipe->iface, alloc);
spawnAngel(testName, asClientPipeName, eventBase, alloc);
Log_info(logger, "Initializing Angel");
initAngel(asClientPipe, asCoreIface, (char*)asCorePipe->name, eventBase, logger, alloc, rand);
struct Sockaddr_storage addr;
Assert_true(!Sockaddr_parse("127.0.0.1", &addr));
Log_info(logger, "Binding UDP admin socket");
struct AddrInterface* udpAdmin =
UDPAddrInterface_new(eventBase, &addr.addr, alloc, NULL, logger);
String* password = String_new("abcd", alloc);
struct Admin* admin = Admin_new(udpAdmin, alloc, logger, eventBase, password);
// Now setup the client.
struct AdminClient* client =
AdminClient_new(udpAdmin->addr, password, eventBase, logger, alloc);
Assert_true(client);
return Allocator_clone(alloc, (&(struct AdminTestFramework) {
.admin = admin,
.client = client,
.alloc = alloc,
.eventBase = eventBase,
.logger = logger,
.addr = Sockaddr_clone(udpAdmin->addr, alloc),
.angelInterface = asCoreIface
}));
示例15: main
int main()
{
struct Allocator* alloc = MallocAllocator_new(20000000);
struct Random* rand = Random_new(alloc, NULL, NULL);
packUnpack(rand);
return 0;
}