2 This file is part of GNUnet.
3 Copyright (C) 2019 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file transport/transport-testing2.c
23 * @brief functions related to testing-tng
24 * @author Christian Grothoff
25 * @author Julius Bünger
28 #include "gnunet_util_lib.h"
29 #include "gnunet_protocols.h"
30 #include "gnunet_constants.h"
31 #include "transport-testing2.h"
32 #include "gnunet_ats_transport_service.h"
33 #include "gnunet_hello_lib.h"
34 #include "gnunet_signatures.h"
35 #include "transport.h"
38 #define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__)
42 * @brief Handle to a transport communicator
44 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
47 * @brief Handle to the configuration
49 struct GNUNET_CONFIGURATION_Handle *cfg;
52 * @brief File name of configuration file
57 * @brief Handle to the transport service
59 struct GNUNET_SERVICE_Handle *tsh;
62 * @brief Task that will be run on shutdown to stop and clean transport
65 struct GNUNET_SCHEDULER_Task *ts_shutdown_task;
68 * @brief Handle to the client
70 struct GNUNET_SERVICE_Client *client;
73 * @brief Handle to the client
75 struct GNUNET_MQ_Handle *c_mq;
78 * @brief Process of the communicator
80 struct GNUNET_OS_Process *c_proc;
85 struct GNUNET_OS_Process *nat_proc;
88 * @brief Task that will be run on shutdown to stop and clean communicator
90 struct GNUNET_SCHEDULER_Task *c_shutdown_task;
93 * @brief Characteristics of the communicator
95 enum GNUNET_TRANSPORT_CommunicatorCharacteristics c_characteristics;
98 * @brief Specifies supported addresses
103 * @brief Specifies supported addresses
108 * @brief Head of the DLL of queues associated with this communicator
110 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_head;
113 * @brief Tail of the DLL of queues associated with this communicator
115 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_tail;
117 /* Callbacks + Closures */
119 * @brief Callback called when a new communicator connects
121 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback
122 communicator_available_cb;
125 * @brief Callback called when a new communicator connects
127 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb;
130 * @brief Callback called when a new communicator connects
132 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb;
135 * @brief Callback called when a new communicator connects
137 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb;
140 * @brief Callback called when a new communicator connects
142 GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_msg_cb;
145 * @brief Backchannel callback
147 GNUNET_TRANSPORT_TESTING_BackchannelCallback bc_cb;
152 struct GNUNET_SERVICE_Handle *sh;
155 * @brief Closure to the callback
160 * Backchannel supported
167 * @brief Queue of a communicator and some context
169 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
172 * @brief Handle to the TransportCommunicator
174 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h;
177 * @brief Envelope to a message that requests the opening of the queue.
179 * If the client already requests queue(s), but the communicator is not yet
180 * connected, we cannot send the request to open the queue. Save it until the
181 * communicator becomes available and send it then.
183 struct GNUNET_MQ_Envelope *open_queue_env;
186 * @brief Peer ID of the peer on the other side of the queue
188 struct GNUNET_PeerIdentity peer_id;
196 * @brief Current message id
201 * An `enum GNUNET_NetworkType` in NBO.
206 * Maximum transmission unit, in NBO. UINT32_MAX for unlimited.
211 * An `enum GNUNET_TRANSPORT_ConnectionStatus` in NBO.
216 * @brief Next element inside a DLL
218 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *next;
221 * @brief Previous element inside a DLL
223 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *prev;
228 * @brief Handle/Context to a single transmission
230 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission
236 * @brief Check whether incoming msg indicating available communicator is
240 * @param msg Message struct
242 * @return GNUNET_YES in case message is correct
245 check_communicator_available (
247 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
251 size = ntohs (msg->header.size) - sizeof(*msg);
253 return GNUNET_OK; /* receive-only communicator */
254 GNUNET_MQ_check_zero_termination (msg);
260 * @brief Handle new communicator
262 * Store characteristics of communicator, call respective client callback.
264 * @param cls Closure - communicator handle
265 * @param msg Message struct
268 handle_communicator_available (
270 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
272 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
275 size = ntohs (msg->header.size) - sizeof(*msg);
277 return; /* receive-only communicator */
278 tc_h->c_characteristics = ntohl (msg->cc);
279 tc_h->c_addr_prefix = GNUNET_strdup ((const char *) &msg[1]);
280 if (NULL != tc_h->communicator_available_cb)
282 LOG (GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available_cb()\n");
283 tc_h->communicator_available_cb (tc_h->cb_cls,
285 tc_h->c_characteristics,
286 tc_h->c_addr_prefix);
288 GNUNET_SERVICE_client_continue (tc_h->client);
293 * Incoming message. Test message is well-formed.
295 * @param cls the client
296 * @param msg the send message that was sent
297 * @return #GNUNET_OK if message is well-formed
300 check_communicator_backchannel (void *cls,
302 GNUNET_TRANSPORT_CommunicatorBackchannel *msg)
304 // struct TransportClient *tc = cls;
306 // if (CT_COMMUNICATOR != tc->type)
309 // return GNUNET_SYSERR;
311 // GNUNET_MQ_check_boxed_message (msg);
317 * @brief Receive an incoming message.
319 * Pass the message to the client.
321 * @param cls Closure - communicator handle
325 handle_communicator_backchannel (void *cls,
327 GNUNET_TRANSPORT_CommunicatorBackchannel *
330 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
331 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *other_tc_h;
332 struct GNUNET_MessageHeader *msg;
333 msg = (struct GNUNET_MessageHeader *) &bc_msg[1];
334 uint16_t isize = ntohs (msg->size);
335 const char *target_communicator = ((const char *) msg) + isize;
336 struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *cbi;
337 struct GNUNET_MQ_Envelope *env;
340 if (tc_h->bc_enabled != GNUNET_YES)
342 GNUNET_SERVICE_client_continue (tc_h->client);
345 /* Find client providing this communicator */
346 /* Finally, deliver backchannel message to communicator */
347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
348 "Delivering backchannel message of type %u to %s\n",
350 target_communicator);
351 other_tc_h = tc_h->bc_cb (tc_h, msg, (struct
352 GNUNET_PeerIdentity*) &bc_msg->pid);
353 env = GNUNET_MQ_msg_extra (
356 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING);
357 cbi->pid = bc_msg->pid;
358 memcpy (&cbi[1], msg, isize);
361 GNUNET_MQ_send (other_tc_h->c_mq, env);
362 GNUNET_SERVICE_client_continue (tc_h->client);
367 * Address of our peer added. Test message is well-formed.
369 * @param cls the client
370 * @param aam the send message that was sent
371 * @return #GNUNET_OK if message is well-formed
374 check_add_address (void *cls,
375 const struct GNUNET_TRANSPORT_AddAddressMessage *msg)
377 // if (CT_COMMUNICATOR != tc->type)
380 // return GNUNET_SYSERR;
382 GNUNET_MQ_check_zero_termination (msg);
388 * @brief The communicator informs about an address.
390 * Store address and call client callback.
392 * @param cls Closure - communicator handle
396 handle_add_address (void *cls,
397 const struct GNUNET_TRANSPORT_AddAddressMessage *msg)
399 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
401 size = ntohs (msg->header.size) - sizeof(*msg);
403 return; /* receive-only communicator */
404 LOG (GNUNET_ERROR_TYPE_DEBUG, "received add address cb %u\n", size);
405 tc_h->c_address = GNUNET_strdup ((const char *) &msg[1]);
406 if (NULL != tc_h->add_address_cb)
408 LOG (GNUNET_ERROR_TYPE_DEBUG, "calling add_address_cb()\n");
409 tc_h->add_address_cb (tc_h->cb_cls,
412 GNUNET_TIME_relative_ntoh (msg->expiration),
416 GNUNET_SERVICE_client_continue (tc_h->client);
421 * Incoming message. Test message is well-formed.
423 * @param cls the client
424 * @param msg the send message that was sent
425 * @return #GNUNET_OK if message is well-formed
428 check_incoming_msg (void *cls,
429 const struct GNUNET_TRANSPORT_IncomingMessage *msg)
431 // struct TransportClient *tc = cls;
433 // if (CT_COMMUNICATOR != tc->type)
436 // return GNUNET_SYSERR;
438 GNUNET_MQ_check_boxed_message (msg);
444 * @brief Receive an incoming message.
446 * Pass the message to the client.
448 * @param cls Closure - communicator handle
452 handle_incoming_msg (void *cls,
453 const struct GNUNET_TRANSPORT_IncomingMessage *inc_msg)
455 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
456 struct GNUNET_MessageHeader *msg;
457 msg = (struct GNUNET_MessageHeader *) &inc_msg[1];
458 size_t payload_len = ntohs (msg->size) - sizeof (struct
459 GNUNET_MessageHeader);
460 LOG (GNUNET_ERROR_TYPE_DEBUG,
461 "Incoming message from communicator!\n");
463 if (NULL != tc_h->incoming_msg_cb)
465 tc_h->incoming_msg_cb (tc_h->cb_cls,
472 LOG (GNUNET_ERROR_TYPE_WARNING,
473 "Incoming message from communicator but no handler!\n");
475 if (GNUNET_YES == ntohl (inc_msg->fc_on))
477 /* send ACK when done to communicator for flow control! */
478 struct GNUNET_MQ_Envelope *env;
479 struct GNUNET_TRANSPORT_IncomingMessageAck *ack;
481 env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK);
482 ack->reserved = htonl (0);
483 ack->fc_id = inc_msg->fc_id;
484 ack->sender = inc_msg->sender;
485 GNUNET_MQ_send (tc_h->c_mq, env);
488 GNUNET_SERVICE_client_continue (tc_h->client);
493 * @brief Communicator informs that it tries to establish requested queue
495 * @param cls Closure - communicator handle
499 handle_queue_create_ok (void *cls,
500 const struct GNUNET_TRANSPORT_CreateQueueResponse *msg)
502 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
504 if (NULL != tc_h->queue_create_reply_cb)
506 tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_YES);
508 GNUNET_SERVICE_client_continue (tc_h->client);
513 * @brief Communicator informs that it wont try establishing requested queue.
515 * It will not do so probably because the address is bougus (see comment to
516 * #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL)
518 * @param cls Closure - communicator handle
522 handle_queue_create_fail (
524 const struct GNUNET_TRANSPORT_CreateQueueResponse *msg)
526 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
528 if (NULL != tc_h->queue_create_reply_cb)
530 tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_NO);
532 GNUNET_SERVICE_client_continue (tc_h->client);
537 * New queue became available. Check message.
539 * @param cls the client
540 * @param aqm the send message that was sent
543 check_add_queue_message (void *cls,
544 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm)
546 GNUNET_MQ_check_zero_termination (aqm);
552 * @brief Handle new queue
554 * Store context and call client callback.
556 * @param cls Closure - communicator handle
557 * @param msg Message struct
560 handle_add_queue_message (void *cls,
561 const struct GNUNET_TRANSPORT_AddQueueMessage *msg)
563 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
564 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue;
566 tc_queue = tc_h->queue_head;
567 if (NULL != tc_queue)
569 while (tc_queue->qid != msg->qid)
571 tc_queue = tc_queue->next;
577 GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue);
578 tc_queue->tc_h = tc_h;
579 tc_queue->qid = msg->qid;
580 tc_queue->peer_id = msg->receiver;
581 GNUNET_CONTAINER_DLL_insert (tc_h->queue_head, tc_h->queue_tail, tc_queue);
583 GNUNET_assert (tc_queue->qid == msg->qid);
584 GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver));
585 tc_queue->nt = msg->nt;
586 tc_queue->mtu = msg->mtu;
587 tc_queue->cs = msg->cs;
588 if (NULL != tc_h->add_queue_cb)
590 tc_h->add_queue_cb (tc_h->cb_cls, tc_h, tc_queue);
592 GNUNET_SERVICE_client_continue (tc_h->client);
597 * @brief Shut down the service
599 * @param cls Closure - Handle to the service
602 shutdown_service (void *cls)
604 struct GNUNET_SERVICE_Handle *h = cls;
606 GNUNET_SERVICE_stop (h);
611 * @brief Callback called when new Client (Communicator) connects
613 * @param cls Closure - TransporCommmunicator Handle
614 * @param client Client
615 * @param mq Messagequeue
617 * @return TransportCommunicator Handle
620 connect_cb (void *cls,
621 struct GNUNET_SERVICE_Client *client,
622 struct GNUNET_MQ_Handle *mq)
624 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
626 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client connected.\n");
627 tc_h->client = client;
630 if (NULL == tc_h->queue_head)
632 /* Iterate over queues. They are yet to be opened. Request opening. */
634 GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_iter =
636 NULL != tc_queue_iter;
637 tc_queue_iter = tc_queue_iter->next)
639 if (NULL == tc_queue_iter->open_queue_env)
641 /* Send the previously created mq envelope to request the creation of the
643 GNUNET_MQ_send (tc_h->c_mq,
644 tc_queue_iter->open_queue_env);
645 tc_queue_iter->open_queue_env = NULL;
652 * @brief Callback called when Client disconnects
654 * @param cls Closure - TransportCommunicator Handle
655 * @param client Client
656 * @param internal_cls TransporCommmunicator Handle
659 disconnect_cb (void *cls,
660 struct GNUNET_SERVICE_Client *client,
663 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
665 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected.\n");
671 * Message was transmitted. Process the request.
673 * @param cls the client
674 * @param sma the send message that was sent
677 handle_send_message_ack (void *cls,
678 const struct GNUNET_TRANSPORT_SendMessageToAck *sma)
680 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
681 GNUNET_SERVICE_client_continue (tc_h->client);
687 * @brief Start the communicator part of the transport service
689 * @param communicator_available Callback to be called when a new communicator
691 * @param cfg Configuration
694 transport_communicator_start (
695 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
697 struct GNUNET_MQ_MessageHandler mh[] = {
698 GNUNET_MQ_hd_var_size (communicator_available,
699 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR,
700 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage,
702 GNUNET_MQ_hd_var_size (communicator_backchannel,
703 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL,
704 struct GNUNET_TRANSPORT_CommunicatorBackchannel,
706 GNUNET_MQ_hd_var_size (add_address,
707 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS,
708 struct GNUNET_TRANSPORT_AddAddressMessage,
710 // GNUNET_MQ_hd_fixed_size (del_address,
711 // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS,
712 // struct GNUNET_TRANSPORT_DelAddressMessage,
714 GNUNET_MQ_hd_var_size (incoming_msg,
715 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG,
716 struct GNUNET_TRANSPORT_IncomingMessage,
718 GNUNET_MQ_hd_fixed_size (queue_create_ok,
719 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK,
720 struct GNUNET_TRANSPORT_CreateQueueResponse,
722 GNUNET_MQ_hd_fixed_size (queue_create_fail,
723 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL,
724 struct GNUNET_TRANSPORT_CreateQueueResponse,
726 GNUNET_MQ_hd_var_size (add_queue_message,
727 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP,
728 struct GNUNET_TRANSPORT_AddQueueMessage,
730 // GNUNET_MQ_hd_fixed_size (del_queue_message,
731 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN,
732 // struct GNUNET_TRANSPORT_DelQueueMessage,
734 GNUNET_MQ_hd_fixed_size (send_message_ack,
735 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK,
736 struct GNUNET_TRANSPORT_SendMessageToAck,
738 GNUNET_MQ_handler_end ()
742 tc_h->sh = GNUNET_SERVICE_start ("transport",
748 GNUNET_assert (NULL != tc_h->sh);
753 * @brief Task run at shutdown to kill communicator and clean up
755 * @param cls Closure - Process of communicator
758 shutdown_process (struct GNUNET_OS_Process *proc)
760 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
762 LOG (GNUNET_ERROR_TYPE_WARNING,
763 "Error shutting down communicator with SIGERM, trying SIGKILL\n");
764 if (0 != GNUNET_OS_process_kill (proc, SIGKILL))
766 LOG (GNUNET_ERROR_TYPE_ERROR,
767 "Error shutting down communicator with SIGERM and SIGKILL\n");
770 GNUNET_OS_process_destroy (proc);
775 shutdown_communicator (void *cls)
777 struct GNUNET_OS_Process *proc = cls;
778 shutdown_process (proc);
783 * @brief Start the communicator
785 * @param cfgname Name of the communicator
789 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
790 const char *binary_name)
794 LOG (GNUNET_ERROR_TYPE_DEBUG, "communicator_start\n");
795 binary = GNUNET_OS_get_libexec_binary_path (binary_name);
796 tc_h->c_proc = GNUNET_OS_start_process (GNUNET_YES,
797 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
806 if (NULL == tc_h->c_proc)
808 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start communicator!");
811 LOG (GNUNET_ERROR_TYPE_INFO, "started communicator\n");
812 GNUNET_free (binary);
817 * @brief Task run at shutdown to kill communicator and clean up
819 * @param cls Closure - Process of communicator
822 shutdown_nat (void *cls)
824 struct GNUNET_OS_Process *proc = cls;
825 shutdown_process (proc);
835 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
839 LOG (GNUNET_ERROR_TYPE_DEBUG, "nat_start\n");
840 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-nat");
841 tc_h->nat_proc = GNUNET_OS_start_process (GNUNET_YES,
842 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
847 "gnunet-service-nat",
851 if (NULL == tc_h->nat_proc)
853 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start NAT!");
856 LOG (GNUNET_ERROR_TYPE_INFO, "started NAT\n");
857 GNUNET_free (binary);
862 do_shutdown (void *cls)
864 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
865 shutdown_communicator (tc_h->c_proc);
866 shutdown_service (tc_h->sh);
867 shutdown_nat (tc_h->nat_proc);
872 * @brief Start communicator part of transport service and communicator
874 * @param service_name Name of the service
875 * @param cfg Configuration handle
876 * @param communicator_available_cb Callback that is called when a new
877 * @param add_address_cb Callback that is called when a new
878 * communicator becomes available
879 * @param cb_cls Closure to @a communicator_available_cb and @a
881 * @return Handle to the communicator duo
883 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
884 GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
885 const char *service_name,
886 const char *binary_name,
887 const char *cfg_filename,
888 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback
889 communicator_available_cb,
890 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb,
891 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb,
892 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb,
893 GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_message_cb,
894 GNUNET_TRANSPORT_TESTING_BackchannelCallback bc_cb,
897 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h;
900 GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle);
901 tc_h->cfg_filename = GNUNET_strdup (cfg_filename);
902 tc_h->cfg = GNUNET_CONFIGURATION_create ();
903 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_load (tc_h->cfg, cfg_filename)))
905 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
906 _ ("Malformed configuration file `%s', exit ...\n"),
908 GNUNET_free (tc_h->cfg_filename);
909 GNUNET_CONFIGURATION_destroy (tc_h->cfg);
913 tc_h->bc_enabled = GNUNET_CONFIGURATION_get_value_yesno (tc_h->cfg,
915 "BACKCHANNEL_ENABLED");
916 tc_h->communicator_available_cb = communicator_available_cb;
917 tc_h->add_address_cb = add_address_cb;
918 tc_h->queue_create_reply_cb = queue_create_reply_cb;
919 tc_h->add_queue_cb = add_queue_cb;
920 tc_h->incoming_msg_cb = incoming_message_cb;
922 tc_h->cb_cls = cb_cls;
924 /* Start communicator part of service */
925 transport_communicator_start (tc_h);
928 /* Schedule start communicator */
929 communicator_start (tc_h,
931 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, tc_h);
937 * @brief Instruct communicator to open a queue
939 * @param tc_h Handle to communicator which shall open queue
940 * @param peer_id Towards which peer
941 * @param address For which address
944 GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (
945 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
946 const struct GNUNET_PeerIdentity *peer_id,
949 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue;
950 static uint32_t idgen;
952 struct GNUNET_TRANSPORT_CreateQueue *msg;
953 struct GNUNET_MQ_Envelope *env;
957 GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue);
958 tc_queue->tc_h = tc_h;
959 prefix = GNUNET_HELLO_address_to_prefix (address);
962 GNUNET_break (0); /* We got an invalid address!? */
963 GNUNET_free (tc_queue);
966 GNUNET_free (prefix);
967 alen = strlen (address) + 1;
969 GNUNET_MQ_msg_extra (msg, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE);
970 msg->request_id = htonl (idgen++);
971 tc_queue->qid = msg->request_id;
972 msg->receiver = *peer_id;
973 tc_queue->peer_id = *peer_id;
974 memcpy (&msg[1], address, alen);
975 if (NULL != tc_h->c_mq)
977 GNUNET_MQ_send (tc_h->c_mq, env);
981 tc_queue->open_queue_env = env;
983 GNUNET_CONTAINER_DLL_insert (tc_h->queue_head, tc_h->queue_tail, tc_queue);
988 * @brief Instruct communicator to send data
990 * @param tc_queue The queue to use for sending
991 * @param payload Data to send
992 * @param payload_size Size of the payload
994 * @return Handle to the transmission
996 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *
997 GNUNET_TRANSPORT_TESTING_transport_communicator_send
998 (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue,
1000 size_t payload_size)
1002 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *tc_t;
1003 struct GNUNET_MessageHeader *mh;
1004 struct GNUNET_TRANSPORT_SendMessageTo *msg;
1005 struct GNUNET_MQ_Envelope *env;
1008 inbox_size = sizeof(struct GNUNET_MessageHeader) + payload_size;
1009 mh = GNUNET_malloc (inbox_size);
1010 mh->size = htons (inbox_size);
1011 mh->type = GNUNET_MESSAGE_TYPE_DUMMY;
1015 env = GNUNET_MQ_msg_extra (msg,
1017 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG);
1018 msg->qid = htonl (tc_queue->qid);
1019 msg->mid = tc_queue->mid++;
1020 msg->receiver = tc_queue->peer_id;
1021 memcpy (&msg[1], mh, inbox_size);
1023 GNUNET_MQ_send (tc_queue->tc_h->c_mq, env);
1024 // GNUNET_assert (0); // FIXME: not iplemented!