30#define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing", __VA_ARGS__)
40 if (0 == memcmp (&
t->id,
71 for (cc = tth->
cc_head; NULL != cc; cc = ccn)
157 ret =
p->nc (
p->cb_cls,
173 "Peers %s connected to peer %u (`%s')\n",
228 if (NULL != cc->
ah_sh)
236 for (cc = tth->
cc_head; NULL != cc; cc = ccn)
276 "Peers %s disconnected from peer %u (`%s')\n",
312 if (NULL == cc->
ah_sh)
334 if (NULL !=
p->start_cb)
339 p->hello_size =
record->value_size;
341 memcpy (
p->hello,
record->value,
p->hello_size);
342 p->hello[
p->hello_size - 1] =
'\0';
346 if (NULL !=
p->start_cb)
349 "Peer %u (`%s') successfully started\n",
352 p->start_cb (
p->start_cb_cls);
394 "File not found: `%s'\n",
405 for (i = 0; NULL !=
handlers[i].cb; i++)
418 if (NULL != start_cb_cls)
419 p->start_cb_cls = start_cb_cls;
431 GNUNET_TESTING_configuration_create (tth->
tl_system,
435 "Testing library failed to create unique configuration based on `%s'\n",
444 p->peer = GNUNET_TESTING_peer_configure (tth->
tl_system,
452 "Testing library failed to create unique configuration based on `%s': `%s'\n",
460 if (
GNUNET_OK != GNUNET_TESTING_peer_start (
p->peer))
463 "Testing library failed to create unique configuration based on `%s'\n",
472 GNUNET_TESTING_peer_get_identity (
p->peer,
474 if (0 == memcmp (&
dummy,
479 "Testing library failed to obtain peer identity for peer %u\n",
485 "Peer %u configured with identity `%s'\n",
497 "Failed to connect to transport service for peer `%s': `%s'\n",
508 "Failed to connect to TNG service for peer `%s': `%s'\n",
527 void *restart_cb_cls)
534 "Stopping peer %u (`%s')\n",
547 for (cc =
p->tth->cc_head; NULL != cc; cc = ccn)
560 GNUNET_TESTING_peer_stop (
p->peer))
563 "Failed to stop peer %u (`%s')\n",
572 "Restarting peer %u (`%s')\n",
579 "Failed to restart peer %u (`%s')\n",
586 p->start_cb = restart_cb;
587 p->start_cb_cls = restart_cb_cls;
622 "Stopping peer %u (`%s')\n",
626 for (cc = tth->
cc_head; NULL != cc; cc = ccn)
651 "Disconnecting from PEERSTORE service\n");
659 GNUNET_TESTING_peer_stop (
p->peer))
662 "Testing lib failed to stop peer %u (`%s')\n",
666 GNUNET_TESTING_peer_destroy (
p->peer);
669 if (NULL !=
p->hello)
679 if (NULL !=
p->handlers)
688 "Peer %u (`%s') stopped\n",
691 if (NULL !=
p->rh_task)
743 if ((cc->
p1 ==
p1) &&
773 "New connect request %p\n",
787 "Canceling connect request!\n");
793 if (NULL != cc->
ah_sh)
825 "Developer forgot to cancel connect request!\n");
834 "Developer forgot to stop peer!\n");
856 tth->
tl_system = GNUNET_TESTING_system_create (
"transport-testing",
863 "Failed to initialize testing library!\n");
struct GNUNET_MQ_MessageHandlers handlers[]
struct GNUNET_MQ_Handle * mq
static int ret
Final status code.
static char * peer_id
Option –peer.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static struct GNUNET_NotificationContext * nc
Notification context for broadcasting to monitors.
static struct GNUNET_OS_Process * p
Helper process we started.
static struct GNUNET_SCHEDULER_Task * t
Main task.
struct GNUNET_TRANSPORT_ApplicationSuggestHandle * GNUNET_TRANSPORT_application_suggest(struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_MQ_PriorityPreferences pk, struct GNUNET_BANDWIDTH_Value32NBO bw)
An application would like TRANSPORT to connect to a peer.
struct GNUNET_TRANSPORT_CoreHandle * GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *self, const struct GNUNET_MQ_MessageHandler *handlers, void *cls, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd)
Connect to the transport service.
void GNUNET_TRANSPORT_application_done(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
Shutdown TRANSPORT application client.
void(* GNUNET_TRANSPORT_NotifyDisconnect)(void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)
Function called to notify transport users that another peer disconnected from us.
void *(* GNUNET_TRANSPORT_NotifyConnect)(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Function called to notify transport users that another peer connected to us.
void GNUNET_TRANSPORT_application_suggest_cancel(struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh)
We no longer care about being connected to a peer.
struct GNUNET_TRANSPORT_ApplicationHandle * GNUNET_TRANSPORT_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the TRANSPORT application client handle.
void GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
Disconnect from the transport service.
#define GNUNET_BANDWIDTH_ZERO
Convenience definition to use for 0-bandwidth.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
@ GNUNET_MQ_PRIO_BEST_EFFORT
Best-effort traffic (e.g.
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iteration_start(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Iterate over peerstore entries.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
#define GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY
Key used for storing HELLOs in the peerstore.
void GNUNET_PEERSTORE_iteration_stop(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iteration.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
Handle to a message queue.
Message handler for a specific message type.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_SCHEDULER_Task * next
This is a linked list.
Handle for a request to connect two peers.
int connected
GNUNET_YES if both p1_c and p2_c are GNUNET_YES.
struct GNUNET_MQ_Handle * mq
Message queue for sending from p1 to p2.
int p2_c
Set if peer2 says the connection is up to peer1.
struct GNUNET_TRANSPORT_ApplicationSuggestHandle * ah_sh
Handle by which we ask TNG to facilitate the connection.
void * cb_cls
Closure for cb.
GNUNET_SCHEDULER_TaskCallback cb
Function to call upon completion.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p2
Peer we want to connect.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p1
Peer we want to connect.
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * next
Kept in a DLL.
struct GNUNET_SCHEDULER_Task * tct
Task by which we accomplish the connection.
int p1_c
Set if peer1 says the connection is up to peer2.
struct GNUNET_TESTBED_System * tl_system
Testing library system handle.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p_head
head DLL of peers
struct GNUNET_TRANSPORT_TESTING_PeerContext * p_tail
tail DLL of peers
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc_head
head DLL of connect contexts
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc_tail
head DLL of connect contexts
Context for a single peer.
void * cb_cls
Closure for the nc and nd callbacks.
struct GNUNET_TESTING_Peer * peer
Peer's testing handle.
unsigned int no
An unique number to identify the peer.
struct GNUNET_TRANSPORT_ApplicationHandle * ah
Application handle.
struct GNUNET_PeerIdentity id
Peer identity.
void * start_cb_cls
Closure for start_cb.
struct GNUNET_TRANSPORT_TESTING_Handle * tth
Transport testing handle this peer belongs to.
GNUNET_TRANSPORT_NotifyDisconnect nd
Notify disconnect callback.
static void start_cb(void *cls)
Function called once we have successfully launched a peer.
struct GNUNET_TRANSPORT_TESTING_PeerContext * GNUNET_TRANSPORT_TESTING_start_peer(struct GNUNET_TRANSPORT_TESTING_Handle *tth, const char *cfgname, int peer_id, 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)
Start a peer with the given configuration.
int GNUNET_TRANSPORT_TESTING_restart_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *p, GNUNET_SCHEDULER_TaskCallback restart_cb, void *restart_cb_cls)
Stops and restarts the given peer, sleeping (!) for 5s in between.
static void clear_p2c(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
static void set_mq(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
void GNUNET_TRANSPORT_TESTING_stop_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *p)
Shutdown the given peer.
static void hello_iter_cb(void *cb_cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
static void clear_p1c(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
static void * notify_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
static void set_p2c(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
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)
Find any connecting context matching the given pair of peers.
static void set_p1c(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
struct GNUNET_TRANSPORT_TESTING_Handle * GNUNET_TRANSPORT_TESTING_init()
Initialize the transport testing.
static void retrieve_hello(void *cls)
static struct GNUNET_TRANSPORT_TESTING_PeerContext * find_peer_context(struct GNUNET_TRANSPORT_TESTING_Handle *tth, const struct GNUNET_PeerIdentity *peer)
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * GNUNET_TRANSPORT_TESTING_connect_peers(struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, GNUNET_SCHEDULER_TaskCallback cb, void *cls)
Function called after the HELLO was passed to the transport service.
void GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth)
Clean up the transport testing.
static void notify_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)
void GNUNET_TRANSPORT_TESTING_connect_peers_cancel(struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
Cancel the request to connect two peers.
void(* GNUNET_TRANSPORT_TESTING_ConnectContextCallback)(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
Function called on matching connect requests.