diff options
Diffstat (limited to 'src/transport/transport-testing2.c')
-rw-r--r-- | src/transport/transport-testing2.c | 137 |
1 files changed, 127 insertions, 10 deletions
diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c index ff8e15719..ae5a65f2a 100644 --- a/src/transport/transport-testing2.c +++ b/src/transport/transport-testing2.c | |||
@@ -38,6 +38,9 @@ | |||
38 | #define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__) | 38 | #define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__) |
39 | 39 | ||
40 | 40 | ||
41 | /** | ||
42 | * @brief Handle to a transport communicator | ||
43 | */ | ||
41 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle | 44 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle |
42 | { | 45 | { |
43 | /** | 46 | /** |
@@ -97,12 +100,12 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle | |||
97 | char *c_address; | 100 | char *c_address; |
98 | 101 | ||
99 | /** | 102 | /** |
100 | * @brief Head of the queues | 103 | * @brief Head of the DLL of queues associated with this communicator |
101 | */ | 104 | */ |
102 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_head; | 105 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_head; |
103 | 106 | ||
104 | /** | 107 | /** |
105 | * @brief Tail of the queues | 108 | * @brief Tail of the DLL of queues associated with this communicator |
106 | */ | 109 | */ |
107 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_tail; | 110 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_tail; |
108 | 111 | ||
@@ -129,12 +132,20 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle | |||
129 | GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb; | 132 | GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb; |
130 | 133 | ||
131 | /** | 134 | /** |
135 | * @brief Callback called when a new communicator connects | ||
136 | */ | ||
137 | GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_msg_cb; | ||
138 | |||
139 | /** | ||
132 | * @brief Closure to the callback | 140 | * @brief Closure to the callback |
133 | */ | 141 | */ |
134 | void *cb_cls; | 142 | void *cb_cls; |
135 | }; | 143 | }; |
136 | 144 | ||
137 | 145 | ||
146 | /** | ||
147 | * @brief Queue of a communicator and some context | ||
148 | */ | ||
138 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue | 149 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue |
139 | { | 150 | { |
140 | /** | 151 | /** |
@@ -143,7 +154,11 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue | |||
143 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h; | 154 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h; |
144 | 155 | ||
145 | /** | 156 | /** |
146 | * @brief Task to request the opening of a view | 157 | * @brief Envelope to a message that requests the opening of the queue. |
158 | * | ||
159 | * If the client already requests queue(s), but the communicator is not yet | ||
160 | * connected, we cannot send the request to open the queue. Save it until the | ||
161 | * communicator becomes available and send it then. | ||
147 | */ | 162 | */ |
148 | struct GNUNET_MQ_Envelope *open_queue_env; | 163 | struct GNUNET_MQ_Envelope *open_queue_env; |
149 | 164 | ||
@@ -189,6 +204,9 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue | |||
189 | }; | 204 | }; |
190 | 205 | ||
191 | 206 | ||
207 | /** | ||
208 | * @brief Handle/Context to a single transmission | ||
209 | */ | ||
192 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission | 210 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission |
193 | { | 211 | { |
194 | }; | 212 | }; |
@@ -221,7 +239,9 @@ check_communicator_available ( | |||
221 | /** | 239 | /** |
222 | * @brief Handle new communicator | 240 | * @brief Handle new communicator |
223 | * | 241 | * |
224 | * @param cls Closure | 242 | * Store characteristics of communicator, call respective client callback. |
243 | * | ||
244 | * @param cls Closure - communicator handle | ||
225 | * @param msg Message struct | 245 | * @param msg Message struct |
226 | */ | 246 | */ |
227 | static void | 247 | static void |
@@ -272,6 +292,14 @@ check_add_address (void *cls, | |||
272 | } | 292 | } |
273 | 293 | ||
274 | 294 | ||
295 | /** | ||
296 | * @brief The communicator informs about an address. | ||
297 | * | ||
298 | * Store address and call client callback. | ||
299 | * | ||
300 | * @param cls Closure - communicator handle | ||
301 | * @param msg Message | ||
302 | */ | ||
275 | static void | 303 | static void |
276 | handle_add_address (void *cls, | 304 | handle_add_address (void *cls, |
277 | const struct GNUNET_TRANSPORT_AddAddressMessage *msg) | 305 | const struct GNUNET_TRANSPORT_AddAddressMessage *msg) |
@@ -297,6 +325,63 @@ handle_add_address (void *cls, | |||
297 | } | 325 | } |
298 | 326 | ||
299 | 327 | ||
328 | /** | ||
329 | * Incoming message. Test message is well-formed. | ||
330 | * | ||
331 | * @param cls the client | ||
332 | * @param msg the send message that was sent | ||
333 | * @return #GNUNET_OK if message is well-formed | ||
334 | */ | ||
335 | static int | ||
336 | check_incoming_msg (void *cls, | ||
337 | const struct GNUNET_TRANSPORT_IncomingMessage *msg) | ||
338 | { | ||
339 | //struct TransportClient *tc = cls; | ||
340 | |||
341 | //if (CT_COMMUNICATOR != tc->type) | ||
342 | //{ | ||
343 | // GNUNET_break (0); | ||
344 | // return GNUNET_SYSERR; | ||
345 | //} | ||
346 | GNUNET_MQ_check_boxed_message (msg); | ||
347 | return GNUNET_OK; | ||
348 | } | ||
349 | |||
350 | |||
351 | /** | ||
352 | * @brief Receive an incoming message. | ||
353 | * | ||
354 | * Pass the message to the client. | ||
355 | * | ||
356 | * @param cls Closure - communicator handle | ||
357 | * @param msg Message | ||
358 | */ | ||
359 | static void | ||
360 | handle_incoming_msg (void *cls, | ||
361 | const struct GNUNET_TRANSPORT_IncomingMessage *msg) | ||
362 | { | ||
363 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | ||
364 | |||
365 | if (NULL != tc_h->incoming_msg_cb) { | ||
366 | tc_h->incoming_msg_cb (tc_h->cb_cls, | ||
367 | tc_h, | ||
368 | (const struct GNUNET_MessageHeader *) msg); | ||
369 | } | ||
370 | else | ||
371 | { | ||
372 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
373 | "Incoming message from communicator but no handler!\n"); | ||
374 | } | ||
375 | GNUNET_SERVICE_client_continue (tc_h->client); | ||
376 | } | ||
377 | |||
378 | |||
379 | /** | ||
380 | * @brief Communicator informs that it tries to establish requested queue | ||
381 | * | ||
382 | * @param cls Closure - communicator handle | ||
383 | * @param msg Message | ||
384 | */ | ||
300 | static void | 385 | static void |
301 | handle_queue_create_ok (void *cls, | 386 | handle_queue_create_ok (void *cls, |
302 | const struct GNUNET_TRANSPORT_CreateQueueResponse *msg) | 387 | const struct GNUNET_TRANSPORT_CreateQueueResponse *msg) |
@@ -311,6 +396,15 @@ handle_queue_create_ok (void *cls, | |||
311 | } | 396 | } |
312 | 397 | ||
313 | 398 | ||
399 | /** | ||
400 | * @brief Communicator informs that it wont try establishing requested queue. | ||
401 | * | ||
402 | * It will not do so probably because the address is bougus (see comment to | ||
403 | * #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL) | ||
404 | * | ||
405 | * @param cls Closure - communicator handle | ||
406 | * @param msg Message | ||
407 | */ | ||
314 | static void | 408 | static void |
315 | handle_queue_create_fail ( | 409 | handle_queue_create_fail ( |
316 | void *cls, | 410 | void *cls, |
@@ -342,9 +436,11 @@ check_add_queue_message (void *cls, | |||
342 | 436 | ||
343 | 437 | ||
344 | /** | 438 | /** |
345 | * @brief Handle new communicator | 439 | * @brief Handle new queue |
346 | * | 440 | * |
347 | * @param cls Closure | 441 | * Store context and call client callback. |
442 | * | ||
443 | * @param cls Closure - communicator handle | ||
348 | * @param msg Message struct | 444 | * @param msg Message struct |
349 | */ | 445 | */ |
350 | static void | 446 | static void |
@@ -409,10 +505,13 @@ connect_cb (void *cls, | |||
409 | 505 | ||
410 | if (NULL == tc_h->queue_head) | 506 | if (NULL == tc_h->queue_head) |
411 | return tc_h; | 507 | return tc_h; |
508 | /* Iterate over queues. They are yet to be opened. Request opening. */ | ||
412 | while (NULL != (tc_queue_iter = tc_h->queue_head)) | 509 | while (NULL != (tc_queue_iter = tc_h->queue_head)) |
413 | { | 510 | { |
414 | if (NULL == tc_queue_iter->open_queue_env) | 511 | if (NULL == tc_queue_iter->open_queue_env) |
415 | continue; | 512 | continue; |
513 | /* Send the previously created mq envelope to request the creation of the | ||
514 | * queue. */ | ||
416 | GNUNET_MQ_send (tc_h->c_mq, tc_queue_iter->open_queue_env); | 515 | GNUNET_MQ_send (tc_h->c_mq, tc_queue_iter->open_queue_env); |
417 | tc_queue_iter->open_queue_env = NULL; | 516 | tc_queue_iter->open_queue_env = NULL; |
418 | } | 517 | } |
@@ -467,10 +566,10 @@ transport_communicator_start ( | |||
467 | // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, | 566 | // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, |
468 | // struct GNUNET_TRANSPORT_DelAddressMessage, | 567 | // struct GNUNET_TRANSPORT_DelAddressMessage, |
469 | // NULL), | 568 | // NULL), |
470 | //GNUNET_MQ_hd_var_size (incoming_msg, | 569 | GNUNET_MQ_hd_var_size (incoming_msg, |
471 | // GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, | 570 | GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, |
472 | // struct GNUNET_TRANSPORT_IncomingMessage, | 571 | struct GNUNET_TRANSPORT_IncomingMessage, |
473 | // NULL), | 572 | NULL), |
474 | GNUNET_MQ_hd_fixed_size (queue_create_ok, | 573 | GNUNET_MQ_hd_fixed_size (queue_create_ok, |
475 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, | 574 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, |
476 | struct GNUNET_TRANSPORT_CreateQueueResponse, | 575 | struct GNUNET_TRANSPORT_CreateQueueResponse, |
@@ -592,6 +691,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( | |||
592 | GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, | 691 | GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, |
593 | GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb, | 692 | GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb, |
594 | GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb, | 693 | GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb, |
694 | GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_message_cb, | ||
595 | void *cb_cls) | 695 | void *cb_cls) |
596 | { | 696 | { |
597 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h; | 697 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h; |
@@ -614,6 +714,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( | |||
614 | tc_h->add_address_cb = add_address_cb; | 714 | tc_h->add_address_cb = add_address_cb; |
615 | tc_h->queue_create_reply_cb = queue_create_reply_cb; | 715 | tc_h->queue_create_reply_cb = queue_create_reply_cb; |
616 | tc_h->add_queue_cb = add_queue_cb; | 716 | tc_h->add_queue_cb = add_queue_cb; |
717 | tc_h->incoming_msg_cb = incoming_message_cb; | ||
617 | tc_h->cb_cls = cb_cls; | 718 | tc_h->cb_cls = cb_cls; |
618 | 719 | ||
619 | /* Start communicator part of service */ | 720 | /* Start communicator part of service */ |
@@ -626,6 +727,13 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( | |||
626 | } | 727 | } |
627 | 728 | ||
628 | 729 | ||
730 | /** | ||
731 | * @brief Instruct communicator to open a queue | ||
732 | * | ||
733 | * @param tc_h Handle to communicator which shall open queue | ||
734 | * @param peer_id Towards which peer | ||
735 | * @param address For which address | ||
736 | */ | ||
629 | void | 737 | void |
630 | GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue ( | 738 | GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue ( |
631 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | 739 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, |
@@ -670,6 +778,15 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue ( | |||
670 | } | 778 | } |
671 | 779 | ||
672 | 780 | ||
781 | /** | ||
782 | * @brief Instruct communicator to send data | ||
783 | * | ||
784 | * @param tc_queue The queue to use for sending | ||
785 | * @param payload Data to send | ||
786 | * @param payload_size Size of the payload | ||
787 | * | ||
788 | * @return Handle to the transmission | ||
789 | */ | ||
673 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission * | 790 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission * |
674 | GNUNET_TRANSPORT_TESTING_transport_communicator_send | 791 | GNUNET_TRANSPORT_TESTING_transport_communicator_send |
675 | (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue, | 792 | (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue, |