-
Notifications
You must be signed in to change notification settings - Fork 6
/
helloWorld_ConsumerForever.c
102 lines (80 loc) · 3.14 KB
/
helloWorld_ConsumerForever.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* Copyright 2014 Palo Alto Research Center, Inc. (PARC), a Xerox company. All Rights Reserved.
* The content of this file, whole or in part, is subject to licensing terms.
* If distributing this software, include this License Header Notice in each
* file and provide the accompanying LICENSE file.
*/
/**
* @author Glenn Scott, Computing Science Laboratory, PARC
* @copyright 2014 Palo Alto Research Center, Inc. (PARC), A Xerox Company. All Rights Reserved.
*/
#include <config.h>
#include <stdio.h>
#include <LongBow/runtime.h>
#include <ccnx/api/ccnx_Portal/ccnx_Portal.h>
#include <ccnx/api/ccnx_Portal/ccnx_PortalRTA.h>
#include <parc/security/parc_Security.h>
#include <parc/security/parc_IdentityFile.h>
#include <parc/security/parc_PublicKeySignerPkcs12Store.h>
#include <parc/algol/parc_Memory.h>
PARCIdentity *
createAndGetIdentity(void)
{
parcSecurity_Init();
const char *keystoreName = "consumer_keystore";
const char *keystorePassword = "keystore_password";
unsigned int keyLength = 1024;
unsigned int validityDays = 30;
char *subjectName = "consumer";
bool success = parcPublicKeySignerPkcs12Store_CreateFile(keystoreName, keystorePassword, subjectName, keyLength, validityDays);
assertTrue(success,
"parcPublicKeySignerPkcs12Store_CreateFile('%s', '%s', '%s', %d, %d) failed.",
keystoreName, keystorePassword, subjectName, keyLength, validityDays);
PARCIdentityFile *identityFile = parcIdentityFile_Create(keystoreName, keystorePassword);
PARCIdentity *identity = parcIdentity_Create(identityFile, PARCIdentityFileAsPARCIdentity);
parcIdentityFile_Release(&identityFile);
parcSecurity_Fini();
return identity;
}
CCNxPortalFactory *
setupConsumerFactory(void)
{
PARCIdentity *identity = createAndGetIdentity();
CCNxPortalFactory *factory = ccnxPortalFactory_Create(identity);
parcIdentity_Release(&identity);
return factory;
}
int
consumer(void)
{
CCNxPortalFactory *factory = setupConsumerFactory();
CCNxPortal *portal =
ccnxPortalFactory_CreatePortal(factory, ccnxPortalRTA_Message);
assertNotNull(portal, "Expected a non-null CCNxPortal pointer.");
CCNxName *name = ccnxName_CreateFromURI("lci:/Hello/World");
CCNxInterest *interest = ccnxInterest_CreateSimple(name);
ccnxName_Release(&name);
for (int i = 0; i < 50000; i++) {
CCNxMetaMessage *message = ccnxMetaMessage_CreateFromInterest(interest);
if (ccnxPortal_Send(portal, message, CCNxStackTimeout_Never)) {
while (ccnxPortal_IsError(portal) == false) {
CCNxMetaMessage *response = ccnxPortal_Receive(portal, CCNxStackTimeout_Never);
if (response != NULL) {
if (ccnxMetaMessage_IsContentObject(response)) {
break;
}
}
ccnxMetaMessage_Release(&response);
}
}
}
ccnxPortal_Release(&portal);
ccnxPortalFactory_Release(&factory);
return 0;
}
int
main(int argc, char *argv[argc])
{
return consumer();
}