GNUnet 0.24.1-15-gab6ed22f1
transport-testing2.c File Reference
#include "platform.h"
#include "transport-testing2.h"
Include dependency graph for transport-testing2.c:

Go to the source code of this file.

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "transport-testing", __VA_ARGS__)
 

Functions

static struct GNUNET_TRANSPORT_TESTING_PeerContextfind_peer_context (struct GNUNET_TRANSPORT_TESTING_Handle *tth, const struct GNUNET_PeerIdentity *peer)
 
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. More...
 
static void set_p1c (void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
 
static void set_mq (void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
 
static void set_p2c (void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
 
static void clear_p1c (void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
 
static void clear_p2c (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 notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)
 
static void retrieve_hello (void *cls)
 
static void hello_iter_cb (void *cb_cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
 
struct GNUNET_TRANSPORT_TESTING_PeerContextGNUNET_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. More...
 
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. More...
 
void GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p)
 Shutdown the given peer. More...
 
struct GNUNET_TRANSPORT_TESTING_ConnectRequestGNUNET_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. More...
 
void GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
 Cancel the request to connect two peers. More...
 
void GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth)
 Clean up the transport testing. More...
 
struct GNUNET_TRANSPORT_TESTING_HandleGNUNET_TRANSPORT_TESTING_init ()
 Initialize the transport testing. More...
 

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "transport-testing", __VA_ARGS__)

Definition at line 31 of file transport-testing2.c.

Function Documentation

◆ find_peer_context()

static struct GNUNET_TRANSPORT_TESTING_PeerContext * find_peer_context ( struct GNUNET_TRANSPORT_TESTING_Handle tth,
const struct GNUNET_PeerIdentity peer 
)
static

Definition at line 35 of file transport-testing2.c.

37{
39
40 for (t = tth->p_head; NULL != t; t = t->next)
41 if (0 == memcmp (&t->id,
42 peer,
43 sizeof(struct GNUNET_PeerIdentity)))
44 return t;
45 return NULL;
46}
static struct GNUNET_SCHEDULER_Task * t
Main task.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_SCHEDULER_Task * next
This is a linked list.
Definition: scheduler.c:140
struct GNUNET_TRANSPORT_TESTING_PeerContext * p_head
head DLL of peers
struct GNUNET_TESTING_Peer * peer
Peer's testing handle.
struct GNUNET_TRANSPORT_TESTING_Handle * tth
Transport testing handle this peer belongs to.

References GNUNET_SCHEDULER_Task::next, GNUNET_TRANSPORT_TESTING_Handle::p_head, GNUNET_TRANSPORT_TESTING_PeerContext::peer, t, and GNUNET_TRANSPORT_TESTING_PeerContext::tth.

Referenced by notify_connect(), and notify_disconnect().

Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_find_connecting_context()

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.

Parameters
p1first peer
p2second peer
cbfunction to call
cb_clsclosure for cb

Definition at line 58 of file transport-testing2.c.

67{
68 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
71
72 for (cc = tth->cc_head; NULL != cc; cc = ccn)
73 {
74 ccn = cc->next;
75 if ((cc->p1 == p1) &&
76 (cc->p2 == p2))
77 cb (cb_cls,
78 cc);
79 }
80}
Handle for a request to connect two peers.
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_TRANSPORT_TESTING_ConnectRequest * cc_head
head DLL of connect contexts

References GNUNET_TRANSPORT_TESTING_ConnectRequest::cb, GNUNET_TRANSPORT_TESTING_ConnectRequest::cb_cls, GNUNET_TRANSPORT_TESTING_Handle::cc_head, GNUNET_TRANSPORT_TESTING_ConnectRequest::next, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1, GNUNET_TRANSPORT_TESTING_ConnectRequest::p2, and GNUNET_TRANSPORT_TESTING_PeerContext::tth.

Referenced by GNUNET_TRANSPORT_TESTING_send(), notify_connect(), and notify_disconnect().

Here is the caller graph for this function:

◆ set_p1c()

static void set_p1c ( void *  cls,
struct GNUNET_TRANSPORT_TESTING_ConnectRequest cx 
)
static

Definition at line 84 of file transport-testing2.c.

86{
87 int *found = cls;
88
89 if (NULL != found)
90 *found = GNUNET_YES;
91 cx->p1_c = GNUNET_YES;
92}
@ GNUNET_YES
int p1_c
Set if peer1 says the connection is up to peer2.

References GNUNET_YES, and GNUNET_TRANSPORT_TESTING_ConnectRequest::p1_c.

Referenced by notify_connect().

Here is the caller graph for this function:

◆ set_mq()

static void set_mq ( void *  cls,
struct GNUNET_TRANSPORT_TESTING_ConnectRequest cx 
)
static

Definition at line 96 of file transport-testing2.c.

98{
99 struct GNUNET_MQ_Handle *mq = cls;
100
101 cx->mq = mq;
102}
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
Handle to a message queue.
Definition: mq.c:87
struct GNUNET_MQ_Handle * mq
Message queue for sending from p1 to p2.

References mq, and GNUNET_TRANSPORT_TESTING_ConnectRequest::mq.

Referenced by notify_connect(), and notify_disconnect().

Here is the caller graph for this function:

◆ set_p2c()

static void set_p2c ( void *  cls,
struct GNUNET_TRANSPORT_TESTING_ConnectRequest cx 
)
static

Definition at line 106 of file transport-testing2.c.

108{
109 int *found = cls;
110
111 if (NULL != found)
112 *found = GNUNET_YES;
113 cx->p2_c = GNUNET_YES;
114}
int p2_c
Set if peer2 says the connection is up to peer1.

References GNUNET_YES, and GNUNET_TRANSPORT_TESTING_ConnectRequest::p2_c.

Referenced by notify_connect().

Here is the caller graph for this function:

◆ clear_p1c()

static void clear_p1c ( void *  cls,
struct GNUNET_TRANSPORT_TESTING_ConnectRequest cx 
)
static

Definition at line 118 of file transport-testing2.c.

120{
121 int *found = cls;
122
123 if (NULL != found)
124 *found = GNUNET_YES;
125 cx->p1_c = GNUNET_NO;
126}
@ GNUNET_NO

References GNUNET_NO, GNUNET_YES, and GNUNET_TRANSPORT_TESTING_ConnectRequest::p1_c.

Referenced by notify_disconnect().

Here is the caller graph for this function:

◆ clear_p2c()

static void clear_p2c ( void *  cls,
struct GNUNET_TRANSPORT_TESTING_ConnectRequest cx 
)
static

Definition at line 130 of file transport-testing2.c.

132{
133 int *found = cls;
134
135 if (NULL != found)
136 *found = GNUNET_YES;
137 cx->p2_c = GNUNET_NO;
138}

References GNUNET_NO, GNUNET_YES, and GNUNET_TRANSPORT_TESTING_ConnectRequest::p2_c.

Referenced by notify_disconnect().

Here is the caller graph for this function:

◆ notify_connect()

static void * notify_connect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_MQ_Handle mq 
)
static

Definition at line 142 of file transport-testing2.c.

145{
147 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
148 char *p2_s;
152 int found;
153 void *ret;
154
155 p2 = find_peer_context (p->tth,
156 peer);
157 if (NULL != p->nc)
158 ret = p->nc (p->cb_cls,
159 peer,
160 mq);
161 else
162 ret = NULL;
163
164 if (NULL != p2)
165 GNUNET_asprintf (&p2_s,
166 "%u (`%s')",
167 p2->no,
168 GNUNET_i2s (&p2->id));
169 else
170 GNUNET_asprintf (&p2_s,
171 "`%s'",
172 GNUNET_i2s (peer));
174 "Peers %s connected to peer %u (`%s')\n",
175 p2_s,
176 p->no,
177 GNUNET_i2s (&p->id));
178 GNUNET_free (p2_s);
179 /* update flags in connecting contexts */
180 found = GNUNET_NO;
182 p2,
183 &set_p1c,
184 &found);
185 if (GNUNET_NO == found)
186 {
188 cc->p1 = p;
189 cc->p2 = p2;
190 cc->p1_c = GNUNET_YES;
192 tth->cc_tail,
193 cc);
194 }
195 found = GNUNET_NO;
197 p,
198 &set_p2c,
199 &found);
200 if (GNUNET_NO == found)
201 {
203 cc->p1 = p2;
204 cc->p2 = p;
205 cc->p1_c = GNUNET_YES;
207 tth->cc_tail,
208 cc);
209 }
211 p2,
212 &set_mq,
213 mq);
214 /* update set connected flag for all requests */
215 for (cc = tth->cc_head; NULL != cc; cc = cc->next)
216 {
217 if (GNUNET_YES == cc->connected)
218 continue;
219 if ((GNUNET_YES == cc->p1_c) &&
220 (GNUNET_YES == cc->p2_c))
221 {
222 cc->connected = GNUNET_YES;
223 /* stop trying to connect */
224 if (NULL != cc->tct)
225 {
227 cc->tct = NULL;
228 }
229 if (NULL != cc->ah_sh)
230 {
232 cc->ah_sh = NULL;
233 }
234 }
235 }
236 /* then notify application */
237 for (cc = tth->cc_head; NULL != cc; cc = ccn)
238 {
239 ccn = cc->next;
240 if ((GNUNET_YES == cc->connected) &&
241 (NULL != cc->cb))
242 {
243 cc->cb (cc->cb_cls);
244 cc->cb = NULL; /* only notify once! */
245 }
246 }
247 return ret;
248}
static int ret
Final status code.
Definition: gnunet-arm.c:93
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
void GNUNET_TRANSPORT_application_suggest_cancel(struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh)
We no longer care about being connected to a peer.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ 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_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
int connected
GNUNET_YES if both p1_c and p2_c are GNUNET_YES.
struct GNUNET_TRANSPORT_ApplicationSuggestHandle * ah_sh
Handle by which we ask TNG to facilitate the connection.
struct GNUNET_SCHEDULER_Task * tct
Task by which we accomplish the connection.
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc_tail
head DLL of connect contexts
unsigned int no
An unique number to identify the peer.
struct GNUNET_PeerIdentity id
Peer identity.
static void set_mq(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
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)
static struct GNUNET_TRANSPORT_TESTING_PeerContext * find_peer_context(struct GNUNET_TRANSPORT_TESTING_Handle *tth, const struct GNUNET_PeerIdentity *peer)
#define LOG(kind,...)

