aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_zone_to_name.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-01-20 22:07:10 +0100
committerChristian Grothoff <christian@grothoff.org>2018-01-20 22:07:10 +0100
commit2dee812c480c79a04ada98bb127cba513735c4e2 (patch)
tree5c166d5f9ae26294ad529802a09d68a16e9d0e87 /src/namestore/test_namestore_api_zone_to_name.c
parent923ed39493191b830e8f01b77042e4303e21ccd3 (diff)
downloadgnunet-2dee812c480c79a04ada98bb127cba513735c4e2.tar.gz
gnunet-2dee812c480c79a04ada98bb127cba513735c4e2.zip
reactivate test, fix misc warnings
Diffstat (limited to 'src/namestore/test_namestore_api_zone_to_name.c')
-rw-r--r--src/namestore/test_namestore_api_zone_to_name.c212
1 files changed, 132 insertions, 80 deletions
diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c
index ca33ee280..2bc7d34a3 100644
--- a/src/namestore/test_namestore_api_zone_to_name.c
+++ b/src/namestore/test_namestore_api_zone_to_name.c
@@ -37,28 +37,25 @@
37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
38 38
39 39
40static struct GNUNET_NAMESTORE_Handle * nsh; 40static struct GNUNET_NAMESTORE_Handle *nsh;
41 41
42static struct GNUNET_SCHEDULER_Task * endbadly_task; 42static struct GNUNET_SCHEDULER_Task *endbadly_task;
43 43
44static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey; 44static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
45 45
46static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; 46static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
47 47
48static struct GNUNET_TIME_Absolute expire; 48static struct GNUNET_CRYPTO_EcdsaPublicKey s_zone_value;
49
50static struct GNUNET_CRYPTO_ShortHashCode s_zone;
51
52static struct GNUNET_CRYPTO_ShortHashCode s_zone_value;
53 49
54static char * s_name; 50static char * s_name;
55 51
56static struct GNUNET_CRYPTO_EcdsaSignature *s_signature;
57
58static int res; 52static int res;
59 53
60static char *directory; 54static char *directory;
61 55
56static struct GNUNET_NAMESTORE_QueueEntry *qe;
57
58
62/** 59/**
63 * Re-establish the connection to the service. 60 * Re-establish the connection to the service.
64 * 61 *
@@ -67,12 +64,8 @@ static char *directory;
67static void 64static void
68endbadly (void *cls) 65endbadly (void *cls)
69{ 66{
70 if (nsh != NULL) 67 (void) cls;
71 GNUNET_NAMESTORE_disconnect (nsh); 68 GNUNET_SCHEDULER_shutdown ();
72 nsh = NULL;
73 if (privkey != NULL)
74 GNUNET_free (privkey);
75 privkey = NULL;
76 res = 1; 69 res = 1;
77} 70}
78 71
@@ -80,50 +73,69 @@ endbadly (void *cls)
80static void 73static void
81end (void *cls) 74end (void *cls)
82{ 75{
83 if (endbadly_task != NULL) 76 if (NULL != qe)
77 {
78 GNUNET_NAMESTORE_cancel (qe);
79 qe = NULL;
80 }
81 if (NULL != endbadly_task)
84 { 82 {
85 GNUNET_SCHEDULER_cancel (endbadly_task); 83 GNUNET_SCHEDULER_cancel (endbadly_task);
86 endbadly_task = NULL; 84 endbadly_task = NULL;
87 } 85 }
88 if (privkey != NULL) 86 if (NULL != privkey)
87 {
89 GNUNET_free (privkey); 88 GNUNET_free (privkey);
90 privkey = NULL; 89 privkey = NULL;
91 if (nsh != NULL) 90 }
91 if (NULL != nsh)
92 {
92 GNUNET_NAMESTORE_disconnect (nsh); 93 GNUNET_NAMESTORE_disconnect (nsh);
93 nsh = NULL; 94 nsh = NULL;
95 }
94} 96}
95 97
96 98
97static void 99static void
98zone_to_name_proc (void *cls, 100zone_to_name_proc (void *cls,
99 const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, 101 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
100 struct GNUNET_TIME_Absolute expire,
101 const char *n, 102 const char *n,
102 unsigned int rd_count, 103 unsigned int rd_count,
103 const struct GNUNET_GNSRECORD_Data *rd, 104 const struct GNUNET_GNSRECORD_Data *rd)
104 const struct GNUNET_CRYPTO_EcdsaSignature *signature)
105{ 105{
106 int fail = GNUNET_NO; 106 int fail = GNUNET_NO;
107 107
108 if ((zone_key == NULL) && (n == NULL) && (rd_count == 0) && (rd == NULL) && (signature == NULL)) 108 qe = NULL;
109 if ( (NULL == zone_key) &&
110 (NULL == n) &&
111 (0 == rd_count) &&
112 (NULL == rd) )
109 { 113 {
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No result found\n"); 114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
115 "No result found\n");
111 res = 1; 116 res = 1;
112 } 117 }
113 else 118 else
114 { 119 {
115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result found: `%s'\n", n); 120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
116 if ((n == NULL) || (0 != strcmp(n, s_name))) 121 "Result found: `%s'\n",
122 n);
123 if ( (NULL == n) ||
124 (0 != strcmp (n,
125 s_name)))
117 { 126 {
118 fail = GNUNET_YES; 127 fail = GNUNET_YES;
119 GNUNET_break (0); 128 GNUNET_break (0);
120 } 129 }
121 if (rd_count != 1) 130 if (1 != rd_count)
122 { 131 {
123 fail = GNUNET_YES; 132 fail = GNUNET_YES;
124 GNUNET_break (0); 133 GNUNET_break (0);
125 } 134 }
126 if ((zone_key == NULL) || (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))) 135 if ( (NULL == zone_key) ||
136 (0 != memcmp (zone_key,
137 privkey,
138 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))))
127 { 139 {
128 fail = GNUNET_YES; 140 fail = GNUNET_YES;
129 GNUNET_break (0); 141 GNUNET_break (0);
@@ -133,29 +145,54 @@ zone_to_name_proc (void *cls,
133 else 145 else
134 res = 1; 146 res = 1;
135 } 147 }
136 GNUNET_SCHEDULER_add_now(&end, NULL); 148 GNUNET_SCHEDULER_add_now (&end,
149 NULL);
137} 150}
138 151
139 152
140static void 153static void
141put_cont (void *cls, int32_t success, const char *emsg) 154error_cb (void *cls)
155{
156 (void) cls;
157 qe = NULL;
158 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
159 "Not found!\n");
160 GNUNET_SCHEDULER_shutdown ();
161 res = 2;
162}
163
164
165static void
166put_cont (void *cls,
167 int32_t success,
168 const char *emsg)
142{ 169{
143 char *name = cls; 170 char *name = cls;
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 171
172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
173 "Name store added record for `%s': %s\n",
174 name,
175 (success == GNUNET_OK) ? "SUCCESS" : emsg);
145 if (success == GNUNET_OK) 176 if (success == GNUNET_OK)
146 { 177 {
147 res = 0; 178 res = 0;
148 179
149 /* create initial record */ 180 qe = GNUNET_NAMESTORE_zone_to_name (nsh,
150 GNUNET_NAMESTORE_zone_to_name (nsh, &s_zone, &s_zone_value, zone_to_name_proc, NULL); 181 privkey,
151 182 &s_zone_value,
183 &error_cb,
184 NULL,
185 &zone_to_name_proc,
186 NULL);
152 } 187 }
153 else 188 else
154 { 189 {
155 res = 1; 190 res = 1;
156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
157 "Failed to put records for name `%s'\n", name); 192 "Failed to put records for name `%s'\n",
158 GNUNET_SCHEDULER_add_now(&end, NULL); 193 name);
194 GNUNET_SCHEDULER_add_now (&end,
195 NULL);
159 } 196 }
160} 197}
161 198
@@ -165,57 +202,72 @@ run (void *cls,
165 const struct GNUNET_CONFIGURATION_Handle *cfg, 202 const struct GNUNET_CONFIGURATION_Handle *cfg,
166 struct GNUNET_TESTING_Peer *peer) 203 struct GNUNET_TESTING_Peer *peer)
167{ 204{
168 struct GNUNET_TIME_Absolute et; 205 (void) cls;
169 206 (void) peer;
170 directory = NULL; 207 directory = NULL;
171 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory); 208 GNUNET_assert (GNUNET_OK ==
209 GNUNET_CONFIGURATION_get_value_string (cfg,
210 "PATHS",
211 "GNUNET_TEST_HOME",
212 &directory));
172 GNUNET_DISK_directory_remove (directory); 213 GNUNET_DISK_directory_remove (directory);
173 214
174 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); 215 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
216 &endbadly,
217 NULL);
218 GNUNET_SCHEDULER_add_shutdown (&end,
219 NULL);
175 GNUNET_asprintf (&s_name, "dummy"); 220 GNUNET_asprintf (&s_name, "dummy");
176 /* load privat key */ 221 /* load privat key */
177 char *hostkey_file; 222 {
178 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 223 char *zonekey_file;
179 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); 224
180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 225 GNUNET_asprintf (&zonekey_file,
181 "Using zonekey file `%s'\n", 226 "zonefiles%s%s",
182 hostkey_file); 227 DIR_SEPARATOR_STR,
183 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 228 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
184 GNUNET_free (hostkey_file); 229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
185 GNUNET_assert (privkey != NULL); 230 "Using zonekey file `%s'\n",
231 zonekey_file);
232 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (zonekey_file);
233 GNUNET_free (zonekey_file);
234 }
235 GNUNET_assert (NULL != privkey);
186 /* get public key */ 236 /* get public key */
187 GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey); 237 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
238 &pubkey);
188 239
189 /* zone hash */ 240 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
190 GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), &s_zone); 241 &s_zone_value,
191 GNUNET_CRYPTO_short_hash (s_name, strlen (s_name) + 1, &s_zone_value); 242 sizeof (s_zone_value));
192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 243 {
193 "Using PKEY `%s' \n", 244 struct GNUNET_GNSRECORD_Data rd;
194 GNUNET_NAMESTORE_short_h2s (&s_zone_value)); 245
195 246 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us;
196 struct GNUNET_GNSRECORD_Data rd; 247 rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
197 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; 248 rd.data_size = sizeof (s_zone_value);
198 rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; 249 rd.data = &s_zone_value;
199 rd.data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode); 250 rd.flags = 0;
200 rd.data = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_ShortHashCode)); 251
201 rd.flags = 0; 252 nsh = GNUNET_NAMESTORE_connect (cfg);
202 GNUNET_memcpy ((char *) rd.data, &s_zone_value, sizeof (struct GNUNET_CRYPTO_ShortHashCode)); 253 GNUNET_break (NULL != nsh);
203 nsh = GNUNET_NAMESTORE_connect (cfg); 254 GNUNET_NAMESTORE_records_store (nsh,
204 GNUNET_break (NULL != nsh); 255 privkey,
205 256 s_name,
206 expire = GNUNET_TIME_absolute_get (); 257 1,
207 et.abs_value_us = rd.expiration_time; 258 &rd,
208 s_signature = GNUNET_NAMESTORE_create_signature(privkey, et, s_name, &rd, 1); 259 &put_cont,
209 GNUNET_NAMESTORE_record_put(nsh, &pubkey, s_name, expire, 1, &rd, s_signature, put_cont, NULL); 260 NULL);
210 261 }
211 GNUNET_free ((void *) rd.data);
212} 262}
213 263
214 264
215
216int 265int
217main (int argc, char *argv[]) 266main (int argc,
267 char *argv[])
218{ 268{
269 (void) argc;
270 (void) argv;
219 res = 1; 271 res = 1;
220 if (0 != 272 if (0 !=
221 GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name", 273 GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name",
@@ -227,8 +279,8 @@ main (int argc, char *argv[])
227 } 279 }
228 if (NULL != directory) 280 if (NULL != directory)
229 { 281 {
230 GNUNET_DISK_directory_remove (directory); 282 GNUNET_DISK_directory_remove (directory);
231 GNUNET_free (directory); 283 GNUNET_free (directory);
232 } 284 }
233 return res; 285 return res;
234} 286}