diff options
-rw-r--r-- | src/dht/dht.h | 18 | ||||
-rw-r--r-- | src/dht/dht_api.c | 185 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht.c | 13 | ||||
-rw-r--r-- | src/dht/test_dht_api.c | 62 | ||||
-rw-r--r-- | src/dht/test_dht_api_peer1.conf | 6 |
5 files changed, 221 insertions, 63 deletions
diff --git a/src/dht/dht.h b/src/dht/dht.h index 0cfd9b3bf..68591a97e 100644 --- a/src/dht/dht.h +++ b/src/dht/dht.h | |||
@@ -27,7 +27,7 @@ | |||
27 | #ifndef DHT_H_ | 27 | #ifndef DHT_H_ |
28 | #define DHT_H_ | 28 | #define DHT_H_ |
29 | 29 | ||
30 | #define DEBUG_DHT GNUNET_YES | 30 | #define DEBUG_DHT GNUNET_NO |
31 | 31 | ||
32 | typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls, | 32 | typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls, |
33 | struct GNUNET_MessageHeader *msg); | 33 | struct GNUNET_MessageHeader *msg); |
@@ -166,7 +166,7 @@ struct GNUNET_DHT_GetResultMessage | |||
166 | }; | 166 | }; |
167 | 167 | ||
168 | /** | 168 | /** |
169 | * Message to request data from the DHT | 169 | * Message to issue find peer request to the DHT |
170 | */ | 170 | */ |
171 | struct GNUNET_DHT_FindPeerMessage | 171 | struct GNUNET_DHT_FindPeerMessage |
172 | { | 172 | { |
@@ -175,6 +175,13 @@ struct GNUNET_DHT_FindPeerMessage | |||
175 | */ | 175 | */ |
176 | struct GNUNET_MessageHeader header; | 176 | struct GNUNET_MessageHeader header; |
177 | 177 | ||
178 | /** | ||
179 | * Size of inject message (may be zero) | ||
180 | */ | ||
181 | size_t msg_len; | ||
182 | |||
183 | /* Followed by message to inject at found peers */ | ||
184 | |||
178 | }; | 185 | }; |
179 | 186 | ||
180 | /** | 187 | /** |
@@ -188,14 +195,15 @@ struct GNUNET_DHT_FindPeerResultMessage | |||
188 | struct GNUNET_MessageHeader header; | 195 | struct GNUNET_MessageHeader header; |
189 | 196 | ||
190 | /** | 197 | /** |
191 | * The peer that was searched for | 198 | * The peer that was found |
192 | */ | 199 | */ |
193 | struct GNUNET_PeerIdentity peer; | 200 | struct GNUNET_PeerIdentity peer; |
194 | 201 | ||
195 | /** | 202 | /** |
196 | * The size of the HELLO for the returned peer, | 203 | * The size of the return message from the peer |
204 | * (defaults to HELLO for the peer), | ||
197 | * appended to the end of this message, 0 if | 205 | * appended to the end of this message, 0 if |
198 | * no hello. | 206 | * no message. |
199 | */ | 207 | */ |
200 | size_t data_size; | 208 | size_t data_size; |
201 | 209 | ||
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 9fb77d5d4..f935d69d3 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -24,13 +24,8 @@ | |||
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | * @author Nathan Evans | 25 | * @author Nathan Evans |
26 | * | 26 | * |
27 | * TODO: Only allow a single message until confirmed as received by | ||
28 | * the service. For put messages call continuation as soon as | ||
29 | * receipt acknowledged (then remove), for GET or other messages | ||
30 | * only call continuation when data received. | ||
31 | * Add unique identifier to message types requesting data to be | ||
32 | * returned. | ||
33 | */ | 27 | */ |
28 | |||
34 | #include "platform.h" | 29 | #include "platform.h" |
35 | #include "gnunet_bandwidth_lib.h" | 30 | #include "gnunet_bandwidth_lib.h" |
36 | #include "gnunet_client_lib.h" | 31 | #include "gnunet_client_lib.h" |
@@ -44,7 +39,7 @@ | |||
44 | #include "gnunet_dht_service.h" | 39 | #include "gnunet_dht_service.h" |
45 | #include "dht.h" | 40 | #include "dht.h" |
46 | 41 | ||
47 | #define DEBUG_DHT_API GNUNET_YES | 42 | #define DEBUG_DHT_API GNUNET_NO |
48 | 43 | ||
49 | #define DEFAULT_DHT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 44 | #define DEFAULT_DHT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
50 | 45 | ||
@@ -86,8 +81,6 @@ struct PendingMessage | |||
86 | 81 | ||
87 | struct GNUNET_DHT_GetContext | 82 | struct GNUNET_DHT_GetContext |
88 | { | 83 | { |
89 | |||
90 | |||
91 | /** | 84 | /** |
92 | * Iterator to call on data receipt | 85 | * Iterator to call on data receipt |
93 | */ | 86 | */ |
@@ -100,6 +93,20 @@ struct GNUNET_DHT_GetContext | |||
100 | 93 | ||
101 | }; | 94 | }; |
102 | 95 | ||
96 | struct GNUNET_DHT_FindPeerContext | ||
97 | { | ||
98 | /** | ||
99 | * Iterator to call on data receipt | ||
100 | */ | ||
101 | GNUNET_DHT_FindPeerProcessor proc; | ||
102 | |||
103 | /** | ||
104 | * Closure for the iterator callback | ||
105 | */ | ||
106 | void *proc_cls; | ||
107 | |||
108 | }; | ||
109 | |||
103 | /** | 110 | /** |
104 | * Handle to control a unique operation (one that is | 111 | * Handle to control a unique operation (one that is |
105 | * expected to return results) | 112 | * expected to return results) |
@@ -162,6 +169,38 @@ struct GNUNET_DHT_NonUniqueHandle | |||
162 | void *cont_cls; | 169 | void *cont_cls; |
163 | }; | 170 | }; |
164 | 171 | ||
172 | /** | ||
173 | * Handle to control a get operation. | ||
174 | */ | ||
175 | struct GNUNET_DHT_GetHandle | ||
176 | { | ||
177 | /** | ||
178 | * Handle to the actual route operation for the get | ||
179 | */ | ||
180 | struct GNUNET_DHT_RouteHandle *route_handle; | ||
181 | |||
182 | /** | ||
183 | * The context of the get request | ||
184 | */ | ||
185 | struct GNUNET_DHT_GetContext get_context; | ||
186 | }; | ||
187 | |||
188 | /** | ||
189 | * Handle to control a find peer operation. | ||
190 | */ | ||
191 | struct GNUNET_DHT_FindPeerHandle | ||
192 | { | ||
193 | /** | ||
194 | * Handle to the actual route operation for the request | ||
195 | */ | ||
196 | struct GNUNET_DHT_RouteHandle *route_handle; | ||
197 | |||
198 | /** | ||
199 | * The context of the get request | ||
200 | */ | ||
201 | struct GNUNET_DHT_FindPeerContext find_peer_context; | ||
202 | }; | ||
203 | |||
165 | 204 | ||
166 | /** | 205 | /** |
167 | * Connection to the DHT service. | 206 | * Connection to the DHT service. |
@@ -565,6 +604,17 @@ void get_reply_iterator (void *cls, | |||
565 | 604 | ||
566 | } | 605 | } |
567 | 606 | ||
607 | |||
608 | /** | ||
609 | * Iterator called on each result obtained from a generic route | ||
610 | * operation | ||
611 | */ | ||
612 | void find_peer_reply_iterator (void *cls, | ||
613 | const struct GNUNET_MessageHeader *reply) | ||
614 | { | ||
615 | |||
616 | } | ||
617 | |||
568 | /** | 618 | /** |
569 | * Perform an asynchronous FIND_PEER operation on the DHT. | 619 | * Perform an asynchronous FIND_PEER operation on the DHT. |
570 | * | 620 | * |
@@ -674,8 +724,7 @@ GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle, | |||
674 | } | 724 | } |
675 | 725 | ||
676 | void | 726 | void |
677 | GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *fph); | 727 | GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle, GNUNET_SCHEDULER_Task cont, void *cont_cls); |
678 | |||
679 | 728 | ||
680 | /** | 729 | /** |
681 | * Perform an asynchronous GET operation on the DHT identified. | 730 | * Perform an asynchronous GET operation on the DHT identified. |
@@ -691,7 +740,7 @@ GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *fph); | |||
691 | * | 740 | * |
692 | * @return handle to stop the async get | 741 | * @return handle to stop the async get |
693 | */ | 742 | */ |
694 | struct GNUNET_DHT_RouteHandle * | 743 | struct GNUNET_DHT_GetHandle * |
695 | GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, | 744 | GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, |
696 | struct GNUNET_TIME_Relative timeout, | 745 | struct GNUNET_TIME_Relative timeout, |
697 | uint32_t type, | 746 | uint32_t type, |
@@ -701,15 +750,15 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, | |||
701 | GNUNET_SCHEDULER_Task cont, | 750 | GNUNET_SCHEDULER_Task cont, |
702 | void *cont_cls) | 751 | void *cont_cls) |
703 | { | 752 | { |
704 | struct GNUNET_DHT_GetContext *get_context; | 753 | struct GNUNET_DHT_GetHandle *get_handle; |
705 | struct GNUNET_DHT_GetMessage *get_msg; | 754 | struct GNUNET_DHT_GetMessage *get_msg; |
706 | 755 | ||
707 | if (handle->current != NULL) /* Can't send right now, we have a pending message... */ | 756 | if (handle->current != NULL) /* Can't send right now, we have a pending message... */ |
708 | return NULL; | 757 | return NULL; |
709 | 758 | ||
710 | get_context = GNUNET_malloc(sizeof(struct GNUNET_DHT_GetContext)); | 759 | get_handle = GNUNET_malloc(sizeof(struct GNUNET_DHT_GetHandle)); |
711 | get_context->iter = iter; | 760 | get_handle->get_context.iter = iter; |
712 | get_context->iter_cls = iter_cls; | 761 | get_handle->get_context.iter_cls = iter_cls; |
713 | 762 | ||
714 | #if DEBUG_DHT_API | 763 | #if DEBUG_DHT_API |
715 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -721,13 +770,13 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, | |||
721 | get_msg->header.size = htons(sizeof(struct GNUNET_DHT_GetMessage)); | 770 | get_msg->header.size = htons(sizeof(struct GNUNET_DHT_GetMessage)); |
722 | get_msg->type = htonl(type); | 771 | get_msg->type = htonl(type); |
723 | 772 | ||
724 | return GNUNET_DHT_route_start(handle, key, 0, 0, &get_msg->header, timeout, &get_reply_iterator, get_context, cont, cont_cls); | 773 | get_handle->route_handle = GNUNET_DHT_route_start(handle, key, 0, 0, &get_msg->header, timeout, &get_reply_iterator, get_handle, cont, cont_cls); |
725 | 774 | return get_handle; | |
726 | } | 775 | } |
727 | 776 | ||
728 | 777 | ||
729 | void | 778 | void |
730 | GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle) | 779 | GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle, GNUNET_SCHEDULER_Task cont, void *cont_cls) |
731 | { | 780 | { |
732 | struct PendingMessage *pending; | 781 | struct PendingMessage *pending; |
733 | struct GNUNET_DHT_StopMessage *message; | 782 | struct GNUNET_DHT_StopMessage *message; |
@@ -750,8 +799,8 @@ GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle) | |||
750 | pending = GNUNET_malloc(sizeof(struct PendingMessage)); | 799 | pending = GNUNET_malloc(sizeof(struct PendingMessage)); |
751 | pending->msg = (struct GNUNET_MessageHeader *)message; | 800 | pending->msg = (struct GNUNET_MessageHeader *)message; |
752 | pending->timeout = DEFAULT_DHT_TIMEOUT; | 801 | pending->timeout = DEFAULT_DHT_TIMEOUT; |
753 | pending->cont = NULL; | 802 | pending->cont = cont; |
754 | pending->cont_cls = NULL; | 803 | pending->cont_cls = cont_cls; |
755 | pending->is_unique = GNUNET_NO; | 804 | pending->is_unique = GNUNET_NO; |
756 | pending->unique_id = route_handle->uid; | 805 | pending->unique_id = route_handle->uid; |
757 | 806 | ||
@@ -781,33 +830,95 @@ GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle) | |||
781 | * @param get_handle handle to the GET operation to stop | 830 | * @param get_handle handle to the GET operation to stop |
782 | */ | 831 | */ |
783 | void | 832 | void |
784 | GNUNET_DHT_get_stop (struct GNUNET_DHT_RouteHandle *get_handle) | 833 | GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle, GNUNET_SCHEDULER_Task cont, void *cont_cls) |
785 | { | 834 | { |
786 | #if OLDREMOVE | 835 | #if DEBUG_DHT_API |
787 | struct GNUNET_DHT_GetMessage *get_msg; | 836 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
788 | struct GNUNET_DHT_Handle *handle; | 837 | "`%s': Removing pending get request with key %s, uid %llu\n", "DHT API", GNUNET_h2s(&get_handle->route_handle->key), get_handle->route_handle->uid); |
789 | GNUNET_HashCode *uid_key; | ||
790 | #endif | 838 | #endif |
839 | GNUNET_DHT_route_stop(get_handle->route_handle, cont, cont_cls); | ||
840 | GNUNET_free(get_handle); | ||
791 | 841 | ||
792 | GNUNET_DHT_route_stop(get_handle); | 842 | } |
793 | 843 | ||
794 | #if OLDREMOVE | ||
795 | uid_key = hash_from_uid(get_handle->uid); | ||
796 | GNUNET_assert(GNUNET_CONTAINER_multihashmap_remove(handle->outstanding_requests, uid_key, get_handle) == GNUNET_YES); | ||
797 | 844 | ||
798 | if (handle->do_destroy == GNUNET_NO) | 845 | /** |
799 | { | 846 | * Perform an asynchronous FIND PEER operation on the DHT. |
800 | get_msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_GetMessage)); | 847 | * |
801 | get_msg->header.type = htons(GNUNET_MESSAGE_TYPE_DHT_GET_STOP); | 848 | * @param handle handle to the DHT service |
802 | get_msg->header.size = htons(sizeof(struct GNUNET_DHT_GetMessage)); | 849 | * @param timeout timeout for this request to be sent to the |
850 | * service | ||
851 | * @param options routing options for this message | ||
852 | * @param message a message to inject at found peers (may be null) | ||
853 | * @param key the key to look up | ||
854 | * @param iter function to call on each result | ||
855 | * @param iter_cls closure for iter | ||
856 | * @param cont continuation to call once message sent | ||
857 | * @param cont_cls closure for continuation | ||
858 | * | ||
859 | * @return handle to stop the async get, NULL on error | ||
860 | */ | ||
861 | struct GNUNET_DHT_FindPeerHandle * | ||
862 | GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle, | ||
863 | struct GNUNET_TIME_Relative timeout, | ||
864 | enum GNUNET_DHT_RouteOption options, | ||
865 | struct GNUNET_MessageHeader *message, | ||
866 | const GNUNET_HashCode * key, | ||
867 | GNUNET_DHT_FindPeerProcessor proc, | ||
868 | void *proc_cls, | ||
869 | GNUNET_SCHEDULER_Task cont, | ||
870 | void *cont_cls) | ||
871 | { | ||
872 | struct GNUNET_DHT_FindPeerHandle *find_peer_handle; | ||
873 | struct GNUNET_DHT_FindPeerMessage *find_peer_msg; | ||
874 | size_t msize; | ||
875 | |||
876 | if (handle->current != NULL) /* Can't send right now, we have a pending message... */ | ||
877 | return NULL; | ||
803 | 878 | ||
879 | if (message != NULL) | ||
880 | msize = ntohs(message->size); | ||
881 | else | ||
882 | msize = 0; | ||
804 | 883 | ||
805 | } | 884 | find_peer_handle = GNUNET_malloc(sizeof(struct GNUNET_DHT_FindPeerHandle)); |
885 | find_peer_handle->find_peer_context.proc = proc; | ||
886 | find_peer_handle->find_peer_context.proc_cls = proc_cls; | ||
887 | |||
888 | #if DEBUG_DHT_API | ||
889 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
890 | "`%s': Inserting pending `%s' request with key %s\n", "DHT API", "FIND PEER", GNUNET_h2s(key)); | ||
806 | #endif | 891 | #endif |
892 | |||
893 | find_peer_msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_FindPeerMessage) + msize); | ||
894 | find_peer_msg->header.type = htons(GNUNET_MESSAGE_TYPE_DHT_FIND_PEER); | ||
895 | find_peer_msg->header.size = htons(sizeof(struct GNUNET_DHT_FindPeerMessage)); | ||
896 | find_peer_msg->msg_len = msize; | ||
897 | |||
898 | if (message != NULL) | ||
899 | { | ||
900 | memcpy(&find_peer_msg[1], message, msize); | ||
901 | } | ||
902 | |||
903 | find_peer_handle->route_handle = GNUNET_DHT_route_start(handle, key, 0, options, &find_peer_msg->header, timeout, &find_peer_reply_iterator, find_peer_handle, cont, cont_cls); | ||
904 | return find_peer_handle; | ||
905 | } | ||
906 | |||
907 | /** | ||
908 | * Stop async find peer. Frees associated resources. | ||
909 | * | ||
910 | * @param find_peer_handle GET operation to stop. | ||
911 | */ | ||
912 | void | ||
913 | GNUNET_DHT_find_peer_stop (struct GNUNET_DHT_FindPeerHandle *find_peer_handle, GNUNET_SCHEDULER_Task cont, void *cont_cls) | ||
914 | { | ||
807 | #if DEBUG_DHT_API | 915 | #if DEBUG_DHT_API |
808 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 916 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
809 | "`%s': Removing pending get request with key %s, uid %llu\n", "DHT API", GNUNET_h2s(&get_handle->key), get_handle->uid); | 917 | "`%s': Removing pending `%s' request with key %s, uid %llu\n", "DHT API", "FIND PEER", GNUNET_h2s(&find_peer_handle->route_handle->key), find_peer_handle->route_handle->uid); |
810 | #endif | 918 | #endif |
919 | GNUNET_DHT_route_stop(find_peer_handle->route_handle, cont, cont_cls); | ||
920 | GNUNET_free(find_peer_handle); | ||
921 | |||
811 | } | 922 | } |
812 | 923 | ||
813 | 924 | ||
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index b8a45e5d1..c6ddb0ab9 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -144,7 +144,9 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { | |||
144 | */ | 144 | */ |
145 | static void handle_dht_get (void *cls, struct GNUNET_DHT_GetMessage *get_msg, GNUNET_HashCode *key) | 145 | static void handle_dht_get (void *cls, struct GNUNET_DHT_GetMessage *get_msg, GNUNET_HashCode *key) |
146 | { | 146 | { |
147 | #if DEBUG_DHT | ||
147 | GNUNET_HashCode get_key; | 148 | GNUNET_HashCode get_key; |
149 | #endif | ||
148 | size_t get_type; | 150 | size_t get_type; |
149 | 151 | ||
150 | GNUNET_assert(ntohs(get_msg->header.size) >= sizeof(struct GNUNET_DHT_GetMessage)); | 152 | GNUNET_assert(ntohs(get_msg->header.size) >= sizeof(struct GNUNET_DHT_GetMessage)); |
@@ -164,14 +166,13 @@ static void handle_dht_get (void *cls, struct GNUNET_DHT_GetMessage *get_msg, GN | |||
164 | */ | 166 | */ |
165 | static void handle_dht_find_peer (void *cls, struct GNUNET_DHT_FindPeerMessage *find_msg, GNUNET_HashCode *key) | 167 | static void handle_dht_find_peer (void *cls, struct GNUNET_DHT_FindPeerMessage *find_msg, GNUNET_HashCode *key) |
166 | { | 168 | { |
167 | |||
168 | GNUNET_assert(ntohs(find_msg->header.size) == sizeof(struct GNUNET_DHT_FindPeerMessage)); | ||
169 | |||
170 | #if DEBUG_DHT | 169 | #if DEBUG_DHT |
171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
172 | "`%s': Received `%s' request from client, key %s\n", "DHT", "FIND PEER", GNUNET_h2s(key)); | 171 | "`%s': Received `%s' request from client, key %s (msg size %d, we expected %d)\n", "DHT", "FIND PEER", GNUNET_h2s(key), ntohs(find_msg->header.size), sizeof(struct GNUNET_DHT_FindPeerMessage)); |
173 | #endif | 172 | #endif |
174 | 173 | ||
174 | GNUNET_assert(ntohs(find_msg->header.size) >= sizeof(struct GNUNET_DHT_FindPeerMessage)); | ||
175 | |||
175 | /* FIXME: Implement find peer functionality here */ | 176 | /* FIXME: Implement find peer functionality here */ |
176 | } | 177 | } |
177 | 178 | ||
@@ -298,10 +299,8 @@ handle_dht_start_message(void *cls, struct GNUNET_SERVER_Client * client, | |||
298 | handle_dht_find_peer(cls, (struct GNUNET_DHT_FindPeerMessage *)enc_msg, &dht_msg->key); | 299 | handle_dht_find_peer(cls, (struct GNUNET_DHT_FindPeerMessage *)enc_msg, &dht_msg->key); |
299 | break; | 300 | break; |
300 | default: | 301 | default: |
301 | #if DEBUG_DHT | 302 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
303 | "`%s': Message type (%d) not handled\n", "DHT", enc_type); | 303 | "`%s': Message type (%d) not handled\n", "DHT", enc_type); |
304 | #endif | ||
305 | } | 304 | } |
306 | 305 | ||
307 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 306 | GNUNET_SERVER_receive_done(client, GNUNET_OK); |
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index dd940a6e4..9dc429148 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c | |||
@@ -51,8 +51,8 @@ struct PeerContext | |||
51 | struct GNUNET_CONFIGURATION_Handle *cfg; | 51 | struct GNUNET_CONFIGURATION_Handle *cfg; |
52 | struct GNUNET_DHT_Handle *dht_handle; | 52 | struct GNUNET_DHT_Handle *dht_handle; |
53 | struct GNUNET_PeerIdentity id; | 53 | struct GNUNET_PeerIdentity id; |
54 | struct GNUNET_DHT_RouteHandle *get_handle; | 54 | struct GNUNET_DHT_GetHandle *get_handle; |
55 | struct GNUNET_DHT_RouteHandle *find_peer_handle; | 55 | struct GNUNET_DHT_FindPeerHandle *find_peer_handle; |
56 | 56 | ||
57 | #if START_ARM | 57 | #if START_ARM |
58 | pid_t arm_pid; | 58 | pid_t arm_pid; |
@@ -123,6 +123,50 @@ end_badly () | |||
123 | return; | 123 | return; |
124 | } | 124 | } |
125 | 125 | ||
126 | /** | ||
127 | * Signature of the main function of a task. | ||
128 | * | ||
129 | * @param cls closure | ||
130 | * @param tc context information (why was this task triggered now) | ||
131 | */ | ||
132 | void test_find_peer_stop (void *cls, | ||
133 | const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
134 | { | ||
135 | struct PeerContext *peer = cls; | ||
136 | |||
137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer_stop!\n"); | ||
138 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | ||
139 | GNUNET_SCHEDULER_add_now(sched, &end_badly, NULL); | ||
140 | |||
141 | GNUNET_assert (peer->dht_handle != NULL); | ||
142 | |||
143 | GNUNET_DHT_find_peer_stop(peer->find_peer_handle, &end, &p1); | ||
144 | |||
145 | //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &end, &p1); | ||
146 | |||
147 | } | ||
148 | |||
149 | /** | ||
150 | * Signature of the main function of a task. | ||
151 | * | ||
152 | * @param cls closure | ||
153 | * @param tc context information (why was this task triggered now) | ||
154 | */ | ||
155 | void test_find_peer (void *cls, | ||
156 | const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
157 | { | ||
158 | struct PeerContext *peer = cls; | ||
159 | GNUNET_HashCode hash; | ||
160 | memset(&hash, 42, sizeof(GNUNET_HashCode)); | ||
161 | |||
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer!\n"); | ||
163 | GNUNET_assert (peer->dht_handle != NULL); | ||
164 | |||
165 | peer->find_peer_handle = GNUNET_DHT_find_peer_start(peer->dht_handle, TIMEOUT, 0, NULL, &hash, NULL, NULL, &test_find_peer_stop, &p1); | ||
166 | |||
167 | if (peer->find_peer_handle == NULL) | ||
168 | GNUNET_SCHEDULER_add_now(sched, &end_badly, &p1); | ||
169 | } | ||
126 | 170 | ||
127 | /** | 171 | /** |
128 | * Signature of the main function of a task. | 172 | * Signature of the main function of a task. |
@@ -143,11 +187,8 @@ void test_put (void *cls, | |||
143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_put!\n"); | 187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_put!\n"); |
144 | GNUNET_assert (peer->dht_handle != NULL); | 188 | GNUNET_assert (peer->dht_handle != NULL); |
145 | 189 | ||
146 | GNUNET_DHT_put(peer->dht_handle, &hash, 0, data_size, data, GNUNET_TIME_relative_to_absolute(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 360)) ,GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 360), &end, NULL); | 190 | GNUNET_DHT_put(peer->dht_handle, &hash, 0, data_size, data, GNUNET_TIME_relative_to_absolute(TIMEOUT), TIMEOUT, &test_find_peer, &p1); |
147 | 191 | ||
148 | //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1); | ||
149 | |||
150 | //GNUNET_SCHEDULER_add_now(sched, &end, NULL); | ||
151 | } | 192 | } |
152 | 193 | ||
153 | /** | 194 | /** |
@@ -160,8 +201,6 @@ void test_get_stop (void *cls, | |||
160 | const struct GNUNET_SCHEDULER_TaskContext * tc) | 201 | const struct GNUNET_SCHEDULER_TaskContext * tc) |
161 | { | 202 | { |
162 | struct PeerContext *peer = cls; | 203 | struct PeerContext *peer = cls; |
163 | GNUNET_HashCode hash; | ||
164 | memset(&hash, 42, sizeof(GNUNET_HashCode)); | ||
165 | 204 | ||
166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n"); | 205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n"); |
167 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | 206 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) |
@@ -169,10 +208,9 @@ void test_get_stop (void *cls, | |||
169 | 208 | ||
170 | GNUNET_assert (peer->dht_handle != NULL); | 209 | GNUNET_assert (peer->dht_handle != NULL); |
171 | 210 | ||
172 | GNUNET_DHT_get_stop(peer->get_handle); | 211 | GNUNET_DHT_get_stop(peer->get_handle, &test_put, &p1); |
173 | 212 | ||
174 | //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1); | 213 | //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1); |
175 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1); | ||
176 | 214 | ||
177 | } | 215 | } |
178 | 216 | ||
@@ -193,12 +231,10 @@ void test_get (void *cls, | |||
193 | peer->dht_handle = GNUNET_DHT_connect (sched, peer->cfg, 100); | 231 | peer->dht_handle = GNUNET_DHT_connect (sched, peer->cfg, 100); |
194 | GNUNET_assert (peer->dht_handle != NULL); | 232 | GNUNET_assert (peer->dht_handle != NULL); |
195 | 233 | ||
196 | peer->get_handle = GNUNET_DHT_get_start(peer->dht_handle, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100), 42, &hash, NULL, NULL, &test_get_stop, &p1); | 234 | peer->get_handle = GNUNET_DHT_get_start(peer->dht_handle, TIMEOUT, 42, &hash, NULL, NULL, &test_get_stop, &p1); |
197 | 235 | ||
198 | if (peer->get_handle == NULL) | 236 | if (peer->get_handle == NULL) |
199 | GNUNET_SCHEDULER_add_now(sched, &end_badly, &p1); | 237 | GNUNET_SCHEDULER_add_now(sched, &end_badly, &p1); |
200 | |||
201 | //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_get_stop, &p1); | ||
202 | } | 238 | } |
203 | 239 | ||
204 | static void | 240 | static void |
diff --git a/src/dht/test_dht_api_peer1.conf b/src/dht/test_dht_api_peer1.conf index 45a0adde2..b9d9ab417 100644 --- a/src/dht/test_dht_api_peer1.conf +++ b/src/dht/test_dht_api_peer1.conf | |||
@@ -31,7 +31,7 @@ ALLOW_SHUTDOWN = YES | |||
31 | ACCEPT_FROM6 = ::1; | 31 | ACCEPT_FROM6 = ::1; |
32 | ACCEPT_FROM = 127.0.0.1; | 32 | ACCEPT_FROM = 127.0.0.1; |
33 | BINARY = gnunet-service-dht | 33 | BINARY = gnunet-service-dht |
34 | #BINARY = /home/mrwiggles/documents/research/gnunet/gnunet-ng/src/dht/.libs/gnunet-service-dht | 34 | #BINARY = /root/documents/research/gnunet/gnunet-ng/src/dht/.libs/gnunet-service-dht |
35 | #PREFIX = xterm -T dvservice -e gdb --args | 35 | #PREFIX = xterm -T dvservice -e gdb --args |
36 | OPTIONS="" | 36 | OPTIONS="" |
37 | CONFIG = $DEFAULTCONFIG | 37 | CONFIG = $DEFAULTCONFIG |
@@ -39,6 +39,10 @@ HOME = $SERVICEHOME | |||
39 | HOSTNAME = localhost | 39 | HOSTNAME = localhost |
40 | PORT = 2100 | 40 | PORT = 2100 |
41 | 41 | ||
42 | [dhtcache] | ||
43 | QUOTA = 1000000 | ||
44 | DATABASE = sqlite | ||
45 | |||
42 | [hostlist] | 46 | [hostlist] |
43 | HTTP-PROXY = | 47 | HTTP-PROXY = |
44 | SERVERS = http://gnunet.org:8080/ | 48 | SERVERS = http://gnunet.org:8080/ |