References GNUNET_TRANSPORT_TESTING_ConnectRequest::ah_sh, GNUNET_TRANSPORT_TESTING_ConnectRequest::cb, GNUNET_TRANSPORT_TESTING_ConnectRequest::cb_cls, GNUNET_TRANSPORT_TESTING_Handle::cc_head, GNUNET_TRANSPORT_TESTING_Handle::cc_tail, GNUNET_TRANSPORT_TESTING_ConnectRequest::connected, find_peer_context(), GNUNET_asprintf(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_TRANSPORT_application_suggest_cancel(), GNUNET_TRANSPORT_TESTING_find_connecting_context(), GNUNET_YES, GNUNET_TRANSPORT_TESTING_PeerContext::id, LOG, mq, GNUNET_TRANSPORT_TESTING_ConnectRequest::next, GNUNET_TRANSPORT_TESTING_PeerContext::no, p, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1_c, GNUNET_TRANSPORT_TESTING_ConnectRequest::p2, GNUNET_TRANSPORT_TESTING_ConnectRequest::p2_c, ret, set_mq(), set_p1c(), set_p2c(), and GNUNET_TRANSPORT_TESTING_ConnectRequest::tct.

Referenced by GNUNET_TRANSPORT_TESTING_restart_peer(), and GNUNET_TRANSPORT_TESTING_start_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_disconnect()

static void notify_disconnect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  handler_cls 
)
static

