diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/dht.h | 78 | ||||
-rw-r--r-- | src/dht/dht_api.c | 58 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht.c | 100 | ||||
-rw-r--r-- | src/dht/test_dht_api.c | 60 | ||||
-rw-r--r-- | src/dht/test_dht_api_peer1.conf | 3 |
5 files changed, 238 insertions, 61 deletions
diff --git a/src/dht/dht.h b/src/dht/dht.h index 5293bf6bd..82b0df9a2 100644 --- a/src/dht/dht.h +++ b/src/dht/dht.h | |||
@@ -33,6 +33,43 @@ typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls, | |||
33 | struct GNUNET_MessageHeader *msg); | 33 | struct GNUNET_MessageHeader *msg); |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * Generic DHT message, wrapper for other message types | ||
37 | */ | ||
38 | struct GNUNET_DHT_Message | ||
39 | { | ||
40 | /** | ||
41 | * Type: GNUNET_MESSAGE_TYPE_DHT_MESSAGE | ||
42 | */ | ||
43 | struct GNUNET_MessageHeader header; | ||
44 | |||
45 | /** | ||
46 | * The key to search for | ||
47 | */ | ||
48 | GNUNET_HashCode key; | ||
49 | |||
50 | /** | ||
51 | * Replication level for this message | ||
52 | */ | ||
53 | uint16_t desired_replication_level; | ||
54 | |||
55 | /** | ||
56 | * Message options | ||
57 | */ | ||
58 | uint16_t options; | ||
59 | |||
60 | /** | ||
61 | * Is this message uniquely identified? If so it has | ||
62 | * a unique_id appended to it. | ||
63 | */ | ||
64 | /* uint16_t unique; I don't think we need this, it should be held in the encapsulated message */ | ||
65 | |||
66 | /* uint64_t unique_id*/ | ||
67 | /* */ | ||
68 | /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */ | ||
69 | |||
70 | }; | ||
71 | |||
72 | /** | ||
36 | * Message to insert data into the DHT | 73 | * Message to insert data into the DHT |
37 | */ | 74 | */ |
38 | struct GNUNET_DHT_PutMessage | 75 | struct GNUNET_DHT_PutMessage |
@@ -48,11 +85,6 @@ struct GNUNET_DHT_PutMessage | |||
48 | size_t type; | 85 | size_t type; |
49 | 86 | ||
50 | /** | 87 | /** |
51 | * The key to insert data under. | ||
52 | */ | ||
53 | GNUNET_HashCode key; | ||
54 | |||
55 | /** | ||
56 | * The size of the data, appended to the end of this message. | 88 | * The size of the data, appended to the end of this message. |
57 | */ | 89 | */ |
58 | size_t data_size; | 90 | size_t data_size; |
@@ -60,7 +92,7 @@ struct GNUNET_DHT_PutMessage | |||
60 | /** | 92 | /** |
61 | * How long should this data persist? | 93 | * How long should this data persist? |
62 | */ | 94 | */ |
63 | struct GNUNET_TIME_Relative timeout; | 95 | struct GNUNET_TIME_Absolute expiration; |
64 | 96 | ||
65 | }; | 97 | }; |
66 | 98 | ||
@@ -115,32 +147,44 @@ struct GNUNET_DHT_GetResultMessage | |||
115 | }; | 147 | }; |
116 | 148 | ||
117 | /** | 149 | /** |
118 | * Response to PUT request from the DHT | 150 | * Message to request data from the DHT |
119 | */ | 151 | */ |
120 | struct GNUNET_DHT_PutResultMessage | 152 | struct GNUNET_DHT_FindPeerMessage |
121 | { | 153 | { |
122 | /** | 154 | /** |
123 | * Type: GNUNET_MESSAGE_TYPE_DHT_PUT_RESULT | 155 | * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER |
124 | */ | 156 | */ |
125 | struct GNUNET_MessageHeader header; | 157 | struct GNUNET_MessageHeader header; |
126 | 158 | ||
127 | /** | 159 | /** |
128 | * The type for the data for the GET request | 160 | * The key being looked up |
129 | */ | 161 | */ |
130 | size_t type; | 162 | GNUNET_HashCode key; |
163 | |||
164 | }; | ||
131 | 165 | ||
166 | /** | ||
167 | * Message to return data from the DHT | ||
168 | */ | ||
169 | struct GNUNET_DHT_FindPeerResultMessage | ||
170 | { | ||
132 | /** | 171 | /** |
133 | * The key to search for | 172 | * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT |
134 | */ | 173 | */ |
135 | GNUNET_HashCode key; | 174 | struct GNUNET_MessageHeader header; |
136 | 175 | ||
137 | /** | 176 | /** |
138 | * Was the put successful? GNUNET_YES or GNUNET_NO | 177 | * The peer that was searched for |
139 | */ | 178 | */ |
140 | size_t result; | 179 | struct GNUNET_PeerIdentity peer; |
141 | |||
142 | }; | ||
143 | 180 | ||
181 | /** | ||
182 | * The size of the HELLO for the returned peer, | ||
183 | * appended to the end of this message, 0 if | ||
184 | * no hello. | ||
185 | */ | ||
186 | size_t data_size; | ||
144 | 187 | ||
188 | }; | ||
145 | 189 | ||
146 | #endif /* DHT_H_ */ | 190 | #endif /* DHT_H_ */ |
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index db25379fa..a55508b07 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -135,11 +135,14 @@ void service_message_handler (void *cls, | |||
135 | * | 135 | * |
136 | * @param cfg configuration to use | 136 | * @param cfg configuration to use |
137 | * @param sched scheduler to use | 137 | * @param sched scheduler to use |
138 | * @param ht_len size of the internal hash table to use for | ||
139 | * processing multiple GET/FIND requests in parallel | ||
138 | * @return NULL on error | 140 | * @return NULL on error |
139 | */ | 141 | */ |
140 | struct GNUNET_DHT_Handle * | 142 | struct GNUNET_DHT_Handle * |
141 | GNUNET_DHT_connect (struct GNUNET_SCHEDULER_Handle *sched, | 143 | GNUNET_DHT_connect (struct GNUNET_SCHEDULER_Handle *sched, |
142 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 144 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
145 | unsigned int ht_len) | ||
143 | { | 146 | { |
144 | struct GNUNET_DHT_Handle *handle; | 147 | struct GNUNET_DHT_Handle *handle; |
145 | 148 | ||
@@ -233,6 +236,11 @@ struct GNUNET_DHT_GetHandle | |||
233 | * Closure for the iterator callback | 236 | * Closure for the iterator callback |
234 | */ | 237 | */ |
235 | void *iter_cls; | 238 | void *iter_cls; |
239 | |||
240 | /** | ||
241 | * Main handle to this DHT api | ||
242 | */ | ||
243 | struct GNUNET_DHT_Handle *dht_handle; | ||
236 | }; | 244 | }; |
237 | 245 | ||
238 | /** | 246 | /** |
@@ -303,7 +311,6 @@ static size_t | |||
303 | transmit_pending (void *cls, size_t size, void *buf) | 311 | transmit_pending (void *cls, size_t size, void *buf) |
304 | { | 312 | { |
305 | struct GNUNET_DHT_Handle *handle = cls; | 313 | struct GNUNET_DHT_Handle *handle = cls; |
306 | size_t ret; | ||
307 | size_t tsize; | 314 | size_t tsize; |
308 | 315 | ||
309 | if (buf == NULL) | 316 | if (buf == NULL) |
@@ -318,7 +325,6 @@ transmit_pending (void *cls, size_t size, void *buf) | |||
318 | } | 325 | } |
319 | 326 | ||
320 | handle->th = NULL; | 327 | handle->th = NULL; |
321 | ret = 0; | ||
322 | 328 | ||
323 | if (handle->current != NULL) | 329 | if (handle->current != NULL) |
324 | { | 330 | { |
@@ -330,14 +336,15 @@ transmit_pending (void *cls, size_t size, void *buf) | |||
330 | "`%s': Sending message size %d\n", "DHT API", tsize); | 336 | "`%s': Sending message size %d\n", "DHT API", tsize); |
331 | #endif | 337 | #endif |
332 | memcpy(buf, handle->current->msg, tsize); | 338 | memcpy(buf, handle->current->msg, tsize); |
339 | return tsize; | ||
333 | } | 340 | } |
334 | else | 341 | else |
335 | { | 342 | { |
336 | return ret; | 343 | return 0; |
337 | } | 344 | } |
338 | } | 345 | } |
339 | 346 | /* Have no pending request */ | |
340 | return ret; | 347 | return 0; |
341 | } | 348 | } |
342 | 349 | ||
343 | 350 | ||
@@ -483,6 +490,10 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, | |||
483 | get_handle->iter = iter; | 490 | get_handle->iter = iter; |
484 | get_handle->iter_cls = iter_cls; | 491 | get_handle->iter_cls = iter_cls; |
485 | 492 | ||
493 | #if DEBUG_DHT_API | ||
494 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
495 | "`%s': Inserting pending get request with key %s\n", "DHT API", GNUNET_h2s(key)); | ||
496 | #endif | ||
486 | GNUNET_CONTAINER_multihashmap_put(handle->outstanding_get_requests, key, get_handle, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 497 | GNUNET_CONTAINER_multihashmap_put(handle->outstanding_get_requests, key, get_handle, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
487 | 498 | ||
488 | get_msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_GetMessage)); | 499 | get_msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_GetMessage)); |
@@ -503,9 +514,10 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, | |||
503 | * @param record GET operation to stop. | 514 | * @param record GET operation to stop. |
504 | */ | 515 | */ |
505 | void | 516 | void |
506 | GNUNET_DHT_get_stop (struct GNUNET_DHT_Handle *handle, struct GNUNET_DHT_GetHandle *get_handle) | 517 | GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle) |
507 | { | 518 | { |
508 | struct GNUNET_DHT_GetMessage *get_msg; | 519 | struct GNUNET_DHT_GetMessage *get_msg; |
520 | struct GNUNET_DHT_Handle *handle; | ||
509 | 521 | ||
510 | if (handle->do_destroy == GNUNET_NO) | 522 | if (handle->do_destroy == GNUNET_NO) |
511 | { | 523 | { |
@@ -517,7 +529,10 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_Handle *handle, struct GNUNET_DHT_GetHand | |||
517 | 529 | ||
518 | add_pending(handle, &get_msg->header); | 530 | add_pending(handle, &get_msg->header); |
519 | } | 531 | } |
520 | 532 | #if DEBUG_DHT_API | |
533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
534 | "`%s': Removing pending get request with key %s\n", "DHT API", GNUNET_h2s(&get_handle->key)); | ||
535 | #endif | ||
521 | GNUNET_assert(GNUNET_CONTAINER_multihashmap_remove(handle->outstanding_get_requests, &get_handle->key, get_handle) == GNUNET_YES); | 536 | GNUNET_assert(GNUNET_CONTAINER_multihashmap_remove(handle->outstanding_get_requests, &get_handle->key, get_handle) == GNUNET_YES); |
522 | GNUNET_free(get_handle); | 537 | GNUNET_free(get_handle); |
523 | } | 538 | } |
@@ -539,14 +554,16 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_Handle *handle, struct GNUNET_DHT_GetHand | |||
539 | * | 554 | * |
540 | * @return GNUNET_YES if put message is queued for transmission | 555 | * @return GNUNET_YES if put message is queued for transmission |
541 | */ | 556 | */ |
542 | int GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, | 557 | void |
543 | const GNUNET_HashCode * key, | 558 | GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, |
544 | uint32_t type, | 559 | const GNUNET_HashCode * key, |
545 | uint32_t size, | 560 | uint32_t type, |
546 | const char *data, | 561 | uint32_t size, |
547 | struct GNUNET_TIME_Relative exp, | 562 | const char *data, |
548 | GNUNET_SCHEDULER_Task cont, | 563 | struct GNUNET_TIME_Absolute exp, |
549 | void *cont_cls) | 564 | struct GNUNET_TIME_Relative timeout, |
565 | GNUNET_SCHEDULER_Task cont, | ||
566 | void *cont_cls) | ||
550 | { | 567 | { |
551 | struct GNUNET_DHT_PutMessage *put_msg; | 568 | struct GNUNET_DHT_PutMessage *put_msg; |
552 | struct GNUNET_DHT_PutHandle *put_handle; | 569 | struct GNUNET_DHT_PutHandle *put_handle; |
@@ -560,13 +577,18 @@ int GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, | |||
560 | * A put has been previously queued, but not yet sent. | 577 | * A put has been previously queued, but not yet sent. |
561 | * FIXME: change the continuation function and callback or something? | 578 | * FIXME: change the continuation function and callback or something? |
562 | */ | 579 | */ |
563 | return GNUNET_NO; | 580 | return; |
564 | } | 581 | } |
565 | 582 | ||
566 | put_handle = GNUNET_malloc(sizeof(struct GNUNET_DHT_PutHandle)); | 583 | put_handle = GNUNET_malloc(sizeof(struct GNUNET_DHT_PutHandle)); |
567 | put_handle->type = type; | 584 | put_handle->type = type; |
568 | memcpy(&put_handle->key, key, sizeof(GNUNET_HashCode)); | 585 | memcpy(&put_handle->key, key, sizeof(GNUNET_HashCode)); |
569 | 586 | ||
587 | #if DEBUG_DHT_API | ||
588 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
589 | "`%s': Inserting pending put request with key %s\n", "DHT API", GNUNET_h2s(key)); | ||
590 | #endif | ||
591 | |||
570 | GNUNET_CONTAINER_multihashmap_put(handle->outstanding_put_requests, key, put_handle, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 592 | GNUNET_CONTAINER_multihashmap_put(handle->outstanding_put_requests, key, put_handle, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
571 | 593 | ||
572 | msize = sizeof(struct GNUNET_DHT_PutMessage) + size; | 594 | msize = sizeof(struct GNUNET_DHT_PutMessage) + size; |
@@ -579,5 +601,5 @@ int GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, | |||
579 | 601 | ||
580 | add_pending(handle, &put_msg->header); | 602 | add_pending(handle, &put_msg->header); |
581 | 603 | ||
582 | return GNUNET_YES; | 604 | return; |
583 | } | 605 | } |
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 3dcb75353..5bbb2e739 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -167,13 +167,23 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { | |||
167 | * Server handler for initiating local dht get requests | 167 | * Server handler for initiating local dht get requests |
168 | */ | 168 | */ |
169 | static void handle_dht_get (void *cls, struct GNUNET_SERVER_Client * client, | 169 | static void handle_dht_get (void *cls, struct GNUNET_SERVER_Client * client, |
170 | const struct GNUNET_MessageHeader *message) | 170 | const struct GNUNET_MessageHeader *message) |
171 | { | 171 | { |
172 | struct GNUNET_DHT_GetMessage *get_msg = (struct GNUNET_DHT_GetMessage *)message; | ||
173 | GNUNET_HashCode get_key; | ||
174 | size_t get_type; | ||
175 | |||
176 | GNUNET_assert(ntohs(get_msg->header.size) >= sizeof(struct GNUNET_DHT_GetMessage)); | ||
177 | memcpy(&get_key, &get_msg->key, sizeof(GNUNET_HashCode)); | ||
178 | get_type = ntohs(get_msg->type); | ||
179 | |||
172 | #if DEBUG_DHT | 180 | #if DEBUG_DHT |
173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
174 | "`%s': Received `%s' request from client\n", "DHT", "GET"); | 182 | "`%s': Received `%s' request from client, message type %d, key %s\n", "DHT", "GET", get_type, GNUNET_h2s(&get_key)); |
175 | #endif | 183 | #endif |
176 | 184 | ||
185 | /* FIXME: Implement get stop functionality here */ | ||
186 | |||
177 | } | 187 | } |
178 | 188 | ||
179 | /** | 189 | /** |
@@ -182,25 +192,43 @@ static void handle_dht_get (void *cls, struct GNUNET_SERVER_Client * client, | |||
182 | static void handle_dht_get_stop (void *cls, struct GNUNET_SERVER_Client * client, | 192 | static void handle_dht_get_stop (void *cls, struct GNUNET_SERVER_Client * client, |
183 | const struct GNUNET_MessageHeader *message) | 193 | const struct GNUNET_MessageHeader *message) |
184 | { | 194 | { |
195 | struct GNUNET_DHT_GetMessage *get_msg = (struct GNUNET_DHT_GetMessage *)message; /* Get message and get stop message are the same except for type */ | ||
196 | GNUNET_HashCode get_key; | ||
197 | size_t get_type; | ||
198 | |||
199 | GNUNET_assert(ntohs(get_msg->header.size) >= sizeof(struct GNUNET_DHT_GetMessage)); | ||
200 | |||
201 | memcpy(&get_key, &get_msg->key, sizeof(GNUNET_HashCode)); | ||
202 | get_type = ntohs(get_msg->type); | ||
203 | |||
185 | #if DEBUG_DHT | 204 | #if DEBUG_DHT |
186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
187 | "`%s': Received `%s' request from client\n", "DHT", "GET STOP"); | 206 | "`%s': Received `%s' request from client, message type %d, key %s\n", "DHT", "GET STOP", get_type, GNUNET_h2s(&get_key)); |
188 | #endif | 207 | #endif |
189 | 208 | ||
209 | /* FIXME: Implement get stop functionality here */ | ||
210 | |||
190 | } | 211 | } |
191 | 212 | ||
192 | /** | 213 | /** |
193 | * Server handler for initiating local dht find peer requests | 214 | * Server handler for initiating local dht find peer requests |
194 | */ | 215 | */ |
195 | static void handle_dht_find_peer (void *cls, struct GNUNET_SERVER_Client * | 216 | static void handle_dht_find_peer (void *cls, struct GNUNET_SERVER_Client * |
196 | client, const struct GNUNET_MessageHeader * | 217 | client, const struct GNUNET_MessageHeader * |
197 | message) | 218 | message) |
198 | { | 219 | { |
220 | struct GNUNET_DHT_FindPeerMessage *find_msg = (struct GNUNET_DHT_FindPeerMessage *)message; | ||
221 | struct GNUNET_PeerIdentity peer; | ||
222 | |||
223 | GNUNET_assert(ntohs(find_msg->header.size) == sizeof(struct GNUNET_DHT_FindPeerMessage)); | ||
224 | memcpy(&peer, &find_msg->peer, sizeof(struct GNUNET_PeerIdentity)); | ||
225 | |||
199 | #if DEBUG_DHT | 226 | #if DEBUG_DHT |
200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 227 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
201 | "`%s': Received `%s' request from client\n", "DHT", "FIND PEER"); | 228 | "`%s': Received `%s' request from client, peer id %s\n", "DHT", "FIND PEER", GNUNET_i2s(&peer)); |
202 | #endif | 229 | #endif |
203 | 230 | ||
231 | /* FIXME: Implement find peer functionality here */ | ||
204 | } | 232 | } |
205 | 233 | ||
206 | /** | 234 | /** |
@@ -210,11 +238,19 @@ static void handle_dht_find_peer_stop (void *cls, struct GNUNET_SERVER_Client * | |||
210 | client, const struct GNUNET_MessageHeader * | 238 | client, const struct GNUNET_MessageHeader * |
211 | message) | 239 | message) |
212 | { | 240 | { |
241 | struct GNUNET_DHT_FindPeerMessage *find_msg = (struct GNUNET_DHT_FindPeerMessage *)message; /* Find peer stop message is identical to find peer message */ | ||
242 | struct GNUNET_PeerIdentity peer; | ||
243 | |||
244 | GNUNET_assert(ntohs(find_msg->header.size) == sizeof(struct GNUNET_DHT_FindPeerMessage)); | ||
245 | memcpy(&peer, &find_msg->peer, sizeof(struct GNUNET_PeerIdentity)); | ||
246 | |||
213 | #if DEBUG_DHT | 247 | #if DEBUG_DHT |
214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
215 | "`%s': Received `%s' request from client\n", "DHT", "FIND PEER STOP"); | 249 | "`%s': Received `%s' request from client, for peer id %s\n", "DHT", "FIND PEER STOP", GNUNET_i2s(&peer)); |
216 | #endif | 250 | #endif |
217 | 251 | ||
252 | /* FIXME: Implement find peer stop functionality here */ | ||
253 | |||
218 | } | 254 | } |
219 | 255 | ||
220 | /** | 256 | /** |
@@ -223,21 +259,42 @@ static void handle_dht_find_peer_stop (void *cls, struct GNUNET_SERVER_Client * | |||
223 | static void handle_dht_put (void *cls, struct GNUNET_SERVER_Client * client, | 259 | static void handle_dht_put (void *cls, struct GNUNET_SERVER_Client * client, |
224 | const struct GNUNET_MessageHeader *message) | 260 | const struct GNUNET_MessageHeader *message) |
225 | { | 261 | { |
262 | struct GNUNET_DHT_PutMessage *put_msg = (struct GNUNET_DHT_PutMessage *)message; | ||
263 | GNUNET_HashCode put_key; | ||
264 | size_t put_type; | ||
265 | size_t data_size; | ||
266 | char *data; | ||
267 | |||
268 | GNUNET_assert(ntohs(put_msg->header.size) >= sizeof(struct GNUNET_DHT_PutMessage)); | ||
269 | |||
270 | memcpy(&put_key, &put_msg->key, sizeof(GNUNET_HashCode)); | ||
271 | put_type = ntohs(put_msg->type); | ||
272 | data_size = ntohs(put_msg->data_size); | ||
273 | GNUNET_assert(ntohs(put_msg->header.size) == sizeof(struct GNUNET_DHT_PutMessage) + data_size); | ||
274 | data = GNUNET_malloc(data_size); | ||
275 | memcpy(data, &put_msg[1], data_size); | ||
276 | |||
226 | #if DEBUG_DHT | 277 | #if DEBUG_DHT |
227 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 278 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
228 | "`%s': Received `%s' request from client\n", "DHT", "PUT"); | 279 | "`%s': Received `%s' request from client, message type %d, key %s\n", "DHT", "PUT", put_type, GNUNET_h2s(&put_key)); |
229 | #endif | 280 | #endif |
230 | 281 | ||
282 | /** | ||
283 | * FIXME: Implement dht put request functionality here! | ||
284 | */ | ||
285 | |||
286 | GNUNET_free(data); | ||
287 | |||
231 | } | 288 | } |
232 | 289 | ||
233 | /** | 290 | /** |
234 | * Core handler for p2p dht get requests. | 291 | * Core handler for p2p dht get requests. |
235 | */ | 292 | */ |
236 | static int handle_dht_p2p_get (void *cls, | 293 | static int handle_dht_p2p_get (void *cls, |
237 | const struct GNUNET_PeerIdentity * peer, | 294 | const struct GNUNET_PeerIdentity * peer, |
238 | const struct GNUNET_MessageHeader * message, | 295 | const struct GNUNET_MessageHeader * message, |
239 | struct GNUNET_TIME_Relative latency, | 296 | struct GNUNET_TIME_Relative latency, |
240 | uint32_t distance) | 297 | uint32_t distance) |
241 | { | 298 | { |
242 | #if DEBUG_DHT | 299 | #if DEBUG_DHT |
243 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -340,23 +397,22 @@ run (void *cls, | |||
340 | GNUNET_SERVER_add_handlers (server, plugin_handlers); | 397 | GNUNET_SERVER_add_handlers (server, plugin_handlers); |
341 | 398 | ||
342 | coreAPI = | 399 | coreAPI = |
343 | GNUNET_CORE_connect (sched, | 400 | GNUNET_CORE_connect (sched, /* Main scheduler */ |
344 | cfg, | 401 | cfg, /* Main configuration */ |
345 | client_transmit_timeout, | 402 | client_transmit_timeout, /* Delay for connecting */ |
346 | NULL, /* FIXME: anything we want to pass around? */ | 403 | NULL, /* FIXME: anything we want to pass around? */ |
347 | &core_init, | 404 | &core_init, /* Call core_init once connected */ |
348 | NULL, /* Don't care about pre-connects */ | 405 | NULL, /* Don't care about pre-connects */ |
349 | NULL, /* Don't care about connects */ | 406 | NULL, /* Don't care about connects */ |
350 | NULL, /* Don't care about disconnects */ | 407 | NULL, /* Don't care about disconnects */ |
351 | NULL, | 408 | NULL, /* Don't want notified about all incoming messages */ |
352 | GNUNET_NO, | 409 | GNUNET_NO, /* For header only inbound notification */ |
353 | NULL, | 410 | NULL, /* Don't want notified about all outbound messages */ |
354 | GNUNET_NO, | 411 | GNUNET_NO, /* For header only outbound notification */ |
355 | core_handlers); | 412 | core_handlers); /* Register these handlers */ |
356 | 413 | ||
357 | if (coreAPI == NULL) | 414 | if (coreAPI == NULL) |
358 | return; | 415 | return; |
359 | /* load (server); Huh? */ | ||
360 | 416 | ||
361 | /* Scheduled the task to clean up when shutdown is called */ | 417 | /* Scheduled the task to clean up when shutdown is called */ |
362 | cleanup_task = GNUNET_SCHEDULER_add_delayed (sched, | 418 | cleanup_task = GNUNET_SCHEDULER_add_delayed (sched, |
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index 9c9fcb4d0..8092d7b2e 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c | |||
@@ -51,6 +51,9 @@ 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_GetHandle *get_handle; | ||
55 | struct GNUNET_DHT_GetHandle *find_peer_handle; | ||
56 | |||
54 | #if START_ARM | 57 | #if START_ARM |
55 | pid_t arm_pid; | 58 | pid_t arm_pid; |
56 | #endif | 59 | #endif |
@@ -110,6 +113,54 @@ end_badly () | |||
110 | return; | 113 | return; |
111 | } | 114 | } |
112 | 115 | ||
116 | |||
117 | /** | ||
118 | * Signature of the main function of a task. | ||
119 | * | ||
120 | * @param cls closure | ||
121 | * @param tc context information (why was this task triggered now) | ||
122 | */ | ||
123 | void test_put (void *cls, | ||
124 | const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
125 | { | ||
126 | struct PeerContext *peer = cls; | ||
127 | GNUNET_HashCode hash; | ||
128 | char *data; | ||
129 | size_t data_size = 42; | ||
130 | memset(&hash, 42, sizeof(GNUNET_HashCode)); | ||
131 | data = GNUNET_malloc(data_size); | ||
132 | memset(data, 43, data_size); | ||
133 | |||
134 | GNUNET_assert (peer->dht_handle != NULL); | ||
135 | |||
136 | GNUNET_DHT_put(peer->dht_handle, &hash, 0, data_size, data, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 360), NULL, NULL); | ||
137 | |||
138 | //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1); | ||
139 | |||
140 | GNUNET_SCHEDULER_add_now(sched, &end, NULL); | ||
141 | } | ||
142 | |||
143 | /** | ||
144 | * Signature of the main function of a task. | ||
145 | * | ||
146 | * @param cls closure | ||
147 | * @param tc context information (why was this task triggered now) | ||
148 | */ | ||
149 | void test_get_stop (void *cls, | ||
150 | const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
151 | { | ||
152 | struct PeerContext *peer = cls; | ||
153 | GNUNET_HashCode hash; | ||
154 | memset(&hash, 42, sizeof(GNUNET_HashCode)); | ||
155 | |||
156 | GNUNET_assert (peer->dht_handle != NULL); | ||
157 | |||
158 | GNUNET_DHT_get_stop(peer->dht_handle, peer->get_handle); | ||
159 | |||
160 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1); | ||
161 | |||
162 | } | ||
163 | |||
113 | /** | 164 | /** |
114 | * Signature of the main function of a task. | 165 | * Signature of the main function of a task. |
115 | * | 166 | * |
@@ -126,9 +177,12 @@ void test_get (void *cls, | |||
126 | peer->dht_handle = GNUNET_DHT_connect (sched, peer->cfg); | 177 | peer->dht_handle = GNUNET_DHT_connect (sched, peer->cfg); |
127 | GNUNET_assert (peer->dht_handle != NULL); | 178 | GNUNET_assert (peer->dht_handle != NULL); |
128 | 179 | ||
129 | GNUNET_DHT_get_start(peer->dht_handle, 42, &hash, NULL, NULL); | 180 | peer->get_handle = GNUNET_DHT_get_start(peer->dht_handle, 42, &hash, NULL, NULL); |
181 | |||
182 | if (peer->get_handle == NULL) | ||
183 | GNUNET_SCHEDULER_add_now(sched, &end_badly, &p1); | ||
130 | 184 | ||
131 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &end, &p1); | 185 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_get_stop, &p1); |
132 | } | 186 | } |
133 | 187 | ||
134 | static void | 188 | static void |
@@ -162,7 +216,7 @@ run (void *cls, | |||
162 | 216 | ||
163 | setup_peer (&p1, "test_dht_api_peer1.conf"); | 217 | setup_peer (&p1, "test_dht_api_peer1.conf"); |
164 | 218 | ||
165 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &test_get, &p1); | 219 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_get, &p1); |
166 | } | 220 | } |
167 | 221 | ||
168 | static int | 222 | static int |
diff --git a/src/dht/test_dht_api_peer1.conf b/src/dht/test_dht_api_peer1.conf index 5eb4079f4..1c5dced26 100644 --- a/src/dht/test_dht_api_peer1.conf +++ b/src/dht/test_dht_api_peer1.conf | |||
@@ -31,8 +31,9 @@ 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 = /root/documents/research/gnunet/gnunet-ng/src/dht/.libs/gnunet-service-dht | 34 | #BINARY = /home/mrwiggles/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 | CONFIG = $DEFAULTCONFIG | 37 | CONFIG = $DEFAULTCONFIG |
37 | HOME = $SERVICEHOME | 38 | HOME = $SERVICEHOME |
38 | HOSTNAME = localhost | 39 | HOSTNAME = localhost |