aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport-testing2.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport-testing2.c')
-rw-r--r--src/transport/transport-testing2.c280
1 files changed, 247 insertions, 33 deletions
diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c
index 51791e981..9fa6b7761 100644
--- a/src/transport/transport-testing2.c
+++ b/src/transport/transport-testing2.c
@@ -30,6 +30,7 @@
30#include "gnunet_constants.h" 30#include "gnunet_constants.h"
31#include "transport-testing2.h" 31#include "transport-testing2.h"
32#include "gnunet_ats_transport_service.h" 32#include "gnunet_ats_transport_service.h"
33#include "gnunet_hello_lib.h"
33#include "gnunet_signatures.h" 34#include "gnunet_signatures.h"
34#include "transport.h" 35#include "transport.h"
35 36
@@ -66,6 +67,11 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
66 struct GNUNET_SERVICE_Client *client; 67 struct GNUNET_SERVICE_Client *client;
67 68
68 /** 69 /**
70 * @brief Handle to the client
71 */
72 struct GNUNET_MQ_Handle *c_mq;
73
74 /**
69 * @brief Process of the communicator 75 * @brief Process of the communicator
70 */ 76 */
71 struct GNUNET_OS_Process *c_proc; 77 struct GNUNET_OS_Process *c_proc;
@@ -75,16 +81,51 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
75 */ 81 */
76 struct GNUNET_SCHEDULER_Task *c_shutdown_task; 82 struct GNUNET_SCHEDULER_Task *c_shutdown_task;
77 83
84 /**
85 * @brief Characteristics of the communicator
86 */
87 enum GNUNET_TRANSPORT_CommunicatorCharacteristics c_characteristics;
88
89 /**
90 * @brief Specifies supported addresses
91 */
92 char *c_addr_prefix;
93
94 /**
95 * @brief Specifies supported addresses
96 */
97 char *c_address;
98
99 /**
100 * @brief Task to request the opening of a view
101 */
102 struct GNUNET_MQ_Envelope *open_queue_env;
103
78 /* Callbacks + Closures */ 104 /* Callbacks + Closures */
79 /** 105 /**
80 * @brief Callback called when a new communicator connects 106 * @brief Callback called when a new communicator connects
81 */ 107 */
82 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available; 108 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available_cb;
109
110 /**
111 * @brief Callback called when a new communicator connects
112 */
113 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb;
114
115 /**
116 * @brief Callback called when a new communicator connects
117 */
118 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb;
119
120 /**
121 * @brief Callback called when a new communicator connects
122 */
123 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb;
83 124
84 /** 125 /**
85 * @brief Closure to the callback 126 * @brief Closure to the callback
86 */ 127 */
87 void *communicator_available_cls; 128 void *cb_cls;
88}; 129};
89 130
90 131
@@ -127,11 +168,133 @@ handle_communicator_available (void *cls,
127 size = ntohs (msg->header.size) - sizeof (*msg); 168 size = ntohs (msg->header.size) - sizeof (*msg);
128 if (0 == size) 169 if (0 == size)
129 return; /* receive-only communicator */ 170 return; /* receive-only communicator */
130 if (NULL != tc_h->communicator_available) 171 tc_h->c_characteristics = ntohl (msg->cc);
172 tc_h->c_addr_prefix = GNUNET_strdup ((const char *) &msg[1]);
173 if (NULL != tc_h->communicator_available_cb)
174 {
175 LOG (GNUNET_ERROR_TYPE_DEBUG,
176 "calling communicator_available_cb()\n");
177 tc_h->communicator_available_cb (tc_h->cb_cls,
178 tc_h,
179 tc_h->c_characteristics,
180 tc_h->c_addr_prefix);
181 }
182 GNUNET_SERVICE_client_continue (tc_h->client);
183}
184
185
186/**
187 * Address of our peer added. Test message is well-formed.
188 *
189 * @param cls the client
190 * @param aam the send message that was sent
191 * @return #GNUNET_OK if message is well-formed
192 */
193static int
194check_add_address (void *cls,
195 const struct GNUNET_TRANSPORT_AddAddressMessage *msg)
196{
197 struct TransportClient *tc = cls;
198
199 //if (CT_COMMUNICATOR != tc->type)
200 //{
201 // GNUNET_break (0);
202 // return GNUNET_SYSERR;
203 //}
204 GNUNET_MQ_check_zero_termination (msg);
205 return GNUNET_OK;
206}
207
208
209static void
210handle_add_address (void *cls,
211 const struct GNUNET_TRANSPORT_AddAddressMessage *msg)
212{
213 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
214 uint16_t size;
215
216 size = ntohs (msg->header.size) - sizeof (*msg);
217 if (0 == size)
218 return; /* receive-only communicator */
219 tc_h->c_address = GNUNET_strdup ((const char *) &msg[1]);
220 if (NULL != tc_h->add_address_cb)
131 { 221 {
132 LOG (GNUNET_ERROR_TYPE_DEBUG, 222 LOG (GNUNET_ERROR_TYPE_DEBUG,
133 "calling communicator_available()\n"); 223 "calling communicator_available()\n");
134 tc_h->communicator_available (tc_h->communicator_available_cls, msg); 224 tc_h->add_address_cb (tc_h->cb_cls,
225 tc_h,
226 tc_h->c_address,
227 GNUNET_TIME_relative_ntoh (msg->expiration),
228 msg->aid,
229 ntohl (msg->nt));
230 }
231 GNUNET_SERVICE_client_continue (tc_h->client);
232}
233
234
235static void
236handle_queue_create_ok (void *cls,
237 const struct GNUNET_TRANSPORT_CreateQueueResponse *msg)
238{
239 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
240
241 if (NULL != tc_h->queue_create_reply_cb)
242 {
243 tc_h->queue_create_reply_cb (tc_h->cb_cls,
244 tc_h,
245 GNUNET_YES);
246 }
247 GNUNET_SERVICE_client_continue (tc_h->client);
248}
249
250
251static void
252handle_queue_create_fail (void *cls,
253 const struct GNUNET_TRANSPORT_CreateQueueResponse *msg)
254{
255 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
256
257 if (NULL != tc_h->queue_create_reply_cb)
258 {
259 tc_h->queue_create_reply_cb (tc_h->cb_cls,
260 tc_h,
261 GNUNET_NO);
262 }
263 GNUNET_SERVICE_client_continue (tc_h->client);
264}
265
266
267/**
268 * New queue became available. Check message.
269 *
270 * @param cls the client
271 * @param aqm the send message that was sent
272 */
273static int
274check_add_queue_message (void *cls,
275 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm)
276{
277 GNUNET_MQ_check_zero_termination (aqm);
278 return GNUNET_OK;
279}
280
281
282/**
283 * @brief Handle new communicator
284 *
285 * @param cls Closure
286 * @param msg Message struct
287 */
288static void
289handle_add_queue_message (void *cls,
290 const struct GNUNET_TRANSPORT_AddQueueMessage *msg)
291{
292 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
293
294 if (NULL != tc_h->add_queue_cb)
295 {
296 tc_h->add_queue_cb (tc_h->cb_cls,
297 tc_h);
135 } 298 }
136 GNUNET_SERVICE_client_continue (tc_h->client); 299 GNUNET_SERVICE_client_continue (tc_h->client);
137} 300}
@@ -170,6 +333,14 @@ connect_cb (void *cls,
170 LOG (GNUNET_ERROR_TYPE_DEBUG, 333 LOG (GNUNET_ERROR_TYPE_DEBUG,
171 "Client connected.\n"); 334 "Client connected.\n");
172 tc_h->client = client; 335 tc_h->client = client;
336 tc_h->c_mq = mq;
337
338 if (NULL != tc_h->open_queue_env)
339 {
340 GNUNET_MQ_send (tc_h->c_mq,
341 tc_h->open_queue_env);
342 tc_h->open_queue_env = NULL;
343 }
173 return tc_h; 344 return tc_h;
174} 345}
175 346
@@ -213,10 +384,10 @@ transport_communicator_start (struct GNUNET_TRANSPORT_TESTING_TransportCommunica
213 // GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, 384 // GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL,
214 // struct GNUNET_TRANSPORT_CommunicatorBackchannel, 385 // struct GNUNET_TRANSPORT_CommunicatorBackchannel,
215 // NULL), 386 // NULL),
216 //GNUNET_MQ_hd_var_size (add_address, 387 GNUNET_MQ_hd_var_size (add_address,
217 // GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, 388 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS,
218 // struct GNUNET_TRANSPORT_AddAddressMessage, 389 struct GNUNET_TRANSPORT_AddAddressMessage,
219 // NULL), 390 &tc_h),
220 //GNUNET_MQ_hd_fixed_size (del_address, 391 //GNUNET_MQ_hd_fixed_size (del_address,
221 // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, 392 // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS,
222 // struct GNUNET_TRANSPORT_DelAddressMessage, 393 // struct GNUNET_TRANSPORT_DelAddressMessage,
@@ -225,18 +396,18 @@ transport_communicator_start (struct GNUNET_TRANSPORT_TESTING_TransportCommunica
225 // GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, 396 // GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG,
226 // struct GNUNET_TRANSPORT_IncomingMessage, 397 // struct GNUNET_TRANSPORT_IncomingMessage,
227 // NULL), 398 // NULL),
228 //GNUNET_MQ_hd_fixed_size (queue_create_ok, 399 GNUNET_MQ_hd_fixed_size (queue_create_ok,
229 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, 400 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK,
230 // struct GNUNET_TRANSPORT_CreateQueueResponse, 401 struct GNUNET_TRANSPORT_CreateQueueResponse,
231 // NULL), 402 tc_h),
232 //GNUNET_MQ_hd_fixed_size (queue_create_fail, 403 GNUNET_MQ_hd_fixed_size (queue_create_fail,
233 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, 404 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL,
234 // struct GNUNET_TRANSPORT_CreateQueueResponse, 405 struct GNUNET_TRANSPORT_CreateQueueResponse,
235 // NULL), 406 tc_h),
236 //GNUNET_MQ_hd_var_size (add_queue_message, 407 GNUNET_MQ_hd_var_size (add_queue_message,
237 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, 408 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP,
238 // struct GNUNET_TRANSPORT_AddQueueMessage, 409 struct GNUNET_TRANSPORT_AddQueueMessage,
239 // NULL), 410 NULL),
240 //GNUNET_MQ_hd_fixed_size (del_queue_message, 411 //GNUNET_MQ_hd_fixed_size (del_queue_message,
241 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, 412 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN,
242 // struct GNUNET_TRANSPORT_DelQueueMessage, 413 // struct GNUNET_TRANSPORT_DelQueueMessage,
@@ -333,9 +504,10 @@ communicator_start (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
333 * 504 *
334 * @param service_name Name of the service 505 * @param service_name Name of the service
335 * @param cfg Configuration handle 506 * @param cfg Configuration handle
336 * @param communicator_available Callback that is called when a new 507 * @param communicator_available_cb Callback that is called when a new
508 * @param add_address_cb Callback that is called when a new
337 * communicator becomes available 509 * communicator becomes available
338 * @param cb_cls Closure to @p communicator_available 510 * @param cb_cls Closure to @a communicator_available_cb and @a
339 * 511 *
340 * @return Handle to the communicator duo 512 * @return Handle to the communicator duo
341 */ 513 */
@@ -343,10 +515,10 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
343GNUNET_TRANSPORT_TESTING_transport_communicator_service_start 515GNUNET_TRANSPORT_TESTING_transport_communicator_service_start
344 (const char *service_name, 516 (const char *service_name,
345 const char *cfg_filename, 517 const char *cfg_filename,
346 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available, 518 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available_cb,
347 //GNUNET_TRANSPORT_TESTING_Callback2 cb2, 519 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb,
348 //GNUNET_TRANSPORT_TESTING_Callback3 cb3, 520 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb,
349 //GNUNET_TRANSPORT_TESTING_Callback4 cb4, 521 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb,
350 void *cb_cls) 522 void *cb_cls)
351{ 523{
352 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h; 524 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h;
@@ -363,8 +535,11 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start
363 cfg_filename); 535 cfg_filename);
364 return NULL; 536 return NULL;
365 } 537 }
366 tc_h->communicator_available = communicator_available; 538 tc_h->communicator_available_cb = communicator_available_cb;
367 tc_h->communicator_available_cls = cb_cls; 539 tc_h->add_address_cb = add_address_cb;
540 tc_h->queue_create_reply_cb = queue_create_reply_cb;
541 tc_h->add_queue_cb = add_queue_cb;
542 tc_h->cb_cls = cb_cls;
368 543
369 /* Start communicator part of service */ 544 /* Start communicator part of service */
370 transport_communicator_start (tc_h); 545 transport_communicator_start (tc_h);
@@ -374,11 +549,50 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start
374 return tc_h; 549 return tc_h;
375} 550}
376 551
377//void 552
378//GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue 553void
379// (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tch, 554GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue
380// const char *address); 555 (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
381// 556 const struct GNUNET_PeerIdentity *peer_id,
557 const char *address)
558{
559 static uint32_t idgen;
560 char *prefix;
561 struct GNUNET_TRANSPORT_CreateQueue *msg;
562 struct GNUNET_MQ_Envelope *env;
563 size_t alen;
564
565 if (NULL != tc_h->open_queue_env)
566 {
567 // FIXME: handle multiple queue requests
568 return; /* Already waiting for opening of queue */
569 }
570 prefix = GNUNET_HELLO_address_to_prefix (address);
571 if (NULL == prefix)
572 {
573 GNUNET_break (0); /* We got an invalid address!? */
574 return;
575 }
576 alen = strlen (address) + 1;
577 env = GNUNET_MQ_msg_extra (msg,
578 alen,
579 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE);
580 msg->request_id = htonl (idgen++);
581 msg->receiver = *peer_id;
582 memcpy (&msg[1],
583 address,
584 alen);
585 if (NULL != tc_h->c_mq)
586 {
587 GNUNET_MQ_send (tc_h->c_mq,
588 env);
589 }
590 else
591 {
592 tc_h->open_queue_env = env;
593 }
594}
595
382//struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission * 596//struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *
383//GNUNET_TRANSPORT_TESTING_transport_communicator_send 597//GNUNET_TRANSPORT_TESTING_transport_communicator_send
384// (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tcq, 598// (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tcq,