Definition at line 252 of file transport-testing2.c.

255{
257 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
258 char *p2_s;
259 /* Find PeerContext */
260 int no = 0;
261 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL;
263
264 p2 = find_peer_context (p->tth,
265 peer);
266 no = p->no;
267 if (NULL != p2)
268 GNUNET_asprintf (&p2_s,
269 "%u (`%s')",
270 p2->no,
271 GNUNET_i2s (&p2->id));
272 else
273 GNUNET_asprintf (&p2_s,
274 "`%s'",
275 GNUNET_i2s (peer));
277 "Peers %s disconnected from peer %u (`%s')\n",
278 p2_s,
279 no,
280 GNUNET_i2s (&p->id));
281 GNUNET_free (p2_s);
282 /* notify about disconnect */
283 if (NULL != p->nd)
284 p->nd (p->cb_cls,
285 peer,
286 handler_cls);
287 if (NULL == p2)
288 return;
289 /* clear MQ, it is now invalid */
291 p2,
292 &set_mq,
293 NULL);
294 /* update set connected flags for all requests */
296 p2,
297 &clear_p1c,
298 NULL);
300 p,
301 &clear_p2c,
302 NULL);
303 /* resume connectivity requests as necessary */
304 for (cc = tth->cc_head; NULL != cc; cc = cc->next)
305 {
306 if (GNUNET_NO == cc->connected)
307 continue;
308 if ((GNUNET_YES != cc->p1_c) ||
309 (GNUNET_YES != cc->p2_c))
310 {
311 cc->connected = GNUNET_NO;
312 /* start trying to connect */
313 if (NULL == cc->ah_sh)
315 &p2->id,
318 }
319 }
320}
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.
#define GNUNET_BANDWIDTH_ZERO
Convenience definition to use for 0-bandwidth.
@ GNUNET_MQ_PRIO_BEST_EFFORT
Best-effort traffic (e.g.
struct GNUNET_TRANSPORT_ApplicationHandle * ah
Application handle.
static void clear_p2c(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
static void clear_p1c(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)

References GNUNET_TRANSPORT_TESTING_PeerContext::ah, GNUNET_TRANSPORT_TESTING_ConnectRequest::ah_sh, GNUNET_TRANSPORT_TESTING_Handle::cc_head, clear_p1c(), clear_p2c(), GNUNET_TRANSPORT_TESTING_ConnectRequest::connected, find_peer_context(), GNUNET_asprintf(), GNUNET_BANDWIDTH_ZERO, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_MQ_PRIO_BEST_EFFORT, GNUNET_NO, GNUNET_TRANSPORT_application_suggest(), GNUNET_TRANSPORT_TESTING_find_connecting_context(), GNUNET_YES, GNUNET_TRANSPORT_TESTING_PeerContext::id, LOG, GNUNET_TRANSPORT_TESTING_ConnectRequest::next, GNUNET_TRANSPORT_TESTING_PeerContext::no, p, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1_c, GNUNET_TRANSPORT_TESTING_ConnectRequest::p2, GNUNET_TRANSPORT_TESTING_ConnectRequest::p2_c, and set_mq().

Referenced by GNUNET_TRANSPORT_TESTING_restart_peer(), and GNUNET_TRANSPORT_TESTING_start_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ retrieve_hello()

static void retrieve_hello ( void *  cls)
static

Definition at line 360 of file transport-testing2.c.

361{
363 p->rh_task = NULL;
365 "transport",
366 &p->id,
369 p);
370
371}
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.
#define GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY
Key used for storing HELLOs in the peerstore.
static void hello_iter_cb(void *cb_cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)

References GNUNET_PEERSTORE_iteration_start(), GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY, hello_iter_cb(), and p.

Referenced by GNUNET_TRANSPORT_TESTING_start_peer(), and hello_iter_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hello_iter_cb()

static void hello_iter_cb ( void *  cb_cls,
const struct GNUNET_PEERSTORE_Record record,
const char *  emsg 
)
static

Definition at line 327 of file transport-testing2.c.

330{
332 if (NULL == record)
333 {
334 p->pic = NULL;
335 if (NULL != p->start_cb)
337 return;
338 }
339 // Check record type et al?
340 p->hello_size = record->value_size;
341 p->hello = GNUNET_malloc (p->hello_size);
342 memcpy (p->hello, record->value, p->hello_size);
343 p->hello[p->hello_size - 1] = '\0';
344
346 p->pic = NULL;
347 if (NULL != p->start_cb)
348 {
350 "Peer %u (`%s') successfully started\n",
351 p->no,
352 GNUNET_i2s (&p->id));
353 p->start_cb (p->start_cb_cls);
354 p->start_cb = NULL;
355 }
356}
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
#define GNUNET_malloc(size)
Wrapper around malloc.
void GNUNET_PEERSTORE_iteration_stop(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iteration.
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.
Definition: scheduler.c:1304
void * cb_cls
Closure for the nc and nd callbacks.
static void retrieve_hello(void *cls)

References GNUNET_TRANSPORT_TESTING_PeerContext::cb_cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_malloc, GNUNET_PEERSTORE_iteration_stop(), GNUNET_SCHEDULER_add_now(), LOG, p, record(), and retrieve_hello().

Referenced by GNUNET_TRANSPORT_TESTING_restart_peer(), and retrieve_hello().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_start_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.

Parameters
tththe testing handle
cfgnameconfiguration file
peer_idan identification number for the peer
handlersfunctions for receiving messages
ncconnect callback
nddisconnect callback
cb_clsclosure for nc and nd callback
start_cbstart callback
start_cb_clsclosure for start_cb
Returns
the peer context

Definition at line 375 of file transport-testing2.c.

386{
387 char *emsg = NULL;
390 unsigned int i;
391
392 if (GNUNET_NO == GNUNET_DISK_file_test (cfgname))
393 {
395 "File not found: `%s'\n",
396 cfgname);
397 return NULL;
398 }
399
401 p->tth = tth;
402 p->nc = nc;
403 p->nd = nd;
404 if (NULL != handlers)
405 {
406 for (i = 0; NULL != handlers[i].cb; i++)
407 ;
408 p->handlers = GNUNET_new_array (i + 1,
410 GNUNET_memcpy (p->handlers,
411 handlers,
412 i * sizeof(struct GNUNET_MQ_MessageHandler));
413 }
414 if (NULL != cb_cls)
415 p->cb_cls = cb_cls;
416 else
417 p->cb_cls = p;
418 p->start_cb = start_cb;
419 if (NULL != start_cb_cls)
420 p->start_cb_cls = start_cb_cls;
421 else
422 p->start_cb_cls = p;
424 tth->p_tail,
425 p);
426
427 /* Create configuration and call testing lib to modify it */
430 GNUNET_CONFIGURATION_load (p->cfg, cfgname));
431 if (GNUNET_SYSERR ==
432 GNUNET_TESTING_configuration_create (tth->tl_system,
433 p->cfg))
434 {
436 "Testing library failed to create unique configuration based on `%s'\n",
437 cfgname);
439 GNUNET_free (p);
440 return NULL;
441 }
442
443 p->no = peer_id;
444 /* Configure peer with configuration */
445 p->peer = GNUNET_TESTING_peer_configure (tth->tl_system,
446 p->cfg,
447 p->no,
448 NULL,
449 &emsg);
450 if (NULL == p->peer)
451 {
453 "Testing library failed to create unique configuration based on `%s': `%s'\n",
454 cfgname,
455 emsg);
457 GNUNET_free (emsg);
458 return NULL;
459 }
460
461 if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer))
462 {
464 "Testing library failed to create unique configuration based on `%s'\n",
465 cfgname);
467 return NULL;
468 }
469
470 memset (&dummy,
471 '\0',
472 sizeof(dummy));
473 GNUNET_TESTING_peer_get_identity (p->peer,
474 &p->id);
475 if (0 == memcmp (&dummy,
476 &p->id,
477 sizeof(struct GNUNET_PeerIdentity)))
478 {
480 "Testing library failed to obtain peer identity for peer %u\n",
481 p->no);
483 return NULL;
484 }
486 "Peer %u configured with identity `%s'\n",
487 p->no,
488 GNUNET_i2s_full (&p->id));
490 NULL,
491 handlers,
492 p,
495 if (NULL == p->th)
496 {
498 "Failed to connect to transport service for peer `%s': `%s'\n",
499 cfgname,
500 emsg);
502 GNUNET_free (emsg);
503 return NULL;
504 }
506 if (NULL == p->ah)
507 {
509 "Failed to connect to TNG service for peer `%s': `%s'\n",
510 cfgname,
511 emsg);
513 GNUNET_free (emsg);
514 return NULL;
515 }
516 p->ph = GNUNET_PEERSTORE_connect (p->cfg);
517 // FIXME Error handling
519
520 return p;
521}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
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.
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.
struct GNUNET_TRANSPORT_ApplicationHandle * GNUNET_TRANSPORT_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the TRANSPORT application client handle.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy 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).
Definition: disk.c:523
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_SYSERR
#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
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
Message handler for a specific message type.
struct GNUNET_TESTBED_System * tl_system
Testing library system handle.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p_tail
tail DLL of peers
static void start_cb(void *cls)
Function called once we have successfully launched a peer.
void GNUNET_TRANSPORT_TESTING_stop_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *p)
Shutdown the given peer.
static void * notify_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
static void notify_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)

