diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-05 17:31:35 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-05 17:31:35 +0000 |
commit | 65ffaca5903a9cb31050b8bd378f1bf4647b2549 (patch) | |
tree | 157328b1b4c3310b8ce2549565baf08a3ec973e8 /src/namestore/test_namestore_api_zone_to_name.c | |
parent | 61e42c16dc624c29cd343c3630314d058779ea0a (diff) | |
download | gnunet-65ffaca5903a9cb31050b8bd378f1bf4647b2549.tar.gz gnunet-65ffaca5903a9cb31050b8bd378f1bf4647b2549.zip |
- changes
Diffstat (limited to 'src/namestore/test_namestore_api_zone_to_name.c')
-rw-r--r-- | src/namestore/test_namestore_api_zone_to_name.c | 86 |
1 files changed, 76 insertions, 10 deletions
diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c index 387d58272..bd03987d5 100644 --- a/src/namestore/test_namestore_api_zone_to_name.c +++ b/src/namestore/test_namestore_api_zone_to_name.c | |||
@@ -29,6 +29,11 @@ | |||
29 | 29 | ||
30 | #define VERBOSE GNUNET_NO | 30 | #define VERBOSE GNUNET_NO |
31 | 31 | ||
32 | #define RECORDS 5 | ||
33 | #define TEST_RECORD_TYPE 1234 | ||
34 | #define TEST_RECORD_DATALEN 123 | ||
35 | #define TEST_RECORD_DATA 'a' | ||
36 | |||
32 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
33 | 38 | ||
34 | static struct GNUNET_NAMESTORE_Handle * nsh; | 39 | static struct GNUNET_NAMESTORE_Handle * nsh; |
@@ -39,9 +44,16 @@ static struct GNUNET_OS_Process *arm; | |||
39 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; | 44 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; |
40 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | 45 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; |
41 | 46 | ||
47 | struct GNUNET_TIME_Absolute expire; | ||
48 | |||
42 | static GNUNET_HashCode s_zone; | 49 | static GNUNET_HashCode s_zone; |
43 | static GNUNET_HashCode s_zone_value; | 50 | static GNUNET_HashCode s_zone_value; |
44 | 51 | ||
52 | char * s_name; | ||
53 | |||
54 | struct GNUNET_NAMESTORE_RecordData *s_rd; | ||
55 | struct GNUNET_CRYPTO_RsaSignature *s_signature; | ||
56 | |||
45 | static int res; | 57 | static int res; |
46 | 58 | ||
47 | static void | 59 | static void |
@@ -123,17 +135,37 @@ void zone_to_name_proc (void *cls, | |||
123 | const struct GNUNET_NAMESTORE_RecordData *rd, | 135 | const struct GNUNET_NAMESTORE_RecordData *rd, |
124 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 136 | const struct GNUNET_CRYPTO_RsaSignature *signature) |
125 | { | 137 | { |
126 | if ((zone_key == NULL) && (n == NULL) && (rd_count == 0) && (rd == NULL) && (signature == NULL)) | 138 | int fail = GNUNET_NO; |
139 | |||
140 | if ((zone_key == NULL) && (n == NULL) && (rd_count == 0) && (rd == NULL) && (signature == NULL)) | ||
141 | { | ||
142 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No result found\n"); | ||
143 | res = 1; | ||
144 | } | ||
145 | else | ||
146 | { | ||
147 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result found: `%s'\n", n); | ||
148 | if (0 != strcmp(n, s_name)) | ||
127 | { | 149 | { |
128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No result found\n"); | 150 | fail = GNUNET_YES; |
129 | res = 0; | 151 | GNUNET_break (0); |
130 | } | 152 | } |
131 | else | 153 | if (rd_count != 1) |
132 | { | 154 | { |
133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result found\n"); | 155 | fail = GNUNET_YES; |
134 | res = 0; | 156 | GNUNET_break (0); |
135 | } | 157 | } |
136 | GNUNET_SCHEDULER_add_now(&end, NULL); | 158 | if (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) |
159 | { | ||
160 | fail = GNUNET_YES; | ||
161 | GNUNET_break (0); | ||
162 | } | ||
163 | if (fail == GNUNET_NO) | ||
164 | res = 0; | ||
165 | else | ||
166 | res = 1; | ||
167 | } | ||
168 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
137 | } | 169 | } |
138 | 170 | ||
139 | 171 | ||
@@ -155,6 +187,28 @@ delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
155 | 187 | ||
156 | } | 188 | } |
157 | 189 | ||
190 | |||
191 | void | ||
192 | put_cont (void *cls, int32_t success, const char *emsg) | ||
193 | { | ||
194 | char *name = cls; | ||
195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | ||
196 | if (success == GNUNET_OK) | ||
197 | { | ||
198 | res = 0; | ||
199 | |||
200 | /* create initial record */ | ||
201 | GNUNET_NAMESTORE_zone_to_name (nsh, &s_zone, &s_zone_value, zone_to_name_proc, NULL); | ||
202 | |||
203 | } | ||
204 | else | ||
205 | { | ||
206 | res = 1; | ||
207 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to put records for name `%s'\n", name); | ||
208 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
209 | } | ||
210 | } | ||
211 | |||
158 | static void | 212 | static void |
159 | run (void *cls, char *const *args, const char *cfgfile, | 213 | run (void *cls, char *const *args, const char *cfgfile, |
160 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 214 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
@@ -162,6 +216,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
162 | delete_existing_db(cfg); | 216 | delete_existing_db(cfg); |
163 | 217 | ||
164 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); | 218 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); |
219 | GNUNET_asprintf(&s_name, "dummy.dummy.gnunet"); | ||
220 | |||
165 | 221 | ||
166 | /* load privat key */ | 222 | /* load privat key */ |
167 | privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey"); | 223 | privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey"); |
@@ -171,7 +227,14 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
171 | 227 | ||
172 | /* zone hash */ | 228 | /* zone hash */ |
173 | GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); | 229 | GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); |
174 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &s_zone_value); | 230 | GNUNET_CRYPTO_hash (s_name, strlen (s_name) + 1, &s_zone_value); |
231 | |||
232 | struct GNUNET_NAMESTORE_RecordData rd; | ||
233 | rd.expiration = GNUNET_TIME_absolute_get(); | ||
234 | rd.record_type = GNUNET_NAMESTORE_TYPE_PKEY; | ||
235 | rd.data_size = sizeof (GNUNET_HashCode); | ||
236 | rd.data = GNUNET_malloc(sizeof (GNUNET_HashCode)); | ||
237 | memcpy ((char *) rd.data, &s_zone_value, sizeof (GNUNET_HashCode)); | ||
175 | 238 | ||
176 | start_arm (cfgfile); | 239 | start_arm (cfgfile); |
177 | GNUNET_assert (arm != NULL); | 240 | GNUNET_assert (arm != NULL); |
@@ -179,8 +242,11 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
179 | nsh = GNUNET_NAMESTORE_connect (cfg); | 242 | nsh = GNUNET_NAMESTORE_connect (cfg); |
180 | GNUNET_break (NULL != nsh); | 243 | GNUNET_break (NULL != nsh); |
181 | 244 | ||
182 | /* create initial record */ | 245 | expire = GNUNET_TIME_absolute_get (); |
183 | GNUNET_NAMESTORE_zone_to_name (nsh, &s_zone, &s_zone_value, zone_to_name_proc, NULL); | 246 | s_signature = GNUNET_NAMESTORE_create_signature(privkey, s_name, &rd, 1); |
247 | GNUNET_NAMESTORE_record_put(nsh, &pubkey, s_name, expire, 1, &rd, s_signature, put_cont, NULL); | ||
248 | |||
249 | GNUNET_free ((void *) rd.data); | ||
184 | } | 250 | } |
185 | 251 | ||
186 | static int | 252 | static int |