aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport-testing.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport-testing.h')
-rw-r--r--src/transport/transport-testing.h183
1 files changed, 181 insertions, 2 deletions
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
index 4be451d35..e61621b2e 100644
--- a/src/transport/transport-testing.h
+++ b/src/transport/transport-testing.h
@@ -207,8 +207,69 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequest
207 */ 207 */
208 void *cb_cls; 208 void *cb_cls;
209 209
210 int p1_c; // dead? 210 /**
211 int p2_c; // dead? 211 * Set if peer1 says the connection is up to peer2.
212 */
213 int p1_c;
214
215 /**
216 * Set if peer2 says the connection is up to peer1.
217 */
218 int p2_c;
219
220 /**
221 * #GNUNET_YES if both @e p1_c and @e p2_c are #GNUNET_YES.
222 */
223 int connected;
224};
225
226
227/**
228 * Information we keep for active transmission jobs.
229 */
230struct TRANSPORT_TESTING_SendJob
231{
232
233 /**
234 * Kept in a DLL.
235 */
236 struct TRANSPORT_TESTING_SendJob *next;
237
238 /**
239 * Kept in a DLL.
240 */
241 struct TRANSPORT_TESTING_SendJob *prev;
242
243 /**
244 * Sender of the message.
245 */
246 struct GNUNET_TRANSPORT_TESTING_PeerContext *sender;
247
248 /**
249 * Receiver of the message.
250 */
251 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver;
252
253 /**
254 * Operation handle.
255 */
256 struct GNUNET_TRANSPORT_TransmitHandle *th;
257
258 /**
259 * Number of the message.
260 */
261 uint32_t num;
262
263 /**
264 * Type of message to send.
265 */
266 uint16_t mtype;
267
268 /**
269 * Length of the message.
270 */
271 uint16_t msize;
272
212}; 273};
213 274
214 275
@@ -233,6 +294,16 @@ struct GNUNET_TRANSPORT_TESTING_Handle
233 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc_tail; 294 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc_tail;
234 295
235 /** 296 /**
297 * Kept in a DLL.
298 */
299 struct TRANSPORT_TESTING_SendJob *sj_head;
300
301 /**
302 * Kept in a DLL.
303 */
304 struct TRANSPORT_TESTING_SendJob *sj_tail;
305
306 /**
236 * head DLL of peers 307 * head DLL of peers
237 */ 308 */
238 struct GNUNET_TRANSPORT_TESTING_PeerContext *p_head; 309 struct GNUNET_TRANSPORT_TESTING_PeerContext *p_head;
@@ -341,6 +412,32 @@ void
341GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); 412GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc);
342 413
343 414
415/**
416 * Function called on matching connect requests.
417 *
418 * @param cls closure
419 * @param cc request matching the query
420 */
421typedef void
422(*GNUNET_TRANSPORT_TESTING_ConnectContextCallback)(void *cls,
423 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc);
424
425
426/**
427 * Find any connecting context matching the given pair of peers.
428 *
429 * @param p1 first peer
430 * @param p2 second peer
431 * @param cb function to call
432 * @param cb_cls closure for @a cb
433 */
434void
435GNUNET_TRANSPORT_TESTING_find_connecting_context (struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
436 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
437 GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb,
438 void *cb_cls);
439
440
344/* ********************** high-level process functions *************** */ 441/* ********************** high-level process functions *************** */
345 442
346 443
@@ -531,6 +628,14 @@ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext
531 */ 628 */
532 int global_ret; 629 int global_ret;
533 630
631 /**
632 * Generator for the `num` field in test messages. Incremented each
633 * time #GNUNET_TRANSPORT_TESTING_simple_send or
634 * #GNUNET_TRANSPORT_TESTING_large_send are used to transmit a
635 * message.
636 */
637 uint32_t send_num_gen;
638
534 /* ******* internal state, clients should not mess with this **** */ 639 /* ******* internal state, clients should not mess with this **** */
535 640
536 /** 641 /**
@@ -652,6 +757,80 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
652#define GNUNET_TRANSPORT_TESTING_main(num_peers,check,check_cls) \ 757#define GNUNET_TRANSPORT_TESTING_main(num_peers,check,check_cls) \
653 GNUNET_TRANSPORT_TESTING_main_ (argv[0], __FILE__, num_peers, check, check_cls) 758 GNUNET_TRANSPORT_TESTING_main_ (argv[0], __FILE__, num_peers, check, check_cls)
654 759
760/* ***************** Convenience functions for sending ********* */
761
762
763/**
764 * Send a test message of type @a mtype and size @a msize from
765 * peer @a sender to peer @a receiver. The peers should be
766 * connected when this function is called.
767 *
768 * @param sender the sending peer
769 * @param receiver the receiving peer
770 * @param mtype message type to use
771 * @param msize size of the message, at least `sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)`
772 * @param num unique message number
773 * @return #GNUNET_OK if message was queued,
774 * #GNUNET_NO if peers are not connected
775 * #GNUNET_SYSERR if @a msize is illegal
776 */
777int
778GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *sender,
779 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
780 uint16_t mtype,
781 uint16_t msize,
782 uint32_t num);
783
784
785/**
786 * Message type used by #GNUNET_TRANSPORT_TESTING_simple_send().
787 */
788#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE 12345
789
790GNUNET_NETWORK_STRUCT_BEGIN
791struct GNUNET_TRANSPORT_TESTING_TestMessage
792{
793 /**
794 * Type is #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE.
795 */
796 struct GNUNET_MessageHeader header;
797
798 /**
799 * Monotonically increasing counter throughout the test.
800 */
801 uint32_t num GNUNET_PACKED;
802};
803GNUNET_NETWORK_STRUCT_END
804
805
806/**
807 * Task that sends a minimalistic test message from the
808 * first peer to the second peer.
809 *
810 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
811 * which should contain at least two peers, the first two
812 * of which should be currently connected
813 */
814void
815GNUNET_TRANSPORT_TESTING_simple_send (void *cls);
816
817/**
818 * Size of a message sent with
819 * #GNUNET_TRANSPORT_TESTING_large_send(). Big enough
820 * to usually force defragmentation.
821 */
822#define GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE 2600
823
824/**
825 * Task that sends a large test message from the
826 * first peer to the second peer.
827 *
828 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
829 * which should contain at least two peers, the first two
830 * of which should be currently connected
831 */
832void
833GNUNET_TRANSPORT_TESTING_large_send (void *cls);
655 834
656 835
657/* ********************** log-only convenience functions ************* */ 836/* ********************** log-only convenience functions ************* */