References dummy, GNUNET_assert, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_load(), GNUNET_CONTAINER_DLL_insert, GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_i2s_full(), GNUNET_memcpy, GNUNET_new, GNUNET_new_array, GNUNET_NO, GNUNET_OK, GNUNET_PEERSTORE_connect(), GNUNET_SCHEDULER_add_now(), GNUNET_SYSERR, GNUNET_TRANSPORT_application_init(), GNUNET_TRANSPORT_core_connect(), GNUNET_TRANSPORT_TESTING_stop_peer(), handlers, LOG, nc, notify_connect(), notify_disconnect(), p, GNUNET_TRANSPORT_TESTING_Handle::p_head, GNUNET_TRANSPORT_TESTING_Handle::p_tail, peer_id, retrieve_hello(), start_cb(), and GNUNET_TRANSPORT_TESTING_Handle::tl_system.

Referenced by connect_check_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_restart_peer()

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.

Parameters
pthe peer
restart_cbrestart callback
restart_cb_clscallback closure
Returns
GNUNET_OK in success otherwise GNUNET_SYSERR

Definition at line 525 of file transport-testing2.c.

529{
532
533 /* shutdown */
535 "Stopping peer %u (`%s')\n",
536 p->no,
537 GNUNET_i2s (&p->id));
538 if (NULL != p->pic)
539 {
541 p->pic = NULL;
542 }
543 if (NULL != p->th)
544 {
546 p->th = NULL;
547 }
548 for (cc = p->tth->cc_head; NULL != cc; cc = ccn)
549 {
550 ccn = cc->next;
551 if ((cc->p1 == p) ||
552 (cc->p2 == p))
554 }
555 if (NULL != p->ah)
556 {
558 p->ah = NULL;
559 }
560 if (GNUNET_SYSERR ==
561 GNUNET_TESTING_peer_stop (p->peer))
562 {
564 "Failed to stop peer %u (`%s')\n",
565 p->no,
566 GNUNET_i2s (&p->id));
567 return GNUNET_SYSERR;
568 }
569
570 sleep (5); // YUCK!
571
573 "Restarting peer %u (`%s')\n",
574 p->no,
575 GNUNET_i2s (&p->id));
576 /* restart */
577 if (GNUNET_SYSERR == GNUNET_TESTING_peer_start (p->peer))
578 {
580 "Failed to restart peer %u (`%s')\n",
581 p->no,
582 GNUNET_i2s (&p->id));
583 return GNUNET_SYSERR;
584 }
585
586 GNUNET_assert (NULL == p->start_cb);
587 p->start_cb = restart_cb;
588 p->start_cb_cls = restart_cb_cls;
589
591 NULL,
592 p->handlers,
593 p,
596 GNUNET_assert (NULL != p->th);
599 "transport",
600 &p->id,
603 p);
604 GNUNET_assert (NULL != p->pic);
605 return GNUNET_OK;
606}
void GNUNET_TRANSPORT_application_done(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
Shutdown TRANSPORT application client.
void GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
Disconnect from the transport service.
void GNUNET_TRANSPORT_TESTING_connect_peers_cancel(struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
Cancel the request to connect two peers.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_OK, GNUNET_PEERSTORE_iteration_start(), GNUNET_PEERSTORE_iteration_stop(), GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY, GNUNET_SYSERR, GNUNET_TRANSPORT_application_done(), GNUNET_TRANSPORT_application_init(), GNUNET_TRANSPORT_core_connect(), GNUNET_TRANSPORT_core_disconnect(), GNUNET_TRANSPORT_TESTING_connect_peers_cancel(), hello_iter_cb(), LOG, GNUNET_TRANSPORT_TESTING_ConnectRequest::next, notify_connect(), notify_disconnect(), p, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1, and GNUNET_TRANSPORT_TESTING_ConnectRequest::p2.

Here is the call graph for this function:

◆ GNUNET_TRANSPORT_TESTING_stop_peer()

void GNUNET_TRANSPORT_TESTING_stop_peer ( struct GNUNET_TRANSPORT_TESTING_PeerContext p)

Shutdown the given peer.

Parameters
pthe peer

Definition at line 615 of file transport-testing2.c.

617{
618 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
621 /* shutdown */
623 "Stopping peer %u (`%s')\n",
624 p->no,
625 GNUNET_i2s (&p->id));
626
627 for (cc = tth->cc_head; NULL != cc; cc = ccn)
628 {
629 ccn = cc->next;
630 if ((cc->p1 == p) ||
631 (cc->p2 == p))
633 }
634 if (NULL != p->pic)
635 {
637 p->pic = NULL;
638 }
639 if (NULL != p->th)
640 {
642 p->th = NULL;
643 }
644 if (NULL != p->ah)
645 {
647 p->ah = NULL;
648 }
649 if (NULL != p->ph)
650 {
652 "Disconnecting from PEERSTORE service\n");
654 p->ph = NULL;
655 }
656
657 if (NULL != p->peer)
658 {
659 if (GNUNET_OK !=
660 GNUNET_TESTING_peer_stop (p->peer))
661 {
663 "Testing lib failed to stop peer %u (`%s')\n",
664 p->no,
665 GNUNET_i2s (&p->id));
666 }
667 GNUNET_TESTING_peer_destroy (p->peer);
668 p->peer = NULL;
669 }
670 if (NULL != p->hello)
671 {
672 GNUNET_free (p->hello);
673 p->hello = NULL;
674 }
675 if (NULL != p->cfg)
676 {
678 p->cfg = NULL;
679 }
680 if (NULL != p->handlers)
681 {
682 GNUNET_free (p->handlers);
683 p->handlers = NULL;
684 }
686 tth->p_tail,
687 p);
689 "Peer %u (`%s') stopped\n",
690 p->no,
691 GNUNET_i2s (&p->id));
692 if (NULL != p->rh_task)
693 GNUNET_SCHEDULER_cancel (p->rh_task);
694 p->rh_task = NULL;
695 GNUNET_free (p);
696}
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_log(kind,...)
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.

