signbenchtest.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdlib.h>
00020 #include <stdint.h>
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <ccn/ccn.h>
00024 #include <ccn/charbuf.h>
00025 #include <ccn/keystore.h>
00026 #include <time.h>
00027 #include <sys/time.h>
00028
00029 #define FRESHNESS 10
00030 #define COUNT 3000
00031 #define PAYLOAD_SIZE 51
00032
00033 int
00034 main(int argc, char **argv)
00035 {
00036
00037 struct ccn_keystore *keystore = NULL;
00038 int res = 0;
00039 struct ccn_charbuf *signed_info = ccn_charbuf_create();
00040 int i;
00041 int sec, usec;
00042 char msgbuf[PAYLOAD_SIZE];
00043 struct timeval start, end;
00044 struct ccn_charbuf *message = ccn_charbuf_create();
00045 struct ccn_charbuf *path = ccn_charbuf_create();
00046 struct ccn_charbuf *seq = ccn_charbuf_create();
00047
00048 struct ccn_charbuf *temp = ccn_charbuf_create();
00049 keystore = ccn_keystore_create();
00050 ccn_charbuf_putf(temp, "%s/.ccnx/.ccnx_keystore", getenv("HOME"));
00051 res = ccn_keystore_init(keystore,
00052 ccn_charbuf_as_string(temp),
00053 "Th1s1sn0t8g00dp8ssw0rd.");
00054 if (res != 0) {
00055 printf("Failed to initialize keystore %s\n", ccn_charbuf_as_string(temp));
00056 exit(1);
00057 }
00058 ccn_charbuf_destroy(&temp);
00059
00060 res = ccn_signed_info_create(signed_info,
00061 ccn_keystore_public_key_digest(keystore),
00062 ccn_keystore_public_key_digest_length(keystore),
00063 NULL,
00064 CCN_CONTENT_DATA,
00065 FRESHNESS,
00066 NULL,
00067 NULL);
00068
00069 srandom(time(NULL));
00070 for (i=0; i<PAYLOAD_SIZE; i++) {
00071 msgbuf[i] = random();
00072 }
00073
00074 printf("Generating %d signed ContentObjects (one . per 100)\n", COUNT);
00075 gettimeofday(&start, NULL);
00076
00077 for (i=0; i<COUNT; i++) {
00078
00079 if (i>0 && (i%100) == 0) {
00080 printf(".");
00081 fflush(stdout);
00082 }
00083 ccn_name_init(path);
00084 ccn_name_append_str(path, "rtp");
00085 ccn_name_append_str(path, "protocol");
00086 ccn_name_append_str(path, "13.2.117.34");
00087 ccn_name_append_str(path, "domain");
00088 ccn_name_append_str(path, "smetters");
00089 ccn_name_append_str(path, "principal");
00090 ccn_name_append_str(path, "2021915340");
00091 ccn_name_append_str(path, "id");
00092 ccn_charbuf_putf(seq, "%u", i);
00093 ccn_name_append(path, seq->buf, seq->length);
00094 ccn_name_append_str(path, "seq");
00095
00096 res = ccn_encode_ContentObject( message,
00097 path, signed_info,
00098 msgbuf, PAYLOAD_SIZE,
00099 NULL,
00100 ccn_keystore_private_key(keystore));
00101
00102 ccn_charbuf_reset(message);
00103 ccn_charbuf_reset(path);
00104 ccn_charbuf_reset(seq);
00105 }
00106 gettimeofday(&end, NULL);
00107 sec = end.tv_sec - start.tv_sec;
00108 usec = (int)end.tv_usec - (int)start.tv_usec;
00109 while (usec < 0) {
00110 sec--;
00111 usec += 1000000;
00112 }
00113
00114 printf("\nComplete in %d.%06d secs\n", sec, usec);
00115
00116 return(0);
00117 }