diff options
-rw-r--r-- | src/transport/test_communicator_unix.c | 79 | ||||
-rw-r--r-- | src/transport/transport-testing2.c | 280 | ||||
-rw-r--r-- | src/transport/transport-testing2.h | 43 |
3 files changed, 352 insertions, 50 deletions
diff --git a/src/transport/test_communicator_unix.c b/src/transport/test_communicator_unix.c index fd189659c..64ba1d5f5 100644 --- a/src/transport/test_communicator_unix.c +++ b/src/transport/test_communicator_unix.c | |||
@@ -30,6 +30,8 @@ | |||
30 | #include "gnunet_signatures.h" | 30 | #include "gnunet_signatures.h" |
31 | #include "transport.h" | 31 | #include "transport.h" |
32 | 32 | ||
33 | #include <inttypes.h> | ||
34 | |||
33 | /** | 35 | /** |
34 | * TODO | 36 | * TODO |
35 | * - start two communicators | 37 | * - start two communicators |
@@ -45,28 +47,91 @@ | |||
45 | 47 | ||
46 | #define LOG(kind,...) GNUNET_log_from (kind, "test_transport_communicator_unix", __VA_ARGS__) | 48 | #define LOG(kind,...) GNUNET_log_from (kind, "test_transport_communicator_unix", __VA_ARGS__) |
47 | 49 | ||
50 | #define NUM_PEERS 2 | ||
51 | |||
52 | static struct GNUNET_PeerIdentity peer_id[NUM_PEERS]; | ||
53 | |||
54 | static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_hs[NUM_PEERS]; | ||
55 | |||
56 | //static char *addresses[NUM_PEERS]; | ||
57 | |||
58 | static void | ||
59 | communicator_available_cb (void *cls, | ||
60 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | ||
61 | enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, | ||
62 | char *address_prefix) | ||
63 | { | ||
64 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
65 | "Communicator available. (cc: %u, prefix: %s)\n", | ||
66 | cc, | ||
67 | address_prefix); | ||
68 | } | ||
69 | |||
70 | |||
71 | static void | ||
72 | add_address_cb (void *cls, | ||
73 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | ||
74 | const char *address, | ||
75 | struct GNUNET_TIME_Relative expiration, | ||
76 | uint32_t aid, | ||
77 | enum GNUNET_NetworkType nt) | ||
78 | { | ||
79 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
80 | "New address. (addr: %s, expir: %" PRIu32 ", ID: %" PRIu32 ", nt: %u\n", | ||
81 | address, | ||
82 | expiration.rel_value_us, | ||
83 | aid, | ||
84 | nt); | ||
85 | //addresses[1] = GNUNET_strdup (address); | ||
86 | GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (tc_hs[0], | ||
87 | &peer_id[1], | ||
88 | address); | ||
89 | } | ||
90 | |||
91 | |||
92 | static void | ||
93 | queue_create_reply_cb (void *cls, | ||
94 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | ||
95 | int success) | ||
96 | { | ||
97 | if (GNUNET_YES == success) | ||
98 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
99 | "Got Queue!\n"); | ||
100 | else | ||
101 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
102 | "Failed getting queue!\n"); | ||
103 | } | ||
104 | |||
105 | |||
48 | static void | 106 | static void |
49 | communicator_available (void *cls, | 107 | add_queue_cb (void *cls, |
50 | const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) | 108 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) |
51 | { | 109 | { |
52 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 110 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
53 | "communicator_available()\n"); | 111 | "Got Queue!\n"); |
54 | } | 112 | } |
55 | 113 | ||
114 | |||
56 | static void | 115 | static void |
57 | run (void *cls) | 116 | run (void *cls) |
58 | { | 117 | { |
59 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 118 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
60 | 119 | ||
61 | GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( | 120 | tc_hs[0] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( |
62 | "transport", | 121 | "transport", |
63 | "test_communicator_1.conf", | 122 | "test_communicator_1.conf", |
64 | &communicator_available, | 123 | &communicator_available_cb, |
124 | NULL, | ||
125 | &queue_create_reply_cb, | ||
126 | &add_queue_cb, | ||
65 | NULL); /* cls */ | 127 | NULL); /* cls */ |
66 | GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( | 128 | tc_hs[1] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( |
67 | "transport", | 129 | "transport", |
68 | "test_communicator_2.conf", | 130 | "test_communicator_2.conf", |
69 | &communicator_available, | 131 | &communicator_available_cb, |
132 | &add_address_cb, | ||
133 | NULL, | ||
134 | &add_queue_cb, | ||
70 | NULL); /* cls */ | 135 | NULL); /* cls */ |
71 | } | 136 | } |
72 | 137 | ||
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 | */ | ||
193 | static int | ||
194 | check_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 | |||
209 | static void | ||
210 | handle_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 | |||
235 | static void | ||
236 | handle_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 | |||
251 | static void | ||
252 | handle_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 | */ | ||
273 | static int | ||
274 | check_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 | */ | ||
288 | static void | ||
289 | handle_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 * | |||
343 | GNUNET_TRANSPORT_TESTING_transport_communicator_service_start | 515 | GNUNET_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 | 553 | void |
379 | // (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tch, | 554 | GNUNET_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, |
diff --git a/src/transport/transport-testing2.h b/src/transport/transport-testing2.h index c5adda4eb..6aee919cd 100644 --- a/src/transport/transport-testing2.h +++ b/src/transport/transport-testing2.h | |||
@@ -40,7 +40,29 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle; | |||
40 | */ | 40 | */ |
41 | typedef void | 41 | typedef void |
42 | (*GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback)(void *cls, | 42 | (*GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback)(void *cls, |
43 | const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg); | 43 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, |
44 | enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, | ||
45 | char *address_prefix); | ||
46 | |||
47 | |||
48 | typedef void | ||
49 | (*GNUNET_TRANSPORT_TESTING_AddAddressCallback)(void *cls, | ||
50 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | ||
51 | const char *address, | ||
52 | struct GNUNET_TIME_Relative expiration, | ||
53 | uint32_t aid, | ||
54 | enum GNUNET_NetworkType nt); | ||
55 | |||
56 | |||
57 | typedef void | ||
58 | (*GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback)(void *cls, | ||
59 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | ||
60 | int will_try); | ||
61 | |||
62 | |||
63 | typedef void | ||
64 | (*GNUNET_TRANSPORT_TESTING_AddQueueCallback)(void *cls, | ||
65 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h); | ||
44 | 66 | ||
45 | 67 | ||
46 | /** | 68 | /** |
@@ -58,17 +80,18 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * | |||
58 | GNUNET_TRANSPORT_TESTING_transport_communicator_service_start | 80 | GNUNET_TRANSPORT_TESTING_transport_communicator_service_start |
59 | (const char *service_name, | 81 | (const char *service_name, |
60 | const char *cfg_filename, | 82 | const char *cfg_filename, |
61 | GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available, | 83 | GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available_cb, |
62 | //GNUNET_TRANSPORT_TESTING_Callback2 cb2, | 84 | GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, |
63 | //GNUNET_TRANSPORT_TESTING_Callback3 cb3, | 85 | GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb, |
64 | //GNUNET_TRANSPORT_TESTING_Callback4 cb4, | 86 | GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb, |
65 | void *cb_cls); | 87 | void *cb_cls); |
66 | 88 | ||
67 | //void | 89 | void |
68 | //GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue | 90 | GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue |
69 | // (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tch, | 91 | (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, |
70 | // const char *address); | 92 | const struct GNUNET_PeerIdentity *peer_id, |
71 | // | 93 | const char *address); |
94 | |||
72 | //struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission * | 95 | //struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission * |
73 | //GNUNET_TRANSPORT_TESTING_transport_communicator_send | 96 | //GNUNET_TRANSPORT_TESTING_transport_communicator_send |
74 | // (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tcq, | 97 | // (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tcq, |