References GNUNET_TRANSPORT_TESTING_Handle::cc_head, GNUNET_CONFIGURATION_destroy(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_OK, GNUNET_PEERSTORE_disconnect(), GNUNET_PEERSTORE_iteration_stop(), GNUNET_SCHEDULER_cancel(), GNUNET_TRANSPORT_application_done(), GNUNET_TRANSPORT_core_disconnect(), GNUNET_TRANSPORT_TESTING_connect_peers_cancel(), LOG, GNUNET_TRANSPORT_TESTING_ConnectRequest::next, p, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1, GNUNET_TRANSPORT_TESTING_ConnectRequest::p2, GNUNET_TRANSPORT_TESTING_Handle::p_head, and GNUNET_TRANSPORT_TESTING_Handle::p_tail.

Referenced by do_shutdown(), GNUNET_TRANSPORT_TESTING_done(), and GNUNET_TRANSPORT_TESTING_start_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_connect_peers()

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.

Connect the given peers and call the callback when both peers report the inbound connection.

FIXME maybe schedule the application_validate somehow Initiate a connection from p1 to p2 by offering p1 p2's HELLO message

Remarks: start_peer's notify_connect callback can be called before.

Parameters
tthtransport testing handle
p1peer 1
p2peer 2
cbthe callback to call when both peers notified that they are connected
clscallback cls
Returns
a connect request handle

Definition at line 730 of file transport-testing2.c.

736{
737 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
740
741 ccn = NULL;
742 for (cc = tth->cc_head; NULL != cc; cc = cc->next)
743 {
744 if ((cc->p1 == p1) &&
745 (cc->p2 == p2))
746 {
747 ccn = cc;
748 break;
749 }
750 }
751
753 cc->p1 = p1;
754 cc->p2 = p2;
755 cc->cb = cb;
756 if (NULL != cls)
757 cc->cb_cls = cls;
758 else
759 cc->cb_cls = cc;
760 if (NULL != ccn)
761 {
762 cc->p1_c = ccn->p1_c;
763 cc->p2_c = ccn->p2_c;
764 cc->connected = ccn->connected;
765 }
767 tth->cc_tail,
768 cc);
770 &p2->id,
774 "New connect request %p\n",
775 cc);
776 return cc;
777}

