X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Ftransport%2Ftransport-testing.h;h=cb5ad319cc537623e385fc3abf6be31d2b3ed1ef;hb=5a7cef0202631204485cbcb1e36671e4321a936f;hp=b78d11dbe876acb2926abac2b6d513de7279a5e9;hpb=c6444a089a860da694842942283079a25bc1e957;p=oweals%2Fgnunet.git diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index b78d11dbe..cb5ad319c 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h @@ -30,6 +30,9 @@ #include "gnunet_util_lib.h" #include "gnunet_hello_lib.h" #include "gnunet_transport_service.h" +#include "gnunet_transport_core_service.h" +#include "gnunet_transport_hello_service.h" +#include "gnunet_transport_manipulation_service.h" #include "gnunet_testing_lib.h" @@ -46,19 +49,6 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext; struct GNUNET_TRANSPORT_TESTING_Handle; -/** - * Callback when two peers are connected and both have called the connect callback - * to notify clients about a new peer - * - * @param p FIXME: remove ASAP. - * @param cls closure - */ -typedef void -(*GNUNET_TRANSPORT_TESTING_StartCallback) (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, - void *cls); - - - /** * Context for a single peer */ @@ -87,7 +77,12 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext /** * Peer's transport service handle */ - struct GNUNET_TRANSPORT_Handle *th; + struct GNUNET_TRANSPORT_CoreHandle *th; + + /** + * Peer's transport service manipulation handle + */ + struct GNUNET_TRANSPORT_ManipulationHandle *tmh; /** * Peer's ATS handle. @@ -97,7 +92,7 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext /** * Peer's transport get hello handle to retrieve peer's HELLO message */ - struct GNUNET_TRANSPORT_GetHelloHandle *ghh; + struct GNUNET_TRANSPORT_HelloGetHandle *ghh; /** * Peer's testing handle @@ -117,22 +112,22 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext /** * Receive callback */ - GNUNET_TRANSPORT_ReceiveCallback rec; + struct GNUNET_MQ_MessageHandler *handlers; /** * Notify connect callback */ - GNUNET_TRANSPORT_NotifyConnect nc; + GNUNET_TRANSPORT_NotifyConnecT nc; /** * Notify disconnect callback */ - GNUNET_TRANSPORT_NotifyDisconnect nd; + GNUNET_TRANSPORT_NotifyDisconnecT nd; /** * Startup completed callback */ - GNUNET_TRANSPORT_TESTING_StartCallback start_cb; + GNUNET_SCHEDULER_TaskCallback start_cb; /** * Peers HELLO Message @@ -140,10 +135,15 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext struct GNUNET_HELLO_Message *hello; /** - * Closure for the callbacks + * Closure for the @a nc and @a nd callbacks */ void *cb_cls; + /** + * Closure for @e start_cb. + */ + void *start_cb_cls; + /** * An unique number to identify the peer */ @@ -202,8 +202,25 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequest */ void *cb_cls; - int p1_c; // dead? - int p2_c; // dead? + /** + * Message queue for sending from @a p1 to @a p2. + */ + struct GNUNET_MQ_Handle *mq; + + /** + * Set if peer1 says the connection is up to peer2. + */ + int p1_c; + + /** + * Set if peer2 says the connection is up to peer1. + */ + int p2_c; + + /** + * #GNUNET_YES if both @e p1_c and @e p2_c are #GNUNET_YES. + */ + int connected; }; @@ -263,22 +280,24 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth); * @param tth the testing handle * @param cfgname configuration file * @param peer_id the peer_id - * @param rec receive callback + * @param handlers functions for receiving messages * @param nc connect callback * @param nd disconnect callback + * @param cb_cls closure for @a nc and @a nd callback * @param start_cb start callback - * @param cb_cls closure for callback + * @param start_cb_cls closure for @a start_cb * @return the peer context */ struct GNUNET_TRANSPORT_TESTING_PeerContext * GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth, const char *cfgname, int peer_id, - GNUNET_TRANSPORT_ReceiveCallback rec, - GNUNET_TRANSPORT_NotifyConnect nc, - GNUNET_TRANSPORT_NotifyDisconnect nd, - GNUNET_TRANSPORT_TESTING_StartCallback start_cb, - void *cb_cls); + const struct GNUNET_MQ_MessageHandler *handlers, + GNUNET_TRANSPORT_NotifyConnecT nc, + GNUNET_TRANSPORT_NotifyDisconnecT nd, + void *cb_cls, + GNUNET_SCHEDULER_TaskCallback start_cb, + void *start_cb_cls); /** @@ -295,13 +314,13 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext * * @param p the peer * @param restart_cb restart callback - * @param cb_cls callback closure + * @param restart_cb_cls callback closure * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR */ int GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, - GNUNET_TRANSPORT_TESTING_StartCallback restart_cb, - void *cb_cls); + GNUNET_SCHEDULER_TaskCallback restart_cb, + void *restart_cb_cls); @@ -334,6 +353,32 @@ void GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); +/** + * Function called on matching connect requests. + * + * @param cls closure + * @param cc request matching the query + */ +typedef void +(*GNUNET_TRANSPORT_TESTING_ConnectContextCallback)(void *cls, + struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); + + +/** + * Find any connecting context matching the given pair of peers. + * + * @param p1 first peer + * @param p2 second peer + * @param cb function to call + * @param cb_cls closure for @a cb + */ +void +GNUNET_TRANSPORT_TESTING_find_connecting_context (struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, + struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, + GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb, + void *cb_cls); + + /* ********************** high-level process functions *************** */ @@ -362,6 +407,23 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequestList; struct GNUNET_TRANSPORT_TESTING_InternalPeerContext; +GNUNET_NETWORK_STRUCT_BEGIN +struct GNUNET_TRANSPORT_TESTING_TestMessage +{ + /** + * Type is (usually) #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE. + */ + struct GNUNET_MessageHeader header; + + /** + * Monotonically increasing counter throughout the test. + */ + uint32_t num GNUNET_PACKED; +}; +GNUNET_NETWORK_STRUCT_END + + + /** * Function called by the transport for each received message. * @@ -374,7 +436,7 @@ typedef void (*GNUNET_TRANSPORT_TESTING_ReceiveCallback) (void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *message); + const struct GNUNET_TRANSPORT_TESTING_TestMessage *message); /** @@ -524,6 +586,14 @@ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext */ int global_ret; + /** + * Generator for the `num` field in test messages. Incremented each + * time #GNUNET_TRANSPORT_TESTING_simple_send or + * #GNUNET_TRANSPORT_TESTING_large_send are used to transmit a + * message. + */ + uint32_t send_num_gen; + /* ******* internal state, clients should not mess with this **** */ /** @@ -645,6 +715,111 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, #define GNUNET_TRANSPORT_TESTING_main(num_peers,check,check_cls) \ GNUNET_TRANSPORT_TESTING_main_ (argv[0], __FILE__, num_peers, check, check_cls) +/* ***************** Convenience functions for sending ********* */ + +/** + * Send a test message of type @a mtype and size @a msize from + * peer @a sender to peer @a receiver. The peers should be + * connected when this function is called. + * + * @param sender the sending peer + * @param receiver the receiving peer + * @param mtype message type to use + * @param msize size of the message, at least `sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)` + * @param num unique message number + * @param cont continuation to call after transmission + * @param cont_cls closure for @a cont + * @return #GNUNET_OK if message was queued, + * #GNUNET_NO if peers are not connected + * #GNUNET_SYSERR if @a msize is illegal + */ +int +GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, + struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, + uint16_t mtype, + uint16_t msize, + uint32_t num, + GNUNET_SCHEDULER_TaskCallback cont, + void *cont_cls); + + +/** + * Message type used by #GNUNET_TRANSPORT_TESTING_simple_send(). + */ +#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE 12345 + +/** + * Alternative message type for tests. + */ +#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2 12346 + + +/** + * Type of the closure argument to pass to + * #GNUNET_TRANSPORT_TESTING_simple_send() and + * #GNUNET_TRANSPORT_TESTING_large_send(). + */ +struct GNUNET_TRANSPORT_TESTING_SendClosure +{ + /** + * Context for the transmission. + */ + struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; + + /** + * Function that returns the desired message size. Overrides + * the message size, can be NULL in which case the message + * size is the default. + */ + size_t (*get_size_cb)(unsigned int n); + + /** + * Number of messages to be transmitted in a loop. + * Use zero for "forever" (until external shutdown). + */ + unsigned int num_messages; + + /** + * Function to call after all transmissions, can be NULL. + */ + GNUNET_SCHEDULER_TaskCallback cont; + + /** + * Closure for @e cont. + */ + void *cont_cls; + +}; + + +/** + * Task that sends a minimalistic test message from the + * first peer to the second peer. + * + * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure` + * which should contain at least two peers, the first two + * of which should be currently connected + */ +void +GNUNET_TRANSPORT_TESTING_simple_send (void *cls); + +/** + * Size of a message sent with + * #GNUNET_TRANSPORT_TESTING_large_send(). Big enough + * to usually force defragmentation. + */ +#define GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE 2600 + +/** + * Task that sends a large test message from the + * first peer to the second peer. + * + * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure` + * which should contain at least two peers, the first two + * of which should be currently connected + */ +void +GNUNET_TRANSPORT_TESTING_large_send (void *cls); /* ********************** log-only convenience functions ************* */