aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/transport/test_communicator_unix.c3
-rw-r--r--src/transport/transport-testing2.c137
-rw-r--r--src/transport/transport-testing2.h19
3 files changed, 135 insertions, 24 deletions
diff --git a/src/transport/test_communicator_unix.c b/src/transport/test_communicator_unix.c
index 64ba1d5f5..e52391ef2 100644
--- a/src/transport/test_communicator_unix.c
+++ b/src/transport/test_communicator_unix.c
@@ -105,7 +105,8 @@ queue_create_reply_cb (void *cls,
105 105
106static void 106static void
107add_queue_cb (void *cls, 107add_queue_cb (void *cls,
108 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) 108 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
109 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue)
109{ 110{
110 LOG (GNUNET_ERROR_TYPE_DEBUG, 111 LOG (GNUNET_ERROR_TYPE_DEBUG,
111 "Got Queue!\n"); 112 "Got Queue!\n");
diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c
index 9fa6b7761..2abe6c9ce 100644
--- a/src/transport/transport-testing2.c
+++ b/src/transport/transport-testing2.c
@@ -97,9 +97,14 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
97 char *c_address; 97 char *c_address;
98 98
99 /** 99 /**
100 * @brief Task to request the opening of a view 100 * @brief Head of the queues
101 */ 101 */
102 struct GNUNET_MQ_Envelope *open_queue_env; 102 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_head;
103
104 /**
105 * @brief Tail of the queues
106 */
107 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *queue_tail;
103 108
104 /* Callbacks + Closures */ 109 /* Callbacks + Closures */
105 /** 110 /**
@@ -129,6 +134,65 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
129}; 134};
130 135
131 136
137struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
138{
139 /**
140 * @brief Handle to the TransportCommunicator
141 */
142 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h;
143
144 /**
145 * @brief Task to request the opening of a view
146 */
147 struct GNUNET_MQ_Envelope *open_queue_env;
148
149 /**
150 * @brief Peer ID of the peer on the other side of the queue
151 */
152 struct GNUNET_PeerIdentity peer_id;
153
154 /**
155 * @brief Queue ID
156 */
157 uint32_t qid;
158
159 /**
160 * @brief Current message id
161 */
162 uint64_t mid;
163
164 /**
165 * An `enum GNUNET_NetworkType` in NBO.
166 */
167 uint32_t nt;
168
169 /**
170 * Maximum transmission unit, in NBO. UINT32_MAX for unlimited.
171 */
172 uint32_t mtu;
173
174 /**
175 * An `enum GNUNET_TRANSPORT_ConnectionStatus` in NBO.
176 */
177 uint32_t cs;
178
179 /**
180 * @brief Next element inside a DLL
181 */
182 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *next;
183
184 /**
185 * @brief Previous element inside a DLL
186 */
187 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *prev;
188};
189
190
191struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission
192{
193};
194
195
132/** 196/**
133 * @brief Check whether incoming msg indicating available communicator is 197 * @brief Check whether incoming msg indicating available communicator is
134 * correct 198 * correct
@@ -290,11 +354,24 @@ handle_add_queue_message (void *cls,
290 const struct GNUNET_TRANSPORT_AddQueueMessage *msg) 354 const struct GNUNET_TRANSPORT_AddQueueMessage *msg)
291{ 355{
292 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 356 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
357 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue;
293 358
359 tc_queue = tc_h->queue_head;
360 while (tc_queue->qid != msg->qid)
361 {
362 tc_queue = tc_queue->next;
363 }
364 GNUNET_assert (tc_queue->qid == msg->qid);
365 GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id,
366 &msg->receiver));
367 tc_queue->nt = msg->nt;
368 tc_queue->mtu = msg->mtu;
369 tc_queue->cs = msg->cs;
294 if (NULL != tc_h->add_queue_cb) 370 if (NULL != tc_h->add_queue_cb)
295 { 371 {
296 tc_h->add_queue_cb (tc_h->cb_cls, 372 tc_h->add_queue_cb (tc_h->cb_cls,
297 tc_h); 373 tc_h,
374 tc_queue);
298 } 375 }
299 GNUNET_SERVICE_client_continue (tc_h->client); 376 GNUNET_SERVICE_client_continue (tc_h->client);
300} 377}
@@ -329,17 +406,20 @@ connect_cb (void *cls,
329 struct GNUNET_MQ_Handle *mq) 406 struct GNUNET_MQ_Handle *mq)
330{ 407{
331 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 408 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
409 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_iter;
332 410
333 LOG (GNUNET_ERROR_TYPE_DEBUG, 411 LOG (GNUNET_ERROR_TYPE_DEBUG,
334 "Client connected.\n"); 412 "Client connected.\n");
335 tc_h->client = client; 413 tc_h->client = client;
336 tc_h->c_mq = mq; 414 tc_h->c_mq = mq;
337 415
338 if (NULL != tc_h->open_queue_env) 416 if (NULL == tc_h->queue_head) return tc_h;
417 while (NULL != (tc_queue_iter = tc_h->queue_head))
339 { 418 {
419 if (NULL == tc_queue_iter->open_queue_env) continue;
340 GNUNET_MQ_send (tc_h->c_mq, 420 GNUNET_MQ_send (tc_h->c_mq,
341 tc_h->open_queue_env); 421 tc_queue_iter->open_queue_env);
342 tc_h->open_queue_env = NULL; 422 tc_queue_iter->open_queue_env = NULL;
343 } 423 }
344 return tc_h; 424 return tc_h;
345} 425}
@@ -556,17 +636,14 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue
556 const struct GNUNET_PeerIdentity *peer_id, 636 const struct GNUNET_PeerIdentity *peer_id,
557 const char *address) 637 const char *address)
558{ 638{
639 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue;
559 static uint32_t idgen; 640 static uint32_t idgen;
560 char *prefix; 641 char *prefix;
561 struct GNUNET_TRANSPORT_CreateQueue *msg; 642 struct GNUNET_TRANSPORT_CreateQueue *msg;
562 struct GNUNET_MQ_Envelope *env; 643 struct GNUNET_MQ_Envelope *env;
563 size_t alen; 644 size_t alen;
564 645
565 if (NULL != tc_h->open_queue_env) 646 tc_queue = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue);
566 {
567 // FIXME: handle multiple queue requests
568 return; /* Already waiting for opening of queue */
569 }
570 prefix = GNUNET_HELLO_address_to_prefix (address); 647 prefix = GNUNET_HELLO_address_to_prefix (address);
571 if (NULL == prefix) 648 if (NULL == prefix)
572 { 649 {
@@ -578,7 +655,9 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue
578 alen, 655 alen,
579 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); 656 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE);
580 msg->request_id = htonl (idgen++); 657 msg->request_id = htonl (idgen++);
658 tc_queue->qid = msg->request_id;
581 msg->receiver = *peer_id; 659 msg->receiver = *peer_id;
660 tc_queue->peer_id = *peer_id;
582 memcpy (&msg[1], 661 memcpy (&msg[1],
583 address, 662 address,
584 alen); 663 alen);
@@ -589,13 +668,37 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue
589 } 668 }
590 else 669 else
591 { 670 {
592 tc_h->open_queue_env = env; 671 tc_queue->open_queue_env = env;
593 } 672 }
673 GNUNET_CONTAINER_DLL_insert (tc_h->queue_head,
674 tc_h->queue_tail,
675 tc_queue);
594} 676}
595 677
596//struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission * 678
597//GNUNET_TRANSPORT_TESTING_transport_communicator_send 679struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *
598// (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tcq, 680GNUNET_TRANSPORT_TESTING_transport_communicator_send
599// const struct GNUNET_MessageHeader *hdr, 681 (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue,
600// GNUNET_TRANSPORT_TESTING_SuccessStatus cb, void *cb_cls); 682 const void *payload,
683 size_t payload_size/*,
684 GNUNET_TRANSPORT_TESTING_SuccessStatus cb,
685 void *cb_cls*/)
686{
687 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *tc_t;
688 struct GNUNET_TRANSPORT_SendMessageTo *msg;
689 struct GNUNET_MQ_Envelope *env;
690
691 env = GNUNET_MQ_msg_extra (msg,
692 payload_size,
693 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG);
694 msg->qid = htonl (tc_queue->qid);
695 msg->mid = tc_queue->mid++;
696 msg->receiver = tc_queue->peer_id;
697 memcpy (&msg[1],
698 payload,
699 payload_size);
700 GNUNET_MQ_send (tc_queue->tc_h->c_mq,
701 env);
702 return tc_t;
703}
601 704
diff --git a/src/transport/transport-testing2.h b/src/transport/transport-testing2.h
index 6aee919cd..4b9eb0f54 100644
--- a/src/transport/transport-testing2.h
+++ b/src/transport/transport-testing2.h
@@ -32,6 +32,10 @@
32 32
33struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle; 33struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle;
34 34
35struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue;
36
37struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission;
38
35/** 39/**
36 * @brief Function signature for callbacks that are called when new communicators become available 40 * @brief Function signature for callbacks that are called when new communicators become available
37 * 41 *
@@ -62,7 +66,8 @@ typedef void
62 66
63typedef void 67typedef void
64(*GNUNET_TRANSPORT_TESTING_AddQueueCallback)(void *cls, 68(*GNUNET_TRANSPORT_TESTING_AddQueueCallback)(void *cls,
65 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h); 69 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
70 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue);
66 71
67 72
68/** 73/**
@@ -92,9 +97,11 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue
92 const struct GNUNET_PeerIdentity *peer_id, 97 const struct GNUNET_PeerIdentity *peer_id,
93 const char *address); 98 const char *address);
94 99
95//struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission * 100struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *
96//GNUNET_TRANSPORT_TESTING_transport_communicator_send 101GNUNET_TRANSPORT_TESTING_transport_communicator_send
97// (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tcq, 102 (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue,
98// const struct GNUNET_MessageHeader *hdr, 103 const void *payload,
99// GNUNET_TRANSPORT_TESTING_SuccessStatus cb, void *cb_cls); 104 size_t payload_size/*,
105 GNUNET_TRANSPORT_TESTING_SuccessStatus cb,
106 void *cb_cls*/);
100 107