References GNUNET_TRANSPORT_TESTING_PeerContext::ah, GNUNET_TRANSPORT_TESTING_ConnectRequest::ah_sh, GNUNET_TRANSPORT_TESTING_ConnectRequest::cb, GNUNET_TRANSPORT_TESTING_ConnectRequest::cb_cls, GNUNET_TRANSPORT_TESTING_Handle::cc_head, GNUNET_TRANSPORT_TESTING_Handle::cc_tail, GNUNET_TRANSPORT_TESTING_ConnectRequest::connected, GNUNET_BANDWIDTH_ZERO, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_PRIO_BEST_EFFORT, GNUNET_new, GNUNET_TRANSPORT_application_suggest(), GNUNET_TRANSPORT_TESTING_PeerContext::id, LOG, GNUNET_TRANSPORT_TESTING_ConnectRequest::next, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1_c, GNUNET_TRANSPORT_TESTING_ConnectRequest::p2, GNUNET_TRANSPORT_TESTING_ConnectRequest::p2_c, and GNUNET_TRANSPORT_TESTING_PeerContext::tth.

Referenced by do_connect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_connect_peers_cancel()

void GNUNET_TRANSPORT_TESTING_connect_peers_cancel ( struct GNUNET_TRANSPORT_TESTING_ConnectRequest cc)

