diff options
Diffstat (limited to 'src/dht/dht_api.c')
-rw-r--r-- | src/dht/dht_api.c | 177 |
1 files changed, 54 insertions, 123 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 727f1a1f6..1ba2f7277 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -260,7 +260,7 @@ struct GNUNET_DHT_Handle | |||
260 | * @param h DHT handle to reconnect | 260 | * @param h DHT handle to reconnect |
261 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. | 261 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. |
262 | */ | 262 | */ |
263 | static int | 263 | static enum GNUNET_GenericReturnValue |
264 | try_connect (struct GNUNET_DHT_Handle *h); | 264 | try_connect (struct GNUNET_DHT_Handle *h); |
265 | 265 | ||
266 | 266 | ||
@@ -344,7 +344,7 @@ send_get_known_results (struct GNUNET_DHT_GetHandle *gh, | |||
344 | * @param value the `struct GNUNET_DHT_GetHandle *` | 344 | * @param value the `struct GNUNET_DHT_GetHandle *` |
345 | * @return #GNUNET_YES (always) | 345 | * @return #GNUNET_YES (always) |
346 | */ | 346 | */ |
347 | static int | 347 | static enum GNUNET_GenericReturnValue |
348 | add_get_request_to_pending (void *cls, | 348 | add_get_request_to_pending (void *cls, |
349 | const struct GNUNET_HashCode *key, | 349 | const struct GNUNET_HashCode *key, |
350 | void *value) | 350 | void *value) |
@@ -488,7 +488,7 @@ mq_error_handler (void *cls, | |||
488 | * @return #GNUNET_OK if everything went fine, | 488 | * @return #GNUNET_OK if everything went fine, |
489 | * #GNUNET_SYSERR if the message is malformed. | 489 | * #GNUNET_SYSERR if the message is malformed. |
490 | */ | 490 | */ |
491 | static int | 491 | static enum GNUNET_GenericReturnValue |
492 | check_monitor_get (void *cls, | 492 | check_monitor_get (void *cls, |
493 | const struct GNUNET_DHT_MonitorGetMessage *msg) | 493 | const struct GNUNET_DHT_MonitorGetMessage *msg) |
494 | { | 494 | { |
@@ -496,7 +496,7 @@ check_monitor_get (void *cls, | |||
496 | uint16_t msize = ntohs (msg->header.size) - sizeof(*msg); | 496 | uint16_t msize = ntohs (msg->header.size) - sizeof(*msg); |
497 | 497 | ||
498 | if ((plen > UINT16_MAX) || | 498 | if ((plen > UINT16_MAX) || |
499 | (plen * sizeof(struct GNUNET_PeerIdentity) != msize)) | 499 | (plen * sizeof(struct GNUNET_DHT_PathElement) != msize)) |
500 | { | 500 | { |
501 | GNUNET_break (0); | 501 | GNUNET_break (0); |
502 | return GNUNET_SYSERR; | 502 | return GNUNET_SYSERR; |
@@ -534,7 +534,7 @@ handle_monitor_get (void *cls, | |||
534 | ntohl (msg->hop_count), | 534 | ntohl (msg->hop_count), |
535 | ntohl (msg->desired_replication_level), | 535 | ntohl (msg->desired_replication_level), |
536 | ntohl (msg->get_path_length), | 536 | ntohl (msg->get_path_length), |
537 | (struct GNUNET_PeerIdentity *) &msg[1], | 537 | (struct GNUNET_DHT_PathElement *) &msg[1], |
538 | &msg->key); | 538 | &msg->key); |
539 | } | 539 | } |
540 | } | 540 | } |
@@ -548,7 +548,7 @@ handle_monitor_get (void *cls, | |||
548 | * @return #GNUNET_OK if everything went fine, | 548 | * @return #GNUNET_OK if everything went fine, |
549 | * #GNUNET_SYSERR if the message is malformed. | 549 | * #GNUNET_SYSERR if the message is malformed. |
550 | */ | 550 | */ |
551 | static int | 551 | static enum GNUNET_GenericReturnValue |
552 | check_monitor_get_resp (void *cls, | 552 | check_monitor_get_resp (void *cls, |
553 | const struct GNUNET_DHT_MonitorGetRespMessage *msg) | 553 | const struct GNUNET_DHT_MonitorGetRespMessage *msg) |
554 | { | 554 | { |
@@ -557,7 +557,7 @@ check_monitor_get_resp (void *cls, | |||
557 | uint32_t putl = ntohl (msg->put_path_length); | 557 | uint32_t putl = ntohl (msg->put_path_length); |
558 | 558 | ||
559 | if ((getl + putl < getl) || | 559 | if ((getl + putl < getl) || |
560 | ((msize / sizeof(struct GNUNET_PeerIdentity)) < getl + putl)) | 560 | ((msize / sizeof(struct GNUNET_DHT_PathElement)) < getl + putl)) |
561 | { | 561 | { |
562 | GNUNET_break (0); | 562 | GNUNET_break (0); |
563 | return GNUNET_SYSERR; | 563 | return GNUNET_SYSERR; |
@@ -578,12 +578,12 @@ handle_monitor_get_resp (void *cls, | |||
578 | { | 578 | { |
579 | struct GNUNET_DHT_Handle *handle = cls; | 579 | struct GNUNET_DHT_Handle *handle = cls; |
580 | size_t msize = ntohs (msg->header.size) - sizeof(*msg); | 580 | size_t msize = ntohs (msg->header.size) - sizeof(*msg); |
581 | const struct GNUNET_PeerIdentity *path; | 581 | const struct GNUNET_DHT_PathElement *path; |
582 | uint32_t getl = ntohl (msg->get_path_length); | 582 | uint32_t getl = ntohl (msg->get_path_length); |
583 | uint32_t putl = ntohl (msg->put_path_length); | 583 | uint32_t putl = ntohl (msg->put_path_length); |
584 | struct GNUNET_DHT_MonitorHandle *mh; | 584 | struct GNUNET_DHT_MonitorHandle *mh; |
585 | 585 | ||
586 | path = (const struct GNUNET_PeerIdentity *) &msg[1]; | 586 | path = (const struct GNUNET_DHT_PathElement *) &msg[1]; |
587 | for (mh = handle->monitor_head; NULL != mh; mh = mh->next) | 587 | for (mh = handle->monitor_head; NULL != mh; mh = mh->next) |
588 | { | 588 | { |
589 | if (NULL == mh->get_resp_cb) | 589 | if (NULL == mh->get_resp_cb) |
@@ -603,8 +603,8 @@ handle_monitor_get_resp (void *cls, | |||
603 | GNUNET_TIME_absolute_ntoh (msg->expiration_time), | 603 | GNUNET_TIME_absolute_ntoh (msg->expiration_time), |
604 | &msg->key, | 604 | &msg->key, |
605 | (const void *) &path[getl + putl], | 605 | (const void *) &path[getl + putl], |
606 | msize - sizeof(struct GNUNET_PeerIdentity) * (putl | 606 | msize - sizeof(struct GNUNET_DHT_PathElement) * (putl |
607 | + getl)); | 607 | + getl)); |
608 | } | 608 | } |
609 | } | 609 | } |
610 | 610 | ||
@@ -617,7 +617,7 @@ handle_monitor_get_resp (void *cls, | |||
617 | * @return #GNUNET_OK if everything went fine, | 617 | * @return #GNUNET_OK if everything went fine, |
618 | * #GNUNET_SYSERR if the message is malformed. | 618 | * #GNUNET_SYSERR if the message is malformed. |
619 | */ | 619 | */ |
620 | static int | 620 | static enum GNUNET_GenericReturnValue |
621 | check_monitor_put (void *cls, | 621 | check_monitor_put (void *cls, |
622 | const struct GNUNET_DHT_MonitorPutMessage *msg) | 622 | const struct GNUNET_DHT_MonitorPutMessage *msg) |
623 | { | 623 | { |
@@ -626,7 +626,7 @@ check_monitor_put (void *cls, | |||
626 | 626 | ||
627 | msize = ntohs (msg->header.size) - sizeof(*msg); | 627 | msize = ntohs (msg->header.size) - sizeof(*msg); |
628 | putl = ntohl (msg->put_path_length); | 628 | putl = ntohl (msg->put_path_length); |
629 | if ((msize / sizeof(struct GNUNET_PeerIdentity)) < putl) | 629 | if ((msize / sizeof(struct GNUNET_DHT_PathElement)) < putl) |
630 | { | 630 | { |
631 | GNUNET_break (0); | 631 | GNUNET_break (0); |
632 | return GNUNET_SYSERR; | 632 | return GNUNET_SYSERR; |
@@ -648,10 +648,10 @@ handle_monitor_put (void *cls, | |||
648 | struct GNUNET_DHT_Handle *handle = cls; | 648 | struct GNUNET_DHT_Handle *handle = cls; |
649 | size_t msize = ntohs (msg->header.size) - sizeof(*msg); | 649 | size_t msize = ntohs (msg->header.size) - sizeof(*msg); |
650 | uint32_t putl = ntohl (msg->put_path_length); | 650 | uint32_t putl = ntohl (msg->put_path_length); |
651 | const struct GNUNET_PeerIdentity *path; | 651 | const struct GNUNET_DHT_PathElement *path; |
652 | struct GNUNET_DHT_MonitorHandle *mh; | 652 | struct GNUNET_DHT_MonitorHandle *mh; |
653 | 653 | ||
654 | path = (const struct GNUNET_PeerIdentity *) &msg[1]; | 654 | path = (const struct GNUNET_DHT_PathElement *) &msg[1]; |
655 | for (mh = handle->monitor_head; NULL != mh; mh = mh->next) | 655 | for (mh = handle->monitor_head; NULL != mh; mh = mh->next) |
656 | { | 656 | { |
657 | if (NULL == mh->put_cb) | 657 | if (NULL == mh->put_cb) |
@@ -672,7 +672,7 @@ handle_monitor_put (void *cls, | |||
672 | GNUNET_TIME_absolute_ntoh (msg->expiration_time), | 672 | GNUNET_TIME_absolute_ntoh (msg->expiration_time), |
673 | &msg->key, | 673 | &msg->key, |
674 | (const void *) &path[putl], | 674 | (const void *) &path[putl], |
675 | msize - sizeof(struct GNUNET_PeerIdentity) * putl); | 675 | msize - sizeof(struct GNUNET_DHT_PathElement) * putl); |
676 | } | 676 | } |
677 | } | 677 | } |
678 | 678 | ||
@@ -685,7 +685,7 @@ handle_monitor_put (void *cls, | |||
685 | * @return #GNUNET_OK if everything went fine, | 685 | * @return #GNUNET_OK if everything went fine, |
686 | * #GNUNET_SYSERR if the message is malformed. | 686 | * #GNUNET_SYSERR if the message is malformed. |
687 | */ | 687 | */ |
688 | static int | 688 | static enum GNUNET_GenericReturnValue |
689 | check_client_result (void *cls, | 689 | check_client_result (void *cls, |
690 | const struct GNUNET_DHT_ClientResultMessage *msg) | 690 | const struct GNUNET_DHT_ClientResultMessage *msg) |
691 | { | 691 | { |
@@ -695,12 +695,12 @@ check_client_result (void *cls, | |||
695 | size_t meta_length; | 695 | size_t meta_length; |
696 | 696 | ||
697 | meta_length = | 697 | meta_length = |
698 | sizeof(struct GNUNET_PeerIdentity) * (get_path_length + put_path_length); | 698 | sizeof(struct GNUNET_DHT_PathElement) * (get_path_length + put_path_length); |
699 | if ((msize < meta_length) || | 699 | if ((msize < meta_length) || |
700 | (get_path_length > | 700 | (get_path_length > |
701 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) || | 701 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement)) || |
702 | (put_path_length > | 702 | (put_path_length > |
703 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity))) | 703 | GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_DHT_PathElement))) |
704 | { | 704 | { |
705 | GNUNET_break (0); | 705 | GNUNET_break (0); |
706 | return GNUNET_SYSERR; | 706 | return GNUNET_SYSERR; |
@@ -717,7 +717,7 @@ check_client_result (void *cls, | |||
717 | * @param value the `struct GNUNET_DHT_GetHandle` of a request matching the same key | 717 | * @param value the `struct GNUNET_DHT_GetHandle` of a request matching the same key |
718 | * @return #GNUNET_YES to continue to iterate over all results | 718 | * @return #GNUNET_YES to continue to iterate over all results |
719 | */ | 719 | */ |
720 | static int | 720 | static enum GNUNET_GenericReturnValue |
721 | process_client_result (void *cls, | 721 | process_client_result (void *cls, |
722 | const struct GNUNET_HashCode *key, | 722 | const struct GNUNET_HashCode *key, |
723 | void *value) | 723 | void *value) |
@@ -727,8 +727,8 @@ process_client_result (void *cls, | |||
727 | size_t msize = ntohs (crm->header.size) - sizeof(*crm); | 727 | size_t msize = ntohs (crm->header.size) - sizeof(*crm); |
728 | uint32_t put_path_length = ntohl (crm->put_path_length); | 728 | uint32_t put_path_length = ntohl (crm->put_path_length); |
729 | uint32_t get_path_length = ntohl (crm->get_path_length); | 729 | uint32_t get_path_length = ntohl (crm->get_path_length); |
730 | const struct GNUNET_PeerIdentity *put_path; | 730 | const struct GNUNET_DHT_PathElement *put_path; |
731 | const struct GNUNET_PeerIdentity *get_path; | 731 | const struct GNUNET_DHT_PathElement *get_path; |
732 | struct GNUNET_HashCode hc; | 732 | struct GNUNET_HashCode hc; |
733 | size_t data_length; | 733 | size_t data_length; |
734 | size_t meta_length; | 734 | size_t meta_length; |
@@ -746,18 +746,18 @@ process_client_result (void *cls, | |||
746 | } | 746 | } |
747 | /* FIXME: might want to check that type matches */ | 747 | /* FIXME: might want to check that type matches */ |
748 | meta_length = | 748 | meta_length = |
749 | sizeof(struct GNUNET_PeerIdentity) * (get_path_length + put_path_length); | 749 | sizeof(struct GNUNET_DHT_PathElement) * (get_path_length + put_path_length); |
750 | data_length = msize - meta_length; | 750 | data_length = msize - meta_length; |
751 | put_path = (const struct GNUNET_PeerIdentity *) &crm[1]; | 751 | put_path = (const struct GNUNET_DHT_PathElement *) &crm[1]; |
752 | get_path = &put_path[put_path_length]; | 752 | get_path = &put_path[put_path_length]; |
753 | { | 753 | { |
754 | char *pp; | 754 | char *pp; |
755 | char *gp; | 755 | char *gp; |
756 | 756 | ||
757 | gp = GNUNET_STRINGS_pp2s (get_path, | 757 | gp = GNUNET_DHT_pp2s (get_path, |
758 | get_path_length); | 758 | get_path_length); |
759 | pp = GNUNET_STRINGS_pp2s (put_path, | 759 | pp = GNUNET_DHT_pp2s (put_path, |
760 | put_path_length); | 760 | put_path_length); |
761 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 761 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
762 | "Giving %u byte reply for %s to application (GP: %s, PP: %s)\n", | 762 | "Giving %u byte reply for %s to application (GP: %s, PP: %s)\n", |
763 | (unsigned int) data_length, | 763 | (unsigned int) data_length, |
@@ -838,7 +838,7 @@ handle_put_cont (void *cls) | |||
838 | * @param h DHT handle to reconnect | 838 | * @param h DHT handle to reconnect |
839 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. | 839 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. |
840 | */ | 840 | */ |
841 | static int | 841 | static enum GNUNET_GenericReturnValue |
842 | try_connect (struct GNUNET_DHT_Handle *h) | 842 | try_connect (struct GNUNET_DHT_Handle *h) |
843 | { | 843 | { |
844 | struct GNUNET_MQ_MessageHandler handlers[] = { | 844 | struct GNUNET_MQ_MessageHandler handlers[] = { |
@@ -878,14 +878,6 @@ try_connect (struct GNUNET_DHT_Handle *h) | |||
878 | } | 878 | } |
879 | 879 | ||
880 | 880 | ||
881 | /** | ||
882 | * Initialize the connection with the DHT service. | ||
883 | * | ||
884 | * @param cfg configuration to use | ||
885 | * @param ht_len size of the internal hash table to use for | ||
886 | * processing multiple GET/FIND requests in parallel | ||
887 | * @return handle to the DHT service, or NULL on error | ||
888 | */ | ||
889 | struct GNUNET_DHT_Handle * | 881 | struct GNUNET_DHT_Handle * |
890 | GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 882 | GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
891 | unsigned int ht_len) | 883 | unsigned int ht_len) |
@@ -909,11 +901,6 @@ GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
909 | } | 901 | } |
910 | 902 | ||
911 | 903 | ||
912 | /** | ||
913 | * Shutdown connection with the DHT service. | ||
914 | * | ||
915 | * @param handle handle of the DHT connection to stop | ||
916 | */ | ||
917 | void | 904 | void |
918 | GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle) | 905 | GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle) |
919 | { | 906 | { |
@@ -942,26 +929,6 @@ GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle) | |||
942 | } | 929 | } |
943 | 930 | ||
944 | 931 | ||
945 | /** | ||
946 | * Perform a PUT operation storing data in the DHT. FIXME: we should | ||
947 | * change the protocol to get a confirmation for the PUT from the DHT | ||
948 | * and call 'cont' only after getting the confirmation; otherwise, the | ||
949 | * client has no good way of telling if the 'PUT' message actually got | ||
950 | * to the DHT service! | ||
951 | * | ||
952 | * @param handle handle to DHT service | ||
953 | * @param key the key to store under | ||
954 | * @param desired_replication_level estimate of how many | ||
955 | * nearest peers this request should reach | ||
956 | * @param options routing options for this message | ||
957 | * @param type type of the value | ||
958 | * @param size number of bytes in data; must be less than 64k | ||
959 | * @param data the data to store | ||
960 | * @param exp desired expiration time for the value | ||
961 | * @param cont continuation to call when done (transmitting request to service) | ||
962 | * You must not call #GNUNET_DHT_disconnect in this continuation | ||
963 | * @param cont_cls closure for @a cont | ||
964 | */ | ||
965 | struct GNUNET_DHT_PutHandle * | 932 | struct GNUNET_DHT_PutHandle * |
966 | GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, | 933 | GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, |
967 | const struct GNUNET_HashCode *key, | 934 | const struct GNUNET_HashCode *key, |
@@ -1020,17 +987,6 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, | |||
1020 | } | 987 | } |
1021 | 988 | ||
1022 | 989 | ||
1023 | /** | ||
1024 | * Cancels a DHT PUT operation. Note that the PUT request may still | ||
1025 | * go out over the network (we can't stop that); However, if the PUT | ||
1026 | * has not yet been sent to the service, cancelling the PUT will stop | ||
1027 | * this from happening (but there is no way for the user of this API | ||
1028 | * to tell if that is the case). The only use for this API is to | ||
1029 | * prevent a later call to 'cont' from #GNUNET_DHT_put (e.g. because | ||
1030 | * the system is shutting down). | ||
1031 | * | ||
1032 | * @param ph put operation to cancel ('cont' will no longer be called) | ||
1033 | */ | ||
1034 | void | 990 | void |
1035 | GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph) | 991 | GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph) |
1036 | { | 992 | { |
@@ -1047,21 +1003,6 @@ GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph) | |||
1047 | } | 1003 | } |
1048 | 1004 | ||
1049 | 1005 | ||
1050 | /** | ||
1051 | * Perform an asynchronous GET operation on the DHT identified. | ||
1052 | * | ||
1053 | * @param handle handle to the DHT service | ||
1054 | * @param type expected type of the response object | ||
1055 | * @param key the key to look up | ||
1056 | * @param desired_replication_level estimate of how many | ||
1057 | nearest peers this request should reach | ||
1058 | * @param options routing options for this message | ||
1059 | * @param xquery extended query data (can be NULL, depending on type) | ||
1060 | * @param xquery_size number of bytes in @a xquery | ||
1061 | * @param iter function to call on each result | ||
1062 | * @param iter_cls closure for @a iter | ||
1063 | * @return handle to stop the async get | ||
1064 | */ | ||
1065 | struct GNUNET_DHT_GetHandle * | 1006 | struct GNUNET_DHT_GetHandle * |
1066 | GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, | 1007 | GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, |
1067 | enum GNUNET_BLOCK_Type type, | 1008 | enum GNUNET_BLOCK_Type type, |
@@ -1111,16 +1052,6 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, | |||
1111 | } | 1052 | } |
1112 | 1053 | ||
1113 | 1054 | ||
1114 | /** | ||
1115 | * Tell the DHT not to return any of the following known results | ||
1116 | * to this client. | ||
1117 | * | ||
1118 | * @param get_handle get operation for which results should be filtered | ||
1119 | * @param num_results number of results to be blocked that are | ||
1120 | * provided in this call (size of the @a results array) | ||
1121 | * @param results array of hash codes over the 'data' of the results | ||
1122 | * to be blocked | ||
1123 | */ | ||
1124 | void | 1055 | void |
1125 | GNUNET_DHT_get_filter_known_results (struct GNUNET_DHT_GetHandle *get_handle, | 1056 | GNUNET_DHT_get_filter_known_results (struct GNUNET_DHT_GetHandle *get_handle, |
1126 | unsigned int num_results, | 1057 | unsigned int num_results, |
@@ -1145,11 +1076,6 @@ GNUNET_DHT_get_filter_known_results (struct GNUNET_DHT_GetHandle *get_handle, | |||
1145 | } | 1076 | } |
1146 | 1077 | ||
1147 | 1078 | ||
1148 | /** | ||
1149 | * Stop async DHT-get. | ||
1150 | * | ||
1151 | * @param get_handle handle to the GET operation to stop | ||
1152 | */ | ||
1153 | void | 1079 | void |
1154 | GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle) | 1080 | GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle) |
1155 | { | 1081 | { |
@@ -1183,18 +1109,6 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle) | |||
1183 | } | 1109 | } |
1184 | 1110 | ||
1185 | 1111 | ||
1186 | /** | ||
1187 | * Start monitoring the local DHT service. | ||
1188 | * | ||
1189 | * @param handle Handle to the DHT service. | ||
1190 | * @param type Type of blocks that are of interest. | ||
1191 | * @param key Key of data of interest, NULL for all. | ||
1192 | * @param get_cb Callback to process monitored get messages. | ||
1193 | * @param get_resp_cb Callback to process monitored get response messages. | ||
1194 | * @param put_cb Callback to process monitored put messages. | ||
1195 | * @param cb_cls Closure for callbacks. | ||
1196 | * @return Handle to stop monitoring. | ||
1197 | */ | ||
1198 | struct GNUNET_DHT_MonitorHandle * | 1112 | struct GNUNET_DHT_MonitorHandle * |
1199 | GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle, | 1113 | GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle, |
1200 | enum GNUNET_BLOCK_Type type, | 1114 | enum GNUNET_BLOCK_Type type, |
@@ -1227,13 +1141,6 @@ GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle, | |||
1227 | } | 1141 | } |
1228 | 1142 | ||
1229 | 1143 | ||
1230 | /** | ||
1231 | * Stop monitoring. | ||
1232 | * | ||
1233 | * @param mh The handle to the monitor request returned by monitor_start. | ||
1234 | * | ||
1235 | * On return get_handle will no longer be valid, caller must not use again!!! | ||
1236 | */ | ||
1237 | void | 1144 | void |
1238 | GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *mh) | 1145 | GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *mh) |
1239 | { | 1146 | { |
@@ -1262,4 +1169,28 @@ GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *mh) | |||
1262 | } | 1169 | } |
1263 | 1170 | ||
1264 | 1171 | ||
1172 | char * | ||
1173 | GNUNET_DHT_pp2s (const struct GNUNET_DHT_PathElement *path, | ||
1174 | unsigned int path_len) | ||
1175 | { | ||
1176 | char *buf; | ||
1177 | size_t off; | ||
1178 | size_t plen = path_len * 5 + 1; | ||
1179 | |||
1180 | GNUNET_assert (path_len < UINT32_MAX / 5); | ||
1181 | off = 0; | ||
1182 | buf = GNUNET_malloc (plen); | ||
1183 | for (unsigned int i = 0; i < path_len; i++) | ||
1184 | { | ||
1185 | off += GNUNET_snprintf (&buf[off], | ||
1186 | plen - off, | ||
1187 | "%s%s", | ||
1188 | GNUNET_i2s (&path[i].pred), | ||
1189 | (i == path_len - 1) ? "" : "-"); | ||
1190 | } | ||
1191 | return buf; | ||
1192 | |||
1193 | } | ||
1194 | |||
1195 | |||
1265 | /* end of dht_api.c */ | 1196 | /* end of dht_api.c */ |