GNUnet  0.11.x
transport-testing.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2006, 2009, 2015, 2016 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
26 #include "transport-testing.h"
27 
28 
29 #define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing", __VA_ARGS__)
30 
31 
34  const struct GNUNET_PeerIdentity *peer)
35 {
37 
38  for (t = tth->p_head; NULL != t; t = t->next)
39  if (0 == memcmp (&t->id,
40  peer,
41  sizeof(struct GNUNET_PeerIdentity)))
42  return t;
43  return NULL;
44 }
45 
46 
55 void
58  *p1,
59  struct
61  *p2,
63  cb,
64  void *cb_cls)
65 {
66  struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
69 
70  for (cc = tth->cc_head; NULL != cc; cc = ccn)
71  {
72  ccn = cc->next;
73  if ((cc->p1 == p1) &&
74  (cc->p2 == p2))
75  cb (cb_cls,
76  cc);
77  }
78 }
79 
80 
81 static void
82 set_p1c (void *cls,
84 {
85  int *found = cls;
86 
87  if (NULL != found)
88  *found = GNUNET_YES;
89  cx->p1_c = GNUNET_YES;
90 }
91 
92 
93 static void
94 set_mq (void *cls,
96 {
97  struct GNUNET_MQ_Handle *mq = cls;
98 
99  cx->mq = mq;
100 }
101 
102 
103 static void
104 set_p2c (void *cls,
106 {
107  int *found = cls;
108 
109  if (NULL != found)
110  *found = GNUNET_YES;
111  cx->p2_c = GNUNET_YES;
112 }
113 
114 
115 static void
116 clear_p1c (void *cls,
118 {
119  int *found = cls;
120 
121  if (NULL != found)
122  *found = GNUNET_YES;
123  cx->p1_c = GNUNET_NO;
124 }
125 
126 
127 static void
128 clear_p2c (void *cls,
130 {
131  int *found = cls;
132 
133  if (NULL != found)
134  *found = GNUNET_YES;
135  cx->p2_c = GNUNET_NO;
136 }
137 
138 
139 static void *
140 notify_connect (void *cls,
141  const struct GNUNET_PeerIdentity *peer,
142  struct GNUNET_MQ_Handle *mq)
143 {
145  struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
146  char *p2_s;
150  int found;
151  void *ret;
152 
153  p2 = find_peer_context (p->tth,
154  peer);
155  if (NULL != p->nc)
156  ret = p->nc (p->cb_cls,
157  peer,
158  mq);
159  else
160  ret = NULL;
161 
162  if (NULL != p2)
163  GNUNET_asprintf (&p2_s,
164  "%u (`%s')",
165  p2->no,
166  GNUNET_i2s (&p2->id));
167  else
168  GNUNET_asprintf (&p2_s,
169  "`%s'",
170  GNUNET_i2s (peer));
172  "Peers %s connected to peer %u (`%s')\n",
173  p2_s,
174  p->no,
175  GNUNET_i2s (&p->id));
176  GNUNET_free (p2_s);
177  /* update flags in connecting contexts */
178  found = GNUNET_NO;
180  p2,
181  &set_p1c,
182  &found);
183  if (GNUNET_NO == found)
184  {
186  cc->p1 = p;
187  cc->p2 = p2;
188  cc->p1_c = GNUNET_YES;
190  tth->cc_tail,
191  cc);
192  }
193  found = GNUNET_NO;
195  p,
196  &set_p2c,
197  &found);
198  if (GNUNET_NO == found)
199  {
201  cc->p1 = p2;
202  cc->p2 = p;
203  cc->p1_c = GNUNET_YES;
205  tth->cc_tail,
206  cc);
207  }
209  p2,
210  &set_mq,
211  mq);
212  /* update set connected flag for all requests */
213  for (cc = tth->cc_head; NULL != cc; cc = cc->next)
214  {
215  if (GNUNET_YES == cc->connected)
216  continue;
217  if ((GNUNET_YES == cc->p1_c) &&
218  (GNUNET_YES == cc->p2_c))
219  {
220  cc->connected = GNUNET_YES;
221  /* stop trying to connect */
222  if (NULL != cc->tct)
223  {
225  cc->tct = NULL;
226  }
227  if (NULL != cc->oh)
228  {
230  cc->oh = NULL;
231  }
232  if (NULL != cc->ats_sh)
233  {
235  cc->ats_sh = NULL;
236  }
237  }
238  }
239  /* then notify application */
240  for (cc = tth->cc_head; NULL != cc; cc = ccn)
241  {
242  ccn = cc->next;
243  if ((GNUNET_YES == cc->connected) &&
244  (NULL != cc->cb))
245  {
246  cc->cb (cc->cb_cls);
247  cc->cb = NULL; /* only notify once! */
248  }
249  }
250  return ret;
251 }
252 
253 
259 static void
260 offer_hello (void *cls);
261 
262 
263 static void
264 notify_disconnect (void *cls,
265  const struct GNUNET_PeerIdentity *peer,
266  void *handler_cls)
267 {
269  struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
270  char *p2_s;
271  /* Find PeerContext */
272  int no = 0;
273  struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL;
275 
276  p2 = find_peer_context (p->tth,
277  peer);
278  no = p->no;
279  if (NULL != p2)
280  GNUNET_asprintf (&p2_s,
281  "%u (`%s')",
282  p2->no,
283  GNUNET_i2s (&p2->id));
284  else
285  GNUNET_asprintf (&p2_s,
286  "`%s'",
287  GNUNET_i2s (peer));
289  "Peers %s disconnected from peer %u (`%s')\n",
290  p2_s,
291  no,
292  GNUNET_i2s (&p->id));
293  GNUNET_free (p2_s);
294  /* notify about disconnect */
295  if (NULL != p->nd)
296  p->nd (p->cb_cls,
297  peer,
298  handler_cls);
299  if (NULL == p2)
300  return;
301  /* clear MQ, it is now invalid */
303  p2,
304  &set_mq,
305  NULL);
306  /* update set connected flags for all requests */
308  p2,
309  &clear_p1c,
310  NULL);
312  p,
313  &clear_p2c,
314  NULL);
315  /* resume connectivity requests as necessary */
316  for (cc = tth->cc_head; NULL != cc; cc = cc->next)
317  {
318  if (GNUNET_NO == cc->connected)
319  continue;
320  if ((GNUNET_YES != cc->p1_c) ||
321  (GNUNET_YES != cc->p2_c))
322  {
323  cc->connected = GNUNET_NO;
324  /* start trying to connect */
325  if ((NULL == cc->tct) &&
326  (NULL == cc->oh))
328  cc);
329  if (NULL == cc->ats_sh)
331  &p2->id,
332  1);
333  }
334  }
335 }
336 
337 
338 static void
340  const struct GNUNET_MessageHeader *message)
341 {
343  struct GNUNET_PeerIdentity hello_id;
344 
346  GNUNET_HELLO_get_id ((const struct
347  GNUNET_HELLO_Message *) message,
348  &hello_id));
349  GNUNET_assert (0 == memcmp (&hello_id,
350  &p->id,
351  sizeof(hello_id)));
352  GNUNET_free (p->hello);
353  p->hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (message);
354 
355  if (NULL != p->start_cb)
356  {
358  "Peer %u (`%s') successfully started\n",
359  p->no,
360  GNUNET_i2s (&p->id));
361  p->start_cb (p->start_cb_cls);
362  p->start_cb = NULL;
363  }
364 }
365 
366 
383  const char *cfgname,
384  int peer_id,
385  const struct
389  void *cb_cls,
391  void *start_cb_cls)
392 {
393  char *emsg = NULL;
395  struct GNUNET_PeerIdentity dummy;
396  unsigned int i;
397 
398  if (GNUNET_NO == GNUNET_DISK_file_test (cfgname))
399  {
401  "File not found: `%s'\n",
402  cfgname);
403  return NULL;
404  }
405 
407  p->tth = tth;
408  p->nc = nc;
409  p->nd = nd;
410  if (NULL != handlers)
411  {
412  for (i = 0; NULL != handlers[i].cb; i++)
413  ;
414  p->handlers = GNUNET_new_array (i + 1,
415  struct GNUNET_MQ_MessageHandler);
416  GNUNET_memcpy (p->handlers,
417  handlers,
418  i * sizeof(struct GNUNET_MQ_MessageHandler));
419  }
420  if (NULL != cb_cls)
421  p->cb_cls = cb_cls;
422  else
423  p->cb_cls = p;
424  p->start_cb = start_cb;
425  if (NULL != start_cb_cls)
426  p->start_cb_cls = start_cb_cls;
427  else
428  p->start_cb_cls = p;
430  tth->p_tail,
431  p);
432 
433  /* Create configuration and call testing lib to modify it */
434  p->cfg = GNUNET_CONFIGURATION_create ();
436  GNUNET_CONFIGURATION_load (p->cfg, cfgname));
437  if (GNUNET_SYSERR ==
439  p->cfg))
440  {
442  "Testing library failed to create unique configuration based on `%s'\n",
443  cfgname);
445  GNUNET_free (p);
446  return NULL;
447  }
448 
449  p->no = peer_id;
450  /* Configure peer with configuration */
452  p->cfg,
453  p->no,
454  NULL,
455  &emsg);
456  if (NULL == p->peer)
457  {
459  "Testing library failed to create unique configuration based on `%s': `%s'\n",
460  cfgname,
461  emsg);
463  GNUNET_free (emsg);
464  return NULL;
465  }
466 
467  if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer))
468  {
470  "Testing library failed to create unique configuration based on `%s'\n",
471  cfgname);
473  return NULL;
474  }
475 
476  memset (&dummy,
477  '\0',
478  sizeof(dummy));
480  &p->id);
481  if (0 == memcmp (&dummy,
482  &p->id,
483  sizeof(struct GNUNET_PeerIdentity)))
484  {
486  "Testing library failed to obtain peer identity for peer %u\n",
487  p->no);
489  return NULL;
490  }
492  "Peer %u configured with identity `%s'\n",
493  p->no,
494  GNUNET_i2s_full (&p->id));
496  p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
497  NULL,
498  handlers,
499  p,
502  NULL);
503  if ((NULL == p->th) ||
504  (NULL == p->tmh))
505  {
507  "Failed to connect to transport service for peer `%s': `%s'\n",
508  cfgname,
509  emsg);
511  GNUNET_free (emsg);
512  return NULL;
513  }
514  p->ats = GNUNET_ATS_connectivity_init (p->cfg);
515  if (NULL == p->ats)
516  {
518  "Failed to connect to ATS service for peer `%s': `%s'\n",
519  cfgname,
520  emsg);
522  GNUNET_free (emsg);
523  return NULL;
524  }
525  p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
527  &get_hello,
528  p);
529  GNUNET_assert (NULL != p->ghh);
530  return p;
531 }
532 
533 
542 int
546  void *restart_cb_cls)
547 {
550 
551  /* shutdown */
553  "Stopping peer %u (`%s')\n",
554  p->no,
555  GNUNET_i2s (&p->id));
556  if (NULL != p->ghh)
557  {
559  p->ghh = NULL;
560  }
561  if (NULL != p->th)
562  {
564  p->th = NULL;
565  }
566  if (NULL != p->tmh)
567  {
569  p->tmh = NULL;
570  }
571  for (cc = p->tth->cc_head; NULL != cc; cc = ccn)
572  {
573  ccn = cc->next;
574  if ((cc->p1 == p) ||
575  (cc->p2 == p))
577  }
578  if (NULL != p->ats)
579  {
581  p->ats = NULL;
582  }
583  if (GNUNET_SYSERR ==
584  GNUNET_TESTING_peer_stop (p->peer))
585  {
587  "Failed to stop peer %u (`%s')\n",
588  p->no,
589  GNUNET_i2s (&p->id));
590  return GNUNET_SYSERR;
591  }
592 
593  sleep (5); // YUCK!
594 
596  "Restarting peer %u (`%s')\n",
597  p->no,
598  GNUNET_i2s (&p->id));
599  /* restart */
601  {
603  "Failed to restart peer %u (`%s')\n",
604  p->no,
605  GNUNET_i2s (&p->id));
606  return GNUNET_SYSERR;
607  }
608 
609  GNUNET_assert (NULL == p->start_cb);
610  p->start_cb = restart_cb;
611  p->start_cb_cls = restart_cb_cls;
612 
613  p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
614  NULL,
615  p->handlers,
616  p,
619  NULL);
620  GNUNET_assert (NULL != p->th);
621  p->ats = GNUNET_ATS_connectivity_init (p->cfg);
622  p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
624  &get_hello,
625  p);
626  GNUNET_assert (NULL != p->ghh);
627  return GNUNET_OK;
628 }
629 
630 
636 void
639 {
640  struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
643 
644  for (cc = tth->cc_head; NULL != cc; cc = ccn)
645  {
646  ccn = cc->next;
647  if ((cc->p1 == p) ||
648  (cc->p2 == p))
650  }
651  if (NULL != p->ghh)
652  {
654  p->ghh = NULL;
655  }
656  if (NULL != p->tmh)
657  {
659  p->tmh = NULL;
660  }
661  if (NULL != p->th)
662  {
664  p->th = NULL;
665  }
666  if (NULL != p->peer)
667  {
668  if (GNUNET_OK !=
669  GNUNET_TESTING_peer_stop (p->peer))
670  {
672  "Testing lib failed to stop peer %u (`%s')\n",
673  p->no,
674  GNUNET_i2s (&p->id));
675  }
677  p->peer = NULL;
678  }
679  if (NULL != p->ats)
680  {
682  p->ats = NULL;
683  }
684  if (NULL != p->hello)
685  {
686  GNUNET_free (p->hello);
687  p->hello = NULL;
688  }
689  if (NULL != p->cfg)
690  {
692  p->cfg = NULL;
693  }
694  if (NULL != p->handlers)
695  {
696  GNUNET_free (p->handlers);
697  p->handlers = NULL;
698  }
700  tth->p_tail,
701  p);
703  "Peer %u (`%s') stopped\n",
704  p->no,
705  GNUNET_i2s (&p->id));
706  GNUNET_free (p);
707 }
708 
709 
714 static void
715 hello_offered (void *cls)
716 {
718 
719  cc->oh = NULL;
721  &offer_hello,
722  cc);
723 }
724 
725 
731 static void
732 offer_hello (void *cls)
733 {
735  struct GNUNET_TRANSPORT_TESTING_PeerContext *p1 = cc->p1;
736  struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = cc->p2;
737 
738  cc->tct = NULL;
739  {
740  char *p2_s = GNUNET_strdup (GNUNET_i2s (&p2->id));
741 
743  "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n",
744  p1->no,
745  GNUNET_i2s (&p1->id),
746  p2->no,
747  p2_s,
748  GNUNET_HELLO_size (cc->p2->hello));
749  GNUNET_free (p2_s);
750  }
751 
752  if (NULL != cc->oh)
754  cc->oh =
756  (const struct
757  GNUNET_MessageHeader *) cc->p2->hello,
758  &hello_offered,
759  cc);
760 }
761 
762 
778  struct
781  void *cls)
782 {
783  struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
786 
787  ccn = NULL;
788  for (cc = tth->cc_head; NULL != cc; cc = cc->next)
789  {
790  if ((cc->p1 == p1) &&
791  (cc->p2 == p2))
792  {
793  ccn = cc;
794  break;
795  }
796  }
797 
799  cc->p1 = p1;
800  cc->p2 = p2;
801  cc->cb = cb;
802  if (NULL != cls)
803  cc->cb_cls = cls;
804  else
805  cc->cb_cls = cc;
806  if (NULL != ccn)
807  {
808  cc->p1_c = ccn->p1_c;
809  cc->p2_c = ccn->p2_c;
810  cc->connected = ccn->connected;
811  }
813  tth->cc_tail,
814  cc);
816  cc);
818  &p2->id,
819  1);
821  "New connect request %p\n",
822  cc);
823  return cc;
824 }
825 
826 
834 void
837  *cc)
838 {
839  struct GNUNET_TRANSPORT_TESTING_Handle *tth = cc->p1->tth;
840 
842  "Canceling connect request!\n");
843  if (NULL != cc->tct)
844  {
846  cc->tct = NULL;
847  }
848  if (NULL != cc->oh)
849  {
851  cc->oh = NULL;
852  }
853  if (NULL != cc->ats_sh)
854  {
856  cc->ats_sh = NULL;
857  }
859  tth->cc_tail,
860  cc);
861  GNUNET_free (cc);
862 }
863 
864 
870 void
872 {
877 
878  if (NULL == tth)
879  return;
880  cc = tth->cc_head;
881  while (NULL != cc)
882  {
883  ct = cc->next;
885  "Developer forgot to cancel connect request!\n");
887  cc = ct;
888  }
889  p = tth->p_head;
890  while (NULL != p)
891  {
892  t = p->next;
894  "Developer forgot to stop peer!\n");
896  p = t;
897  }
899  GNUNET_YES);
900 
901  GNUNET_free (tth);
902 }
903 
904 
912 {
914 
916  tth->tl_system = GNUNET_TESTING_system_create ("transport-testing",
917  NULL,
918  NULL,
919  NULL);
920  if (NULL == tth->tl_system)
921  {
923  "Failed to initialize testing library!\n");
924  GNUNET_free (tth);
925  return NULL;
926  }
927  return tth;
928 }
929 
930 
931 /* end of transport-testing.c */
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
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_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
struct GNUNET_ATS_ConnectivityHandle * GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the ATS connectivity suggestion client handle.
struct GNUNET_ATS_ConnectivitySuggestHandle * GNUNET_ATS_connectivity_suggest(struct GNUNET_ATS_ConnectivityHandle *ch, const struct GNUNET_PeerIdentity *peer, uint32_t strength)
We would like to receive address suggestions for a peer.
void GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch)
Client is done with ATS connectivity management, release resources.
void GNUNET_ATS_connectivity_suggest_cancel(struct GNUNET_ATS_ConnectivitySuggestHandle *sh)
We no longer care about being connected to a peer.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
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:482
#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.
int GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, struct GNUNET_PeerIdentity *peer)
Get the peer identity from a HELLO message.
Definition: hello.c:671
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:652
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_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
struct GNUNET_MessageHeader * GNUNET_copy_message(const struct GNUNET_MessageHeader *msg)
Create a copy of the given message.
#define GNUNET_free(ptr)
Wrapper around free.
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:1296
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1269
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1458
struct GNUNET_TESTING_System * GNUNET_TESTING_system_create(const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services)
Create a system handle.
Definition: testing.c:449
struct GNUNET_TESTING_Peer * GNUNET_TESTING_peer_configure(struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t key_number, struct GNUNET_PeerIdentity *id, char **emsg)
Configure a GNUnet peer.
Definition: testing.c:1161
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:529
int GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer)
Start the peer.
Definition: testing.c:1354
int GNUNET_TESTING_configuration_create(struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new configuration using the given configuration as a template; ports and paths will be modif...
Definition: testing.c:1140
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1550
void GNUNET_TESTING_peer_get_identity(struct GNUNET_TESTING_Peer *peer, struct GNUNET_PeerIdentity *id)
Obtain the peer identity from a peer handle.
Definition: testing.c:1332
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TRANSPORT_HelloGetHandle * GNUNET_TRANSPORT_hello_get(const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_TRANSPORT_AddressClass ac, GNUNET_TRANSPORT_HelloUpdateCallback rec, void *rec_cls)
Obtain updates on changes to the HELLO message for this peer.
void GNUNET_TRANSPORT_offer_hello_cancel(struct GNUNET_TRANSPORT_OfferHelloHandle *ohh)
Cancel the request to transport to offer the HELLO message.
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.
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_OfferHelloHandle * GNUNET_TRANSPORT_offer_hello(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_MessageHeader *hello, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Offer the transport service the HELLO of another peer.
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_hello_get_cancel(struct GNUNET_TRANSPORT_HelloGetHandle *ghh)
Stop receiving updates about changes to our HELLO message.
struct GNUNET_TRANSPORT_ManipulationHandle * GNUNET_TRANSPORT_manipulation_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the transport service.
void GNUNET_TRANSPORT_manipulation_disconnect(struct GNUNET_TRANSPORT_ManipulationHandle *handle)
Disconnect from the transport service.
void GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
Disconnect from the transport service.
@ GNUNET_TRANSPORT_AC_ANY
Bitmask for "any" address.
A HELLO message is used to exchange information about transports with other peers.
Handle to a message queue.
Definition: mq.c:86
Message handler for a specific message type.
Header for all communications.
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:139
Handle for a request to connect two peers.
struct GNUNET_MQ_Handle * mq
Message queue for sending from p1 to p2.
int connected
GNUNET_YES if both p1_c and p2_c are GNUNET_YES.
struct GNUNET_TRANSPORT_OfferHelloHandle * oh
Handle by which we inform the peer about the HELLO of the other peer.
int p2_c
Set if peer2 says the connection is up to peer1.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p1
Peer we want to connect.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p2
Peer we want to connect.
GNUNET_SCHEDULER_TaskCallback cb
Function to call upon completion.
struct GNUNET_ATS_ConnectivitySuggestHandle * ats_sh
Handle by which we ask ATS to facilitate the connection.
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_TRANSPORT_TESTING_ConnectRequest * next
Kept in a DLL.
struct GNUNET_TESTING_System * tl_system
Testing library system handle.
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
struct GNUNET_TRANSPORT_TESTING_PeerContext * p_head
head DLL of peers
void * cb_cls
Closure for the nc and nd callbacks.
struct GNUNET_TRANSPORT_TESTING_Handle * tth
Transport testing handle this peer belongs to.
unsigned int no
An unique number to identify the peer.
struct GNUNET_PeerIdentity id
Peer identity.
void * start_cb_cls
Closure for start_cb.
struct GNUNET_ATS_ConnectivityHandle * ats
Peer's ATS handle.
GNUNET_TRANSPORT_NotifyDisconnect nd
Notify disconnect callback.
struct GNUNET_HELLO_Message * hello
Peers HELLO Message.
struct GNUNET_CONFIGURATION_Handle * cfg
Peer's configuration.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static void start_cb(void *cls)
Function called once we have successfully launched a 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.
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.
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.
static void get_hello(void *cb_cls, const struct GNUNET_MessageHeader *message)
static void clear_p1c(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 void * notify_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
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)
Initiate a connection from p1 to p2 by offering p1 p2's HELLO message.
#define LOG(kind,...)
static void hello_offered(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.
struct GNUNET_TRANSPORT_TESTING_Handle * GNUNET_TRANSPORT_TESTING_init()
Initialize the transport testing.
static void notify_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)
static struct GNUNET_TRANSPORT_TESTING_PeerContext * find_peer_context(struct GNUNET_TRANSPORT_TESTING_Handle *tth, const struct GNUNET_PeerIdentity *peer)
void GNUNET_TRANSPORT_TESTING_connect_peers_cancel(struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
Cancel the request to connect two peers Tou MUST cancel the request if you stop the peers before the ...
static void offer_hello(void *cls)
Offer the current HELLO of P2 to P1.
testing lib for transport service
void(* GNUNET_TRANSPORT_TESTING_ConnectContextCallback)(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
Function called on matching connect requests.