Cancel the request to connect two peers.

You MUST cancel the request if you stop the peers before the peers connected successfully.

Parameters
cca connect request handle

Definition at line 781 of file transport-testing2.c.

784{
785 struct GNUNET_TRANSPORT_TESTING_Handle *tth = cc->p1->tth;
786
788 "Canceling connect request!\n");
789 if (NULL != cc->tct)
790 {
792 cc->tct = NULL;
793 }
794 if (NULL != cc->ah_sh)
795 {
797 cc->ah_sh = NULL;
798 }
800 tth->cc_tail,
801 cc);
802 GNUNET_free (cc);
803}

References GNUNET_TRANSPORT_TESTING_ConnectRequest::ah_sh, GNUNET_TRANSPORT_TESTING_Handle::cc_head, GNUNET_TRANSPORT_TESTING_Handle::cc_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_SCHEDULER_cancel(), GNUNET_TRANSPORT_application_suggest_cancel(), LOG, GNUNET_TRANSPORT_TESTING_ConnectRequest::p1, GNUNET_TRANSPORT_TESTING_ConnectRequest::tct, and GNUNET_TRANSPORT_TESTING_PeerContext::tth.

Referenced by do_shutdown(), GNUNET_TRANSPORT_TESTING_done(), GNUNET_TRANSPORT_TESTING_restart_peer(), and GNUNET_TRANSPORT_TESTING_stop_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_done()

