This file is part of GNUnet.
Copyright (C) 2006, 2009, 2015, 2016 GNUnet e.V.
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
#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"
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
*/
/**
* 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.
/**
* 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
/**
* 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
*/
void *cb_cls;
+ /**
+ * 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.
*/
};
-/**
- * Information we keep for active transmission jobs.
- */
-struct TRANSPORT_TESTING_SendJob
-{
-
- /**
- * Kept in a DLL.
- */
- struct TRANSPORT_TESTING_SendJob *next;
-
- /**
- * Kept in a DLL.
- */
- struct TRANSPORT_TESTING_SendJob *prev;
-
- /**
- * Sender of the message.
- */
- struct GNUNET_TRANSPORT_TESTING_PeerContext *sender;
-
- /**
- * Receiver of the message.
- */
- struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver;
-
- /**
- * Operation handle.
- */
- struct GNUNET_TRANSPORT_TransmitHandle *th;
-
- /**
- * Number of the message.
- */
- uint32_t num;
-
- /**
- * Type of message to send.
- */
- uint16_t mtype;
-
- /**
- * Length of the message.
- */
- uint16_t msize;
-
-};
-
-
/**
* Handle for a test run.
*/
*/
struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc_tail;
- /**
- * Kept in a DLL.
- */
- struct TRANSPORT_TESTING_SendJob *sj_head;
-
- /**
- * Kept in a DLL.
- */
- struct TRANSPORT_TESTING_SendJob *sj_tail;
-
/**
* head DLL of peers
*/
* @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
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,
+ const struct GNUNET_MQ_MessageHandler *handlers,
+ GNUNET_TRANSPORT_NotifyConnecT nc,
+ GNUNET_TRANSPORT_NotifyDisconnecT nd,
void *cb_cls,
- GNUNET_TRANSPORT_TESTING_StartCallback start_cb,
+ GNUNET_SCHEDULER_TaskCallback start_cb,
void *start_cb_cls);
*/
int
GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
- GNUNET_TRANSPORT_TESTING_StartCallback restart_cb,
+ GNUNET_SCHEDULER_TaskCallback restart_cb,
void *restart_cb_cls);
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.
*
(*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);
/**
/* ***************** 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
* @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
struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
uint16_t mtype,
uint16_t msize,
- uint32_t num);
+ uint32_t num,
+ GNUNET_SCHEDULER_TaskCallback cont,
+ void *cont_cls);
/**
*/
#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE 12345
-GNUNET_NETWORK_STRUCT_BEGIN
-struct GNUNET_TRANSPORT_TESTING_TestMessage
+/**
+ * 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
{
/**
- * Type is #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE.
+ * Context for the transmission.
*/
- struct GNUNET_MessageHeader header;
+ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
/**
- * Monotonically increasing counter throughout the test.
+ * Function that returns the desired message size. Overrides
+ * the message size, can be NULL in which case the message
+ * size is the default.
*/
- uint32_t num GNUNET_PACKED;
+ 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;
+
};
-GNUNET_NETWORK_STRUCT_END
/**
* Task that sends a minimalistic test message from the
* first peer to the second peer.
*
- * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
+ * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure`
* which should contain at least two peers, the first two
* of which should be currently connected
*/
* Task that sends a large test message from the
* first peer to the second peer.
*
- * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
+ * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure`
* which should contain at least two peers, the first two
* of which should be currently connected
*/