diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-09-26 21:24:03 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-09-26 21:24:03 +0000 |
commit | 7b00dd51218edbd9182caa664cfce185edc2cc45 (patch) | |
tree | 2cea8a9d7085aa6e3d16256f18f7c77f3320bb75 /src/dht/gnunet-service-dht_clients.c | |
parent | 60ff113fe4e7bb71d5696063b9a9b81eba60a108 (diff) | |
download | gnunet-7b00dd51218edbd9182caa664cfce185edc2cc45.tar.gz gnunet-7b00dd51218edbd9182caa664cfce185edc2cc45.zip |
porting xdht to new service API, major code de-duplication effort
Diffstat (limited to 'src/dht/gnunet-service-dht_clients.c')
-rw-r--r-- | src/dht/gnunet-service-dht_clients.c | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c index 0e344b566..df56c010a 100644 --- a/src/dht/gnunet-service-dht_clients.c +++ b/src/dht/gnunet-service-dht_clients.c | |||
@@ -213,6 +213,25 @@ struct ClientHandle | |||
213 | 213 | ||
214 | }; | 214 | }; |
215 | 215 | ||
216 | /** | ||
217 | * Our handle to the BLOCK library. | ||
218 | */ | ||
219 | struct GNUNET_BLOCK_Context *GDS_block_context; | ||
220 | |||
221 | /** | ||
222 | * Handle for the statistics service. | ||
223 | */ | ||
224 | struct GNUNET_STATISTICS_Handle *GDS_stats; | ||
225 | |||
226 | /** | ||
227 | * Handle for the service. | ||
228 | */ | ||
229 | struct GNUNET_SERVICE_Handle *GDS_service; | ||
230 | |||
231 | /** | ||
232 | * The configuration the DHT service is running with | ||
233 | */ | ||
234 | const struct GNUNET_CONFIGURATION_Handle *GDS_cfg; | ||
216 | 235 | ||
217 | /** | 236 | /** |
218 | * List of active monitoring requests. | 237 | * List of active monitoring requests. |
@@ -496,7 +515,7 @@ handle_dht_local_put (void *cls, | |||
496 | ntohl (dht_msg->options), | 515 | ntohl (dht_msg->options), |
497 | ntohl (dht_msg->desired_replication_level), | 516 | ntohl (dht_msg->desired_replication_level), |
498 | GNUNET_TIME_absolute_ntoh (dht_msg->expiration), | 517 | GNUNET_TIME_absolute_ntoh (dht_msg->expiration), |
499 | 0 /* hop count */ , | 518 | 0 /* hop count */, |
500 | peer_bf, | 519 | peer_bf, |
501 | &dht_msg->key, | 520 | &dht_msg->key, |
502 | 0, | 521 | 0, |
@@ -541,6 +560,43 @@ check_dht_local_get (void *cls, | |||
541 | 560 | ||
542 | 561 | ||
543 | /** | 562 | /** |
563 | * Handle a result from local datacache for a GET operation. | ||
564 | * | ||
565 | * @param cls the `struct ClientHandle` of the client doing the query | ||
566 | * @param type type of the block | ||
567 | * @param expiration_time when does the content expire | ||
568 | * @param key key for the content | ||
569 | * @param put_path_length number of entries in @a put_path | ||
570 | * @param put_path peers the original PUT traversed (if tracked) | ||
571 | * @param get_path_length number of entries in @a get_path | ||
572 | * @param get_path peers this reply has traversed so far (if tracked) | ||
573 | * @param data payload of the reply | ||
574 | * @param data_size number of bytes in @a data | ||
575 | */ | ||
576 | static void | ||
577 | handle_local_result (void *cls, | ||
578 | enum GNUNET_BLOCK_Type type, | ||
579 | struct GNUNET_TIME_Absolute expiration_time, | ||
580 | const struct GNUNET_HashCode *key, | ||
581 | unsigned int put_path_length, | ||
582 | const struct GNUNET_PeerIdentity *put_path, | ||
583 | unsigned int get_path_length, | ||
584 | const struct GNUNET_PeerIdentity *get_path, | ||
585 | const void *data, | ||
586 | size_t data_size) | ||
587 | { | ||
588 | // FIXME: this needs some clean up: inline the function, | ||
589 | // possibly avoid even looking up the client! | ||
590 | GDS_CLIENTS_handle_reply (expiration_time, | ||
591 | key, | ||
592 | 0, NULL, | ||
593 | put_path_length, put_path, | ||
594 | type, | ||
595 | data_size, data); | ||
596 | } | ||
597 | |||
598 | |||
599 | /** | ||
544 | * Handler for DHT GET messages from the client. | 600 | * Handler for DHT GET messages from the client. |
545 | * | 601 | * |
546 | * @param cls the client we received this message from | 602 | * @param cls the client we received this message from |
@@ -611,7 +667,9 @@ handle_dht_local_get (void *cls, | |||
611 | cqr->xquery, | 667 | cqr->xquery, |
612 | xquery_size, | 668 | xquery_size, |
613 | NULL, | 669 | NULL, |
614 | 0); | 670 | 0, |
671 | &handle_local_result, | ||
672 | ch); | ||
615 | GNUNET_SERVICE_client_continue (ch->client); | 673 | GNUNET_SERVICE_client_continue (ch->client); |
616 | } | 674 | } |
617 | 675 | ||
@@ -1413,11 +1471,12 @@ GDS_CLIENTS_stop () | |||
1413 | /** | 1471 | /** |
1414 | * Define "main" method using service macro. | 1472 | * Define "main" method using service macro. |
1415 | * | 1473 | * |
1474 | * @param name name of the service, i.e. "dht" or "xdht" | ||
1416 | * @param run name of the initializaton method for the service | 1475 | * @param run name of the initializaton method for the service |
1417 | */ | 1476 | */ |
1418 | #define GDS_DHT_SERVICE_INIT(run) \ | 1477 | #define GDS_DHT_SERVICE_INIT(name,run) \ |
1419 | GNUNET_SERVICE_MAIN \ | 1478 | GNUNET_SERVICE_MAIN \ |
1420 | ("dht", \ | 1479 | (name, \ |
1421 | GNUNET_SERVICE_OPTION_NONE, \ | 1480 | GNUNET_SERVICE_OPTION_NONE, \ |
1422 | run, \ | 1481 | run, \ |
1423 | &client_connect_cb, \ | 1482 | &client_connect_cb, \ |