void GNUNET_TRANSPORT_TESTING_done ( struct GNUNET_TRANSPORT_TESTING_Handle tth)

Clean up the transport testing.

Parameters
tthtransport testing handle

Definition at line 812 of file transport-testing2.c.

813{
818
819 if (NULL == tth)
820 return;
821 cc = tth->cc_head;
822 while (NULL != cc)
823 {
824 ct = cc->next;
826 "Developer forgot to cancel connect request!\n");
828 cc = ct;
829 }
830 p = tth->p_head;
831 while (NULL != p)
832 {
833 t = p->next;
835 "Developer forgot to stop peer!\n");
837 p = t;
838 }
839 GNUNET_TESTING_system_destroy (tth->tl_system,
840 GNUNET_YES);
841
843}

References GNUNET_TRANSPORT_TESTING_Handle::cc_head, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_TRANSPORT_TESTING_connect_peers_cancel(), GNUNET_TRANSPORT_TESTING_stop_peer(), GNUNET_YES, LOG, GNUNET_TRANSPORT_TESTING_ConnectRequest::next, p, GNUNET_TRANSPORT_TESTING_Handle::p_head, t, GNUNET_TRANSPORT_TESTING_Handle::tl_system, and GNUNET_TRANSPORT_TESTING_PeerContext::tth.

Referenced by GNUNET_TRANSPORT_TESTING_main_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_init()

struct GNUNET_TRANSPORT_TESTING_Handle * GNUNET_TRANSPORT_TESTING_init ( void  )

Initialize the transport testing.

Returns
transport testing handle

Definition at line 852 of file transport-testing2.c.

853{
855
857 tth->tl_system = GNUNET_TESTING_system_create ("transport-testing",
858 NULL,
859 NULL,
860 NULL);
861 if (NULL == tth->tl_system)
862 {
864 "Failed to initialize testing library!\n");
865 GNUNET_free (tth);
866 return NULL;
867 }
868 return tth;
869}

References GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_new, and GNUNET_TRANSPORT_TESTING_Handle::tl_system.

Referenced by GNUNET_TRANSPORT_TESTING_main_().

Here is the caller graph for this function: