diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-09-29 17:38:25 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-09-29 17:38:25 +0000 |
commit | 212d423a7b173c8f8df8638dc73c794f2ee1ffde (patch) | |
tree | 984e9647d796b78ddb043587f415420f1f7d6c27 /src/gns/gnunet-service-gns.c | |
parent | 4ec371603a6dff2053daf6f839060c725d6c8d49 (diff) | |
download | gnunet-212d423a7b173c8f8df8638dc73c794f2ee1ffde.tar.gz gnunet-212d423a7b173c8f8df8638dc73c794f2ee1ffde.zip |
-doxy
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r-- | src/gns/gnunet-service-gns.c | 382 |
1 files changed, 216 insertions, 166 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 5ad0bcf76..c5c5ac2bf 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -40,9 +40,27 @@ | |||
40 | #include "gnunet-service-gns_interceptor.h" | 40 | #include "gnunet-service-gns_interceptor.h" |
41 | #include "gnunet_protocols.h" | 41 | #include "gnunet_protocols.h" |
42 | 42 | ||
43 | #define INITIAL_ZONE_ITERATION_INTERVAL GNUNET_TIME_UNIT_MILLISECONDS | 43 | /** |
44 | * The initial interval in milliseconds btween puts in | ||
45 | * a zone iteration | ||
46 | */ | ||
47 | #define INITIAL_PUT_INTERVAL GNUNET_TIME_UNIT_MILLISECONDS | ||
48 | |||
49 | /** | ||
50 | * The upper bound for the zone iteration interval in milliseconds | ||
51 | */ | ||
44 | #define MINIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_UNIT_SECONDS | 52 | #define MINIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_UNIT_SECONDS |
45 | #define DEFAULT_RECORD_PUT_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) | 53 | |
54 | /** | ||
55 | * The default put interval for the zone iteration. In case | ||
56 | * No option is found | ||
57 | */ | ||
58 | #define DEFAULT_ZONE_PUBLISH_TIME_WINDOW GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) | ||
59 | |||
60 | /** | ||
61 | * The factor the current zone iteration interval is divided by for each | ||
62 | * additional new record | ||
63 | */ | ||
46 | #define LATE_ITERATION_SPEEDUP_FACTOR 2 | 64 | #define LATE_ITERATION_SPEEDUP_FACTOR 2 |
47 | 65 | ||
48 | 66 | ||
@@ -52,59 +70,85 @@ | |||
52 | struct ClientShortenHandle | 70 | struct ClientShortenHandle |
53 | { | 71 | { |
54 | 72 | ||
55 | /* DLL */ | 73 | /** |
74 | * List for all shorten requests | ||
75 | */ | ||
56 | struct ClientShortenHandle *next; | 76 | struct ClientShortenHandle *next; |
57 | 77 | /** | |
58 | /* DLL */ | 78 | * List for all shorten requests |
79 | */ | ||
59 | struct ClientShortenHandle *prev; | 80 | struct ClientShortenHandle *prev; |
60 | 81 | ||
61 | /* the requesting client that */ | 82 | /** |
83 | * Handle to the requesting client | ||
84 | */ | ||
62 | struct GNUNET_SERVER_Client *client; | 85 | struct GNUNET_SERVER_Client *client; |
63 | 86 | ||
64 | /* request id */ | 87 | /** |
65 | uint64_t unique_id; | 88 | * The request id |
89 | */ | ||
90 | uint64_t request_id; | ||
66 | 91 | ||
67 | /* request type */ | 92 | /** |
93 | * request type | ||
94 | */ | ||
68 | enum GNUNET_GNS_RecordType type; | 95 | enum GNUNET_GNS_RecordType type; |
69 | 96 | ||
70 | /* name to shorten */ | 97 | /** |
98 | * name to shorten | ||
99 | */ | ||
71 | char name[MAX_DNS_NAME_LENGTH]; | 100 | char name[MAX_DNS_NAME_LENGTH]; |
72 | 101 | ||
73 | /* name of private zone (relative to root) */ | 102 | /** |
103 | * name of private zone (relative to root) | ||
104 | */ | ||
74 | char private_zone_id[MAX_DNS_NAME_LENGTH]; | 105 | char private_zone_id[MAX_DNS_NAME_LENGTH]; |
75 | 106 | ||
76 | /* name of shorten zone (relative to root) */ | 107 | /** |
108 | * name of shorten zone (relative to root) | ||
109 | */ | ||
77 | char shorten_zone_id[MAX_DNS_NAME_LENGTH]; | 110 | char shorten_zone_id[MAX_DNS_NAME_LENGTH]; |
78 | 111 | ||
79 | /* root zone */ | 112 | /** |
113 | * master zone | ||
114 | */ | ||
80 | struct GNUNET_CRYPTO_ShortHashCode root_zone; | 115 | struct GNUNET_CRYPTO_ShortHashCode root_zone; |
81 | 116 | ||
82 | /* private zone */ | 117 | /** |
118 | * private zone | ||
119 | */ | ||
83 | struct GNUNET_CRYPTO_ShortHashCode private_zone; | 120 | struct GNUNET_CRYPTO_ShortHashCode private_zone; |
84 | 121 | ||
85 | /* shorten zone */ | 122 | /** |
123 | * shorten zone | ||
124 | */ | ||
86 | struct GNUNET_CRYPTO_ShortHashCode shorten_zone; | 125 | struct GNUNET_CRYPTO_ShortHashCode shorten_zone; |
87 | 126 | ||
88 | /* Namestore lookup task */ | 127 | /** |
128 | * Namestore lookup task | ||
129 | */ | ||
89 | struct GNUNET_NAMESTORE_QueueEntry *namestore_task; | 130 | struct GNUNET_NAMESTORE_QueueEntry *namestore_task; |
90 | |||
91 | }; | 131 | }; |
92 | 132 | ||
93 | 133 | ||
94 | /** | 134 | /** |
95 | * Handle to a get auhtority operation from api | 135 | * Handle to a get authority operation from api |
96 | */ | 136 | */ |
97 | struct ClientGetAuthHandle | 137 | struct ClientGetAuthHandle |
98 | { | 138 | { |
99 | /* the requesting client that */ | 139 | /** |
140 | * Handle to the requesting client */ | ||
100 | struct GNUNET_SERVER_Client *client; | 141 | struct GNUNET_SERVER_Client *client; |
101 | 142 | ||
102 | /* request id */ | 143 | /** |
103 | uint64_t unique_id; | 144 | * request id |
145 | */ | ||
146 | uint64_t request_id; | ||
104 | 147 | ||
105 | /* name to lookup authority */ | 148 | /** |
149 | * name to lookup authority | ||
150 | */ | ||
106 | char *name; | 151 | char *name; |
107 | |||
108 | }; | 152 | }; |
109 | 153 | ||
110 | 154 | ||
@@ -114,25 +158,39 @@ struct ClientGetAuthHandle | |||
114 | struct ClientLookupHandle | 158 | struct ClientLookupHandle |
115 | { | 159 | { |
116 | 160 | ||
117 | /* the requesting client that */ | 161 | /** |
162 | * Handle to the requesting client | ||
163 | */ | ||
118 | struct GNUNET_SERVER_Client *client; | 164 | struct GNUNET_SERVER_Client *client; |
119 | 165 | ||
120 | /* The zone we look up in */ | 166 | /** |
167 | * The zone we look up in | ||
168 | */ | ||
121 | struct GNUNET_CRYPTO_ShortHashCode zone; | 169 | struct GNUNET_CRYPTO_ShortHashCode zone; |
122 | 170 | ||
123 | /* Do we only want to lookup from local cache? */ | 171 | /** |
172 | * GNUNET_YES if we only want to lookup from local cache | ||
173 | */ | ||
124 | int only_cached; | 174 | int only_cached; |
125 | 175 | ||
126 | /* request id */ | 176 | /** |
127 | uint64_t unique_id; | 177 | * request id |
178 | */ | ||
179 | uint64_t request_id; | ||
128 | 180 | ||
129 | /* request type */ | 181 | /** |
182 | * request type | ||
183 | */ | ||
130 | enum GNUNET_GNS_RecordType type; | 184 | enum GNUNET_GNS_RecordType type; |
131 | 185 | ||
132 | /* optional zone private key used for shorten */ | 186 | /** |
187 | * optional zone private key used for shorten | ||
188 | */ | ||
133 | struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key; | 189 | struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key; |
134 | 190 | ||
135 | /* the name to look up */ | 191 | /** |
192 | * the name to look up | ||
193 | */ | ||
136 | char *name; | 194 | char *name; |
137 | }; | 195 | }; |
138 | 196 | ||
@@ -149,7 +207,6 @@ static struct GNUNET_CRYPTO_RsaPrivateKey *zone_key; | |||
149 | 207 | ||
150 | /** | 208 | /** |
151 | * Our handle to the namestore service | 209 | * Our handle to the namestore service |
152 | * FIXME maybe need a second handle for iteration | ||
153 | */ | 210 | */ |
154 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | 211 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; |
155 | 212 | ||
@@ -179,38 +236,59 @@ static unsigned long long num_public_records; | |||
179 | static unsigned long long last_num_public_records; | 236 | static unsigned long long last_num_public_records; |
180 | 237 | ||
181 | /** | 238 | /** |
182 | * FIXME! | 239 | * Zone iteration PUT interval. |
183 | */ | 240 | */ |
184 | static struct GNUNET_TIME_Relative zone_iteration_interval; | 241 | static struct GNUNET_TIME_Relative put_interval; |
185 | 242 | ||
186 | /* dht update interval FIXME define? */ | 243 | /** |
187 | static struct GNUNET_TIME_Relative record_put_interval; | 244 | * Time window for zone iteration |
245 | */ | ||
246 | static struct GNUNET_TIME_Relative zone_publish_time_window; | ||
188 | 247 | ||
189 | /* zone update task */ | 248 | /** |
190 | static GNUNET_SCHEDULER_TaskIdentifier zone_update_taskid; | 249 | * zone publish task |
250 | */ | ||
251 | static GNUNET_SCHEDULER_TaskIdentifier zone_publish_task; | ||
191 | 252 | ||
192 | /* automatic pkey import for name shortening */ | 253 | /** |
254 | * GNUNET_YES if automatic pkey import for name shortening | ||
255 | * is enabled | ||
256 | */ | ||
193 | static int auto_import_pkey; | 257 | static int auto_import_pkey; |
194 | 258 | ||
195 | /* first zone iteration is specia */ | 259 | /** |
260 | * GNUNET_YES if zone has never been published before | ||
261 | */ | ||
196 | static int first_zone_iteration; | 262 | static int first_zone_iteration; |
197 | 263 | ||
198 | /* lookup timeout */ | 264 | /** |
265 | * The lookup timeout | ||
266 | */ | ||
199 | static struct GNUNET_TIME_Relative default_lookup_timeout; | 267 | static struct GNUNET_TIME_Relative default_lookup_timeout; |
200 | 268 | ||
201 | /* ipv6 support */ | 269 | /** |
270 | * GNUNET_YES if ipv6 is supported | ||
271 | */ | ||
202 | static int v6_enabled; | 272 | static int v6_enabled; |
203 | 273 | ||
204 | /* ipv4 support */ | 274 | /** |
275 | * GNUNET_YES if ipv4 is supported | ||
276 | */ | ||
205 | static int v4_enabled; | 277 | static int v4_enabled; |
206 | 278 | ||
207 | /* Shorten DLL for cancelling NS requests */ | 279 | /** |
280 | * List for shorten requests | ||
281 | */ | ||
208 | static struct ClientShortenHandle *csh_head; | 282 | static struct ClientShortenHandle *csh_head; |
209 | 283 | ||
210 | /* Shorten DLL for cancelling NS requests */ | 284 | /** |
285 | * List for shorten requests | ||
286 | */ | ||
211 | static struct ClientShortenHandle *csh_tail; | 287 | static struct ClientShortenHandle *csh_tail; |
212 | 288 | ||
213 | /* Statistics handle */ | 289 | /** |
290 | * Handle to the statistics service | ||
291 | */ | ||
214 | static struct GNUNET_STATISTICS_Handle *statistics; | 292 | static struct GNUNET_STATISTICS_Handle *statistics; |
215 | 293 | ||
216 | 294 | ||
@@ -237,8 +315,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
237 | gns_resolver_cleanup (); | 315 | gns_resolver_cleanup (); |
238 | if (NULL != statistics) | 316 | if (NULL != statistics) |
239 | GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); | 317 | GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); |
240 | if (zone_update_taskid != GNUNET_SCHEDULER_NO_TASK) | 318 | if (zone_publish_task != GNUNET_SCHEDULER_NO_TASK) |
241 | GNUNET_SCHEDULER_cancel (zone_update_taskid); | 319 | GNUNET_SCHEDULER_cancel (zone_publish_task); |
242 | if (NULL != namestore_iter) | 320 | if (NULL != namestore_iter) |
243 | GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter); | 321 | GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter); |
244 | GNUNET_NAMESTORE_disconnect(namestore_handle); | 322 | GNUNET_NAMESTORE_disconnect(namestore_handle); |
@@ -253,33 +331,23 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
253 | * @param tc task context | 331 | * @param tc task context |
254 | */ | 332 | */ |
255 | static void | 333 | static void |
256 | update_zone_dht_next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 334 | publish_zone_dht_next (void *cls, |
335 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
257 | { | 336 | { |
258 | zone_update_taskid = GNUNET_SCHEDULER_NO_TASK; | 337 | zone_publish_task = GNUNET_SCHEDULER_NO_TASK; |
259 | GNUNET_NAMESTORE_zone_iterator_next (namestore_iter); | 338 | GNUNET_NAMESTORE_zone_iterator_next (namestore_iter); |
260 | } | 339 | } |
261 | 340 | ||
262 | 341 | ||
263 | /** | 342 | /** |
264 | * Continuation for DHT put | 343 | * Periodically iterate over our zone and store everything in dht |
265 | * | 344 | * |
266 | * @param cls closure | 345 | * @param cls NULL |
267 | * @param success GNUNET_OK if the PUT was transmitted, | 346 | * @param tc task context |
268 | * GNUNET_NO on timeout, | ||
269 | * GNUNET_SYSERR on disconnect from service | ||
270 | * after the PUT message was transmitted | ||
271 | * (so we don't know if it was received or not) | ||
272 | */ | 347 | */ |
273 | static void | 348 | static void |
274 | record_dht_put(void *cls, int success) | 349 | publish_zone_dht_start (void *cls, |
275 | { | 350 | const struct GNUNET_SCHEDULER_TaskContext *tc); |
276 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "put request transmitted\n"); | ||
277 | } | ||
278 | |||
279 | |||
280 | /* prototype */ | ||
281 | static void | ||
282 | update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
283 | 351 | ||
284 | 352 | ||
285 | /** | 353 | /** |
@@ -323,7 +391,7 @@ put_gns_record(void *cls, | |||
323 | * we can safely set the interval to the value for a single | 391 | * we can safely set the interval to the value for a single |
324 | * record | 392 | * record |
325 | */ | 393 | */ |
326 | zone_iteration_interval = GNUNET_TIME_relative_divide (record_put_interval, | 394 | put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window, |
327 | 1); | 395 | 1); |
328 | 396 | ||
329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 397 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
@@ -331,18 +399,18 @@ put_gns_record(void *cls, | |||
331 | } | 399 | } |
332 | else | 400 | else |
333 | { | 401 | { |
334 | zone_iteration_interval = GNUNET_TIME_relative_divide (record_put_interval, | 402 | put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window, |
335 | num_public_records); | 403 | num_public_records); |
336 | } | 404 | } |
337 | zone_iteration_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL, | 405 | put_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL, |
338 | zone_iteration_interval); | 406 | put_interval); |
339 | 407 | ||
340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 408 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
341 | "Zone iteration finished. Adjusted zone iteration interval to %s\n", | 409 | "Zone iteration finished. Adjusted zone iteration interval to %s\n", |
342 | GNUNET_STRINGS_relative_time_to_string (zone_iteration_interval, GNUNET_YES)); | 410 | GNUNET_STRINGS_relative_time_to_string (put_interval, GNUNET_YES)); |
343 | GNUNET_STATISTICS_set (statistics, | 411 | GNUNET_STATISTICS_set (statistics, |
344 | "Current zone iteration interval (in ms)", | 412 | "Current zone iteration interval (in ms)", |
345 | zone_iteration_interval.rel_value, | 413 | put_interval.rel_value, |
346 | GNUNET_NO); | 414 | GNUNET_NO); |
347 | GNUNET_STATISTICS_update (statistics, | 415 | GNUNET_STATISTICS_update (statistics, |
348 | "Number of zone iterations", 1, GNUNET_NO); | 416 | "Number of zone iterations", 1, GNUNET_NO); |
@@ -351,11 +419,11 @@ put_gns_record(void *cls, | |||
351 | last_num_public_records, | 419 | last_num_public_records, |
352 | GNUNET_NO); | 420 | GNUNET_NO); |
353 | if (0 == num_public_records) | 421 | if (0 == num_public_records) |
354 | zone_update_taskid = GNUNET_SCHEDULER_add_delayed (zone_iteration_interval, | 422 | zone_publish_task = GNUNET_SCHEDULER_add_delayed (put_interval, |
355 | &update_zone_dht_start, | 423 | &publish_zone_dht_start, |
356 | NULL); | 424 | NULL); |
357 | else | 425 | else |
358 | zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_start, NULL); | 426 | zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, NULL); |
359 | return; | 427 | return; |
360 | } | 428 | } |
361 | 429 | ||
@@ -365,14 +433,14 @@ put_gns_record(void *cls, | |||
365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
366 | "No records for name `%s'! Skipping.\n", | 434 | "No records for name `%s'! Skipping.\n", |
367 | name); | 435 | name); |
368 | zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next, | 436 | zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_next, |
369 | NULL); | 437 | NULL); |
370 | return; | 438 | return; |
371 | } | 439 | } |
372 | if (NULL == signature) | 440 | if (NULL == signature) |
373 | { | 441 | { |
374 | GNUNET_break (0); | 442 | GNUNET_break (0); |
375 | zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next, | 443 | zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_next, |
376 | NULL); | 444 | NULL); |
377 | return; | 445 | return; |
378 | } | 446 | } |
@@ -401,8 +469,8 @@ put_gns_record(void *cls, | |||
401 | _("Records for name `%s' in zone %s too large to fit into DHT"), | 469 | _("Records for name `%s' in zone %s too large to fit into DHT"), |
402 | name, | 470 | name, |
403 | GNUNET_short_h2s (&zhash)); | 471 | GNUNET_short_h2s (&zhash)); |
404 | GNUNET_free(nrb); | 472 | GNUNET_free (nrb); |
405 | zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_next, | 473 | zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_next, |
406 | NULL); | 474 | NULL); |
407 | return; | 475 | return; |
408 | } | 476 | } |
@@ -428,7 +496,7 @@ put_gns_record(void *cls, | |||
428 | (char*)nrb, | 496 | (char*)nrb, |
429 | expiration, | 497 | expiration, |
430 | DHT_OPERATION_TIMEOUT, | 498 | DHT_OPERATION_TIMEOUT, |
431 | &record_dht_put, | 499 | NULL, |
432 | NULL); | 500 | NULL); |
433 | GNUNET_free (nrb); | 501 | GNUNET_free (nrb); |
434 | 502 | ||
@@ -438,20 +506,20 @@ put_gns_record(void *cls, | |||
438 | { | 506 | { |
439 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 507 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
440 | "Last record count was lower than current record count. Reducing interval.\n"); | 508 | "Last record count was lower than current record count. Reducing interval.\n"); |
441 | zone_iteration_interval = GNUNET_TIME_relative_divide (record_put_interval, | 509 | put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window, |
442 | num_public_records); | 510 | num_public_records); |
443 | next_put_interval = GNUNET_TIME_relative_divide (zone_iteration_interval, | 511 | next_put_interval = GNUNET_TIME_relative_divide (put_interval, |
444 | LATE_ITERATION_SPEEDUP_FACTOR); | 512 | LATE_ITERATION_SPEEDUP_FACTOR); |
445 | } | 513 | } |
446 | else | 514 | else |
447 | next_put_interval = zone_iteration_interval; | 515 | next_put_interval = put_interval; |
448 | 516 | ||
449 | GNUNET_STATISTICS_set (statistics, | 517 | GNUNET_STATISTICS_set (statistics, |
450 | "Current zone iteration interval (ms)", | 518 | "Current zone iteration interval (ms)", |
451 | next_put_interval.rel_value, | 519 | next_put_interval.rel_value, |
452 | GNUNET_NO); | 520 | GNUNET_NO); |
453 | zone_update_taskid = GNUNET_SCHEDULER_add_delayed (next_put_interval, | 521 | zone_publish_task = GNUNET_SCHEDULER_add_delayed (next_put_interval, |
454 | &update_zone_dht_next, | 522 | &publish_zone_dht_next, |
455 | NULL); | 523 | NULL); |
456 | } | 524 | } |
457 | 525 | ||
@@ -463,9 +531,9 @@ put_gns_record(void *cls, | |||
463 | * @param tc task context | 531 | * @param tc task context |
464 | */ | 532 | */ |
465 | static void | 533 | static void |
466 | update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 534 | publish_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
467 | { | 535 | { |
468 | zone_update_taskid = GNUNET_SCHEDULER_NO_TASK; | 536 | zone_publish_task = GNUNET_SCHEDULER_NO_TASK; |
469 | 537 | ||
470 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling DHT zone update!\n"); | 538 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling DHT zone update!\n"); |
471 | /* start counting again */ | 539 | /* start counting again */ |
@@ -507,7 +575,7 @@ send_shorten_response (void* cls, const char* name) | |||
507 | rmsg = GNUNET_malloc (sizeof (struct GNUNET_GNS_ClientShortenResultMessage) + | 575 | rmsg = GNUNET_malloc (sizeof (struct GNUNET_GNS_ClientShortenResultMessage) + |
508 | name_len); | 576 | name_len); |
509 | 577 | ||
510 | rmsg->id = csh->unique_id; | 578 | rmsg->id = csh->request_id; |
511 | rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT); | 579 | rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT); |
512 | rmsg->header.size = | 580 | rmsg->header.size = |
513 | htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) + | 581 | htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) + |
@@ -733,8 +801,6 @@ handle_shorten (void *cls, | |||
733 | struct GNUNET_SERVER_Client * client, | 801 | struct GNUNET_SERVER_Client * client, |
734 | const struct GNUNET_MessageHeader * message) | 802 | const struct GNUNET_MessageHeader * message) |
735 | { | 803 | { |
736 | uint16_t msg_size; | ||
737 | const struct GNUNET_GNS_ClientShortenMessage *sh_msg; | ||
738 | struct ClientShortenHandle *csh; | 804 | struct ClientShortenHandle *csh; |
739 | const char *utf_in; | 805 | const char *utf_in; |
740 | char name[MAX_DNS_NAME_LENGTH]; | 806 | char name[MAX_DNS_NAME_LENGTH]; |
@@ -748,17 +814,14 @@ handle_shorten (void *cls, | |||
748 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 814 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
749 | return; | 815 | return; |
750 | } | 816 | } |
751 | sh_msg = (const struct GNUNET_GNS_ClientShortenMessage *) message; | 817 | |
752 | utf_in = (const char *) &sh_msg[1]; | 818 | |
753 | if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientShortenMessage) - 1]) | 819 | const struct GNUNET_GNS_ClientShortenMessage *sh_msg = |
754 | { | 820 | (const struct GNUNET_GNS_ClientShortenMessage *) message; |
755 | GNUNET_break (0); | 821 | |
756 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 822 | csh = GNUNET_malloc(sizeof (struct ClientShortenHandle)); |
757 | return; | ||
758 | } | ||
759 | csh = GNUNET_malloc (sizeof (struct ClientShortenHandle)); | ||
760 | csh->client = client; | 823 | csh->client = client; |
761 | csh->unique_id = sh_msg->id; | 824 | csh->request_id = sh_msg->id; |
762 | GNUNET_CONTAINER_DLL_insert (csh_head, csh_tail, csh); | 825 | GNUNET_CONTAINER_DLL_insert (csh_head, csh_tail, csh); |
763 | GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr); | 826 | GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr); |
764 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 827 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
@@ -833,7 +896,7 @@ send_get_auth_response(void *cls, const char* name) | |||
833 | rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) | 896 | rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) |
834 | + strlen(name) + 1); | 897 | + strlen(name) + 1); |
835 | 898 | ||
836 | rmsg->id = cah->unique_id; | 899 | rmsg->id = cah->request_id; |
837 | rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT); | 900 | rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT); |
838 | rmsg->header.size = | 901 | rmsg->header.size = |
839 | htons(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) + | 902 | htons(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) + |
@@ -863,8 +926,6 @@ handle_get_authority (void *cls, | |||
863 | struct GNUNET_SERVER_Client * client, | 926 | struct GNUNET_SERVER_Client * client, |
864 | const struct GNUNET_MessageHeader * message) | 927 | const struct GNUNET_MessageHeader * message) |
865 | { | 928 | { |
866 | uint16_t msg_size; | ||
867 | const struct GNUNET_GNS_ClientGetAuthMessage *sh_msg; | ||
868 | struct ClientGetAuthHandle *cah; | 929 | struct ClientGetAuthHandle *cah; |
869 | const char *utf_in; | 930 | const char *utf_in; |
870 | char name[MAX_DNS_NAME_LENGTH]; | 931 | char name[MAX_DNS_NAME_LENGTH]; |
@@ -880,18 +941,15 @@ handle_get_authority (void *cls, | |||
880 | } | 941 | } |
881 | GNUNET_SERVER_notification_context_add (nc, client); | 942 | GNUNET_SERVER_notification_context_add (nc, client); |
882 | 943 | ||
883 | sh_msg = (const struct GNUNET_GNS_ClientGetAuthMessage *) message; | 944 | struct GNUNET_GNS_ClientGetAuthMessage *sh_msg = |
884 | utf_in = (const char *) &sh_msg[1]; | 945 | (struct GNUNET_GNS_ClientGetAuthMessage *) message; |
885 | if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientGetAuthMessage) - 1]) | 946 | |
886 | { | 947 | GNUNET_STRINGS_utf8_tolower((const char*)&sh_msg[1], &nameptr); |
887 | GNUNET_break (0); | 948 | |
888 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 949 | |
889 | return; | ||
890 | } | ||
891 | GNUNET_STRINGS_utf8_tolower(utf_in, &nameptr); | ||
892 | cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle)); | 950 | cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle)); |
893 | cah->client = client; | 951 | cah->client = client; |
894 | cah->unique_id = sh_msg->id; | 952 | cah->request_id = sh_msg->id; |
895 | if (strlen (name) < strlen(GNUNET_GNS_TLD)) | 953 | if (strlen (name) < strlen(GNUNET_GNS_TLD)) |
896 | { | 954 | { |
897 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 955 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -925,17 +983,16 @@ handle_get_authority (void *cls, | |||
925 | cah->name = NULL; | 983 | cah->name = NULL; |
926 | send_get_auth_response(cah, name); | 984 | send_get_auth_response(cah, name); |
927 | return; | 985 | return; |
928 | } | 986 | } |
929 | cah->name = GNUNET_malloc(strlen (name) | 987 | |
988 | cah->name = GNUNET_malloc (strlen (name) | ||
930 | - strlen (GNUNET_GNS_TLD) + 1); | 989 | - strlen (GNUNET_GNS_TLD) + 1); |
931 | memset (cah->name, 0, | 990 | memcpy(cah->name, name, |
932 | strlen (name) - strlen (GNUNET_GNS_TLD) + 1); | 991 | strlen (name) - strlen (GNUNET_GNS_TLD)); |
933 | memcpy (cah->name, name, | ||
934 | strlen (name) - strlen(GNUNET_GNS_TLD)); | ||
935 | 992 | ||
936 | /* Start delegation resolution in our namestore */ | 993 | /* Start delegation resolution in our namestore */ |
937 | gns_resolver_get_authority(zone_hash, zone_hash, name, &send_get_auth_response, cah); | 994 | gns_resolver_get_authority (zone_hash, zone_hash, name, |
938 | 995 | &send_get_auth_response, cah); | |
939 | GNUNET_STATISTICS_update (statistics, | 996 | GNUNET_STATISTICS_update (statistics, |
940 | "Authority lookup attempts", 1, GNUNET_NO); | 997 | "Authority lookup attempts", 1, GNUNET_NO); |
941 | } | 998 | } |
@@ -954,7 +1011,7 @@ send_lookup_response(void* cls, | |||
954 | uint32_t rd_count, | 1011 | uint32_t rd_count, |
955 | const struct GNUNET_NAMESTORE_RecordData *rd) | 1012 | const struct GNUNET_NAMESTORE_RecordData *rd) |
956 | { | 1013 | { |
957 | struct ClientLookupHandle* clh = (struct ClientLookupHandle*)cls; | 1014 | struct ClientLookupHandle* clh = cls; |
958 | struct GNUNET_GNS_ClientLookupResultMessage *rmsg; | 1015 | struct GNUNET_GNS_ClientLookupResultMessage *rmsg; |
959 | size_t len; | 1016 | size_t len; |
960 | 1017 | ||
@@ -962,9 +1019,10 @@ send_lookup_response(void* cls, | |||
962 | "LOOKUP_RESULT", rd_count); | 1019 | "LOOKUP_RESULT", rd_count); |
963 | 1020 | ||
964 | len = GNUNET_NAMESTORE_records_get_size (rd_count, rd); | 1021 | len = GNUNET_NAMESTORE_records_get_size (rd_count, rd); |
965 | rmsg = GNUNET_malloc(len+sizeof(struct GNUNET_GNS_ClientLookupResultMessage)); | 1022 | rmsg = GNUNET_malloc ( |
1023 | len + sizeof (struct GNUNET_GNS_ClientLookupResultMessage)); | ||
966 | 1024 | ||
967 | rmsg->id = clh->unique_id; | 1025 | rmsg->id = clh->request_id; |
968 | rmsg->rd_count = htonl(rd_count); | 1026 | rmsg->rd_count = htonl(rd_count); |
969 | rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT); | 1027 | rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT); |
970 | rmsg->header.size = | 1028 | rmsg->header.size = |
@@ -982,18 +1040,13 @@ send_lookup_response(void* cls, | |||
982 | 1040 | ||
983 | if (NULL != clh->shorten_key) | 1041 | if (NULL != clh->shorten_key) |
984 | GNUNET_CRYPTO_rsa_key_free (clh->shorten_key); | 1042 | GNUNET_CRYPTO_rsa_key_free (clh->shorten_key); |
985 | |||
986 | GNUNET_free(clh); | 1043 | GNUNET_free(clh); |
987 | 1044 | ||
988 | GNUNET_STATISTICS_update (statistics, | 1045 | GNUNET_STATISTICS_update (statistics, |
989 | "Completed lookups", 1, GNUNET_NO); | 1046 | "Completed lookups", 1, GNUNET_NO); |
990 | |||
991 | if (rd != NULL) | 1047 | if (rd != NULL) |
992 | { | ||
993 | GNUNET_STATISTICS_update (statistics, | 1048 | GNUNET_STATISTICS_update (statistics, |
994 | "Records resolved", rd_count, GNUNET_NO); | 1049 | "Records resolved", rd_count, GNUNET_NO); |
995 | } | ||
996 | |||
997 | } | 1050 | } |
998 | 1051 | ||
999 | 1052 | ||
@@ -1009,8 +1062,6 @@ handle_lookup(void *cls, | |||
1009 | struct GNUNET_SERVER_Client * client, | 1062 | struct GNUNET_SERVER_Client * client, |
1010 | const struct GNUNET_MessageHeader * message) | 1063 | const struct GNUNET_MessageHeader * message) |
1011 | { | 1064 | { |
1012 | uint16_t msg_size; | ||
1013 | const struct GNUNET_GNS_ClientLookupMessage *sh_msg; | ||
1014 | size_t namelen; | 1065 | size_t namelen; |
1015 | char name[MAX_DNS_NAME_LENGTH]; | 1066 | char name[MAX_DNS_NAME_LENGTH]; |
1016 | struct ClientLookupHandle *clh; | 1067 | struct ClientLookupHandle *clh; |
@@ -1020,7 +1071,8 @@ handle_lookup(void *cls, | |||
1020 | struct GNUNET_CRYPTO_RsaPrivateKey *key; | 1071 | struct GNUNET_CRYPTO_RsaPrivateKey *key; |
1021 | struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey; | 1072 | struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey; |
1022 | char* tmp_pkey; | 1073 | char* tmp_pkey; |
1023 | 1074 | ||
1075 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP"); | ||
1024 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP"); | 1076 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP"); |
1025 | msg_size = ntohs(message->size); | 1077 | msg_size = ntohs(message->size); |
1026 | if (msg_size < sizeof (struct GNUNET_GNS_ClientLookupMessage)) | 1078 | if (msg_size < sizeof (struct GNUNET_GNS_ClientLookupMessage)) |
@@ -1031,42 +1083,40 @@ handle_lookup(void *cls, | |||
1031 | } | 1083 | } |
1032 | sh_msg = (const struct GNUNET_GNS_ClientLookupMessage *) message; | 1084 | sh_msg = (const struct GNUNET_GNS_ClientLookupMessage *) message; |
1033 | GNUNET_SERVER_notification_context_add (nc, client); | 1085 | GNUNET_SERVER_notification_context_add (nc, client); |
1086 | |||
1087 | struct GNUNET_GNS_ClientLookupMessage *sh_msg = | ||
1088 | (struct GNUNET_GNS_ClientLookupMessage *) message; | ||
1089 | |||
1034 | if (GNUNET_YES == ntohl (sh_msg->have_key)) | 1090 | if (GNUNET_YES == ntohl (sh_msg->have_key)) |
1035 | { | 1091 | { |
1036 | pkey = (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *)&sh_msg[1]; | 1092 | pkey = (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *) &sh_msg[1]; |
1037 | tmp_pkey = (char*)&sh_msg[1]; | 1093 | tmp_pkey = (char*) &sh_msg[1]; |
1038 | key = GNUNET_CRYPTO_rsa_decode_key (tmp_pkey, ntohs(pkey->len)); | 1094 | key = GNUNET_CRYPTO_rsa_decode_key (tmp_pkey, ntohs (pkey->len)); |
1039 | GNUNET_STRINGS_utf8_tolower(&tmp_pkey[ntohs(pkey->len)], &nameptr); | 1095 | GNUNET_STRINGS_utf8_tolower (&tmp_pkey[ntohs (pkey->len)], &nameptr); |
1040 | } | 1096 | } |
1041 | else | 1097 | else |
1042 | { | 1098 | { |
1043 | key = NULL; | 1099 | key = NULL; |
1044 | utf_in = (const char *) &sh_msg[1]; | 1100 | GNUNET_STRINGS_utf8_tolower ((char*) &sh_msg[1], &nameptr); |
1045 | if ('\0' != utf_in[msg_size - sizeof (struct GNUNET_GNS_ClientLookupMessage) - 1]) | 1101 | } |
1046 | { | 1102 | |
1047 | GNUNET_break (0); | 1103 | namelen = strlen(name)+1; |
1048 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1049 | return; | ||
1050 | } | ||
1051 | GNUNET_STRINGS_utf8_tolower(utf_in, &nameptr); | ||
1052 | } | ||
1053 | namelen = strlen (name)+1; | ||
1054 | clh = GNUNET_malloc (sizeof (struct ClientLookupHandle)); | 1104 | clh = GNUNET_malloc (sizeof (struct ClientLookupHandle)); |
1055 | memset (clh, 0, sizeof (struct ClientLookupHandle)); | 1105 | memset (clh, 0, sizeof (struct ClientLookupHandle)); |
1056 | clh->client = client; | 1106 | clh->client = client; |
1057 | clh->name = GNUNET_malloc(namelen); | 1107 | clh->name = GNUNET_malloc (namelen); |
1058 | strcpy(clh->name, name); | 1108 | strcpy (clh->name, name); |
1059 | clh->unique_id = sh_msg->id; | 1109 | clh->request_id = sh_msg->id; |
1060 | clh->type = ntohl(sh_msg->type); | 1110 | clh->type = ntohl (sh_msg->type); |
1061 | clh->shorten_key = key; | 1111 | clh->shorten_key = key; |
1062 | 1112 | ||
1063 | only_cached = ntohl(sh_msg->only_cached); | 1113 | only_cached = ntohl (sh_msg->only_cached); |
1064 | 1114 | ||
1065 | if (strlen (name) > MAX_DNS_NAME_LENGTH) { | 1115 | if (strlen (name) > MAX_DNS_NAME_LENGTH) { |
1066 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1067 | "LOOKUP: %s is too long", name); | 1117 | "LOOKUP: %s is too long", name); |
1068 | clh->name = NULL; | 1118 | clh->name = NULL; |
1069 | send_lookup_response(clh, 0, NULL); | 1119 | send_lookup_response (clh, 0, NULL); |
1070 | return; | 1120 | return; |
1071 | } | 1121 | } |
1072 | 1122 | ||
@@ -1076,21 +1126,21 @@ handle_lookup(void *cls, | |||
1076 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1126 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1077 | "LOOKUP: Query for A record but AF_INET not supported!"); | 1127 | "LOOKUP: Query for A record but AF_INET not supported!"); |
1078 | clh->name = NULL; | 1128 | clh->name = NULL; |
1079 | send_lookup_response(clh, 0, NULL); | 1129 | send_lookup_response (clh, 0, NULL); |
1080 | return; | 1130 | return; |
1081 | } | 1131 | } |
1082 | 1132 | ||
1083 | if ((clh->type == GNUNET_GNS_RECORD_AAAA) && | 1133 | if ((clh->type == GNUNET_GNS_RECORD_AAAA) && |
1084 | (GNUNET_OK != v6_enabled)) | 1134 | (GNUNET_OK != v6_enabled)) |
1085 | { | 1135 | { |
1086 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1087 | "LOOKUP: Query for AAAA record but AF_INET6 not supported!"); | 1137 | "LOOKUP: Query for AAAA record but AF_INET6 not supported!"); |
1088 | clh->name = NULL; | 1138 | clh->name = NULL; |
1089 | send_lookup_response(clh, 0, NULL); | 1139 | send_lookup_response (clh, 0, NULL); |
1090 | return; | 1140 | return; |
1091 | } | 1141 | } |
1092 | 1142 | ||
1093 | if (1 == ntohl(sh_msg->use_default_zone)) | 1143 | if (1 == ntohl (sh_msg->use_default_zone)) |
1094 | clh->zone = zone_hash; //Default zone | 1144 | clh->zone = zone_hash; //Default zone |
1095 | else | 1145 | else |
1096 | clh->zone = sh_msg->zone; | 1146 | clh->zone = sh_msg->zone; |
@@ -1210,18 +1260,18 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1210 | 1260 | ||
1211 | } | 1261 | } |
1212 | 1262 | ||
1213 | zone_iteration_interval = INITIAL_ZONE_ITERATION_INTERVAL; | 1263 | put_interval = INITIAL_PUT_INTERVAL; |
1214 | 1264 | ||
1215 | record_put_interval = DEFAULT_RECORD_PUT_INTERVAL; | 1265 | zone_publish_time_window = DEFAULT_ZONE_PUBLISH_TIME_WINDOW; |
1216 | 1266 | ||
1217 | if (GNUNET_OK == | 1267 | if (GNUNET_OK == |
1218 | GNUNET_CONFIGURATION_get_value_time (c, "gns", | 1268 | GNUNET_CONFIGURATION_get_value_time (c, "gns", |
1219 | "RECORD_PUT_INTERVAL", | 1269 | "ZONE_PUBLISH_TIME_WINDOW", |
1220 | &record_put_interval)) | 1270 | &zone_publish_time_window)) |
1221 | { | 1271 | { |
1222 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1272 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1223 | "Record put interval: %s\n", | 1273 | "Time window for zone iteration: %s\n", |
1224 | GNUNET_STRINGS_relative_time_to_string (record_put_interval, GNUNET_YES)); | 1274 | GNUNET_STRINGS_relative_time_to_string (zone_publish_time_window, GNUNET_YES)); |
1225 | } | 1275 | } |
1226 | 1276 | ||
1227 | if (GNUNET_OK == | 1277 | if (GNUNET_OK == |
@@ -1297,7 +1347,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1297 | * We have roughly an hour for all records; | 1347 | * We have roughly an hour for all records; |
1298 | */ | 1348 | */ |
1299 | first_zone_iteration = GNUNET_YES; | 1349 | first_zone_iteration = GNUNET_YES; |
1300 | zone_update_taskid = GNUNET_SCHEDULER_add_now (&update_zone_dht_start, NULL); | 1350 | zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, NULL); |
1301 | 1351 | ||
1302 | GNUNET_SERVER_add_handlers (server, handlers); | 1352 | GNUNET_SERVER_add_handlers (server, handlers); |
1303 | 1353 | ||