GNUnet  0.19.3
transport-testing2.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 "platform.h"
27 #include "transport-testing2.h"
28 
29 
30 #define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing", __VA_ARGS__)
31 
32 
35  const struct GNUNET_PeerIdentity *peer)
36 {
38 
39  for (t = tth->p_head; NULL != t; t = t->next)
40  if (0 == memcmp (&t->id,
41  peer,
42  sizeof(struct GNUNET_PeerIdentity)))
43  return t;
44  return NULL;
45 }
46 
47 
56 void
59  *p1,
60  struct
62  *p2,
64  cb,
65  void *cb_cls)
66 {
67  struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
70 
71  for (cc = tth->cc_head; NULL != cc; cc = ccn)
72  {
73  ccn = cc->next;
74  if ((cc->p1 == p1) &&
75  (cc->p2 == p2))
76  cb (cb_cls,
77  cc);
78  }
79 }
80 
81 
82 static void
83 set_p1c (void *cls,
85 {
86  int *found = cls;
87 
88  if (NULL != found)
89  *found = GNUNET_YES;
90  cx->p1_c = GNUNET_YES;
91 }
92 
93 
94 static void
95 set_mq (void *cls,
97 {
98  struct GNUNET_MQ_Handle *mq = cls;
99 
100  cx->mq = mq;
101 }
102 
103 
104 static void
105 set_p2c (void *cls,
107 {
108  int *found = cls;
109 
110  if (NULL != found)
111  *found = GNUNET_YES;
112  cx->p2_c = GNUNET_YES;
113 }
114 
115 
116 static void
117 clear_p1c (void *cls,
119 {
120  int *found = cls;
121 
122  if (NULL != found)
123  *found = GNUNET_YES;
124  cx->p1_c = GNUNET_NO;
125 }
126 
127 
128 static void
129 clear_p2c (void *cls,
131 {
132  int *found = cls;
133 
134  if (NULL != found)
135  *found = GNUNET_YES;
136  cx->p2_c = GNUNET_NO;
137 }
138 
139 
140 static void *
141 notify_connect (void *cls,
142  const struct GNUNET_PeerIdentity *peer,
143  struct GNUNET_MQ_Handle *mq)
144 {
146  struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
147  char *p2_s;
151  int found;
152  void *ret;
153 
154  p2 = find_peer_context (p->tth,
155  peer);
156  if (NULL != p->nc)
157  ret = p->nc (p->cb_cls,
158  peer,
159  mq);
160  else
161  ret = NULL;
162 
163  if (NULL != p2)
164  GNUNET_asprintf (&p2_s,
165  "%u (`%s')",
166  p2->no,
167  GNUNET_i2s (&p2->id));
168  else
169  GNUNET_asprintf (&p2_s,
170  "`%s'",
171  GNUNET_i2s (peer));
173  "Peers %s connected to peer %u (`%s')\n",
174  p2_s,
175  p->no,
176  GNUNET_i2s (&p->id));
177  GNUNET_free (p2_s);
178  /* update flags in connecting contexts */
179  found = GNUNET_NO;
181  p2,
182  &set_p1c,
183  &found);
184  if (GNUNET_NO == found)
185  {
187  cc->p1 = p;
188  cc->p2 = p2;
189  cc->p1_c = GNUNET_YES;
191  tth->cc_tail,
192  cc);
193  }
194  found = GNUNET_NO;
196  p,
197  &set_p2c,
198  &found);
199  if (GNUNET_NO == found)
200  {
202  cc->p1 = p2;
203  cc->p2 = p;
204  cc->p1_c = GNUNET_YES;
206  tth->cc_tail,
207  cc);
208  }
210  p2,
211  &set_mq,
212  mq);
213  /* update set connected flag for all requests */
214  for (cc = tth->cc_head; NULL != cc; cc = cc->next)
215  {
216  if (GNUNET_YES == cc->connected)
217  continue;
218  if ((GNUNET_YES == cc->p1_c) &&
219  (GNUNET_YES == cc->p2_c))
220  {
221  cc->connected = GNUNET_YES;
222  /* stop trying to connect */
223  if (NULL != cc->tct)
224  {
226  cc->tct = NULL;
227  }
228  if (NULL != cc->ats_sh)
229  {
231  cc->ats_sh = NULL;
232  }
233  }
234  }
235  /* then notify application */
236  for (cc = tth->cc_head; NULL != cc; cc = ccn)
237  {
238  ccn = cc->next;
239  if ((GNUNET_YES == cc->connected) &&
240  (NULL != cc->cb))
241  {
242  cc->cb (cc->cb_cls);
243  cc->cb = NULL; /* only notify once! */
244  }
245  }
246  return ret;
247 }
248 
249 
255 static void
256 offer_hello (void *cls);
257 
258 
259 static void
260 notify_disconnect (void *cls,
261  const struct GNUNET_PeerIdentity *peer,
262  void *handler_cls)
263 {
265  struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
266  char *p2_s;
267  /* Find PeerContext */
268  int no = 0;
269  struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL;
271 
272  p2 = find_peer_context (p->tth,
273  peer);
274  no = p->no;
275  if (NULL != p2)
276  GNUNET_asprintf (&p2_s,
277  "%u (`%s')",
278  p2->no,
279  GNUNET_i2s (&p2->id));
280  else
281  GNUNET_asprintf (&p2_s,
282  "`%s'",
283  GNUNET_i2s (peer));
285  "Peers %s disconnected from peer %u (`%s')\n",
286  p2_s,
287  no,
288  GNUNET_i2s (&p->id));
289  GNUNET_free (p2_s);
290  /* notify about disconnect */
291  if (NULL != p->nd)
292  p->nd (p->cb_cls,
293  peer,
294  handler_cls);
295  if (NULL == p2)
296  return;
297  /* clear MQ, it is now invalid */
299  p2,
300  &set_mq,
301  NULL);
302  /* update set connected flags for all requests */
304  p2,
305  &clear_p1c,
306  NULL);
308  p,
309  &clear_p2c,
310  NULL);
311  /* resume connectivity requests as necessary */
312  for (cc = tth->cc_head; NULL != cc; cc = cc->next)
313  {
314  if (GNUNET_NO == cc->connected)
315  continue;
316  if ((GNUNET_YES != cc->p1_c) ||
317  (GNUNET_YES != cc->p2_c))
318  {
319  cc->connected = GNUNET_NO;
320  /* start trying to connect */
321  if (NULL == cc->tct)
323  cc);
324  if (NULL == cc->ats_sh)
326  &p2->id,
327  1);
328  }
329  }
330 }
331 
332 static void
333 retrieve_hello (void *cls);
334 
335 static void
337  const struct GNUNET_PEERSTORE_Record *record,
338  const char *emsg)
339 {
341  if (NULL == record)
342  {
343  p->pic = NULL;
344  if (NULL != p->start_cb)
346  return;
347  }
348  // Check record type et al?
349  p->hello_size = record->value_size;
350  p->hello = GNUNET_malloc (p->hello_size);
351  memcpy (p->hello, record->value, p->hello_size);
352  p->hello[p->hello_size - 1] = '\0';
353 
355  p->pic = NULL;
356  if (NULL != p->start_cb)
357  {
359  "Peer %u (`%s') successfully started\n",
360  p->no,
361  GNUNET_i2s (&p->id));
362  p->start_cb (p->start_cb_cls);
363  p->start_cb = NULL;
364  }
365 }
366 
367 
368 static void
369 retrieve_hello (void *cls)
370 {
372  p->rh_task = NULL;
373  p->pic = GNUNET_PEERSTORE_iterate (p->ph,
374  "transport",
375  &p->id,
378  p);
379 
380 }
381 
382 
386  const char *cfgname,
387  int peer_id,
388  const struct
392  void *cb_cls,
394  void *start_cb_cls)
395 {
396  char *emsg = NULL;
398  struct GNUNET_PeerIdentity dummy;
399  unsigned int i;
400 
401  if (GNUNET_NO == GNUNET_DISK_file_test (cfgname))
402  {
404  "File not found: `%s'\n",
405  cfgname);
406  return NULL;
407  }
408 
410  p->tth = tth;
411  p->nc = nc;
412  p->nd = nd;
413  if (NULL != handlers)
414  {
415  for (i = 0; NULL != handlers[i].cb; i++)
416  ;
417  p->handlers = GNUNET_new_array (i + 1,
418  struct GNUNET_MQ_MessageHandler);
419  GNUNET_memcpy (p->handlers,
420  handlers,
421  i * sizeof(struct GNUNET_MQ_MessageHandler));
422  }
423  if (NULL != cb_cls)
424  p->cb_cls = cb_cls;
425  else
426  p->cb_cls = p;
427  p->start_cb = start_cb;
428  if (NULL != start_cb_cls)
429  p->start_cb_cls = start_cb_cls;
430  else
431  p->start_cb_cls = p;
433  tth->p_tail,
434  p);
435 
436  /* Create configuration and call testing lib to modify it */
437  p->cfg = GNUNET_CONFIGURATION_create ();
439  GNUNET_CONFIGURATION_load (p->cfg, cfgname));
440  if (GNUNET_SYSERR ==
442  p->cfg))
443  {
445  "Testing library failed to create unique configuration based on `%s'\n",
446  cfgname);
448  GNUNET_free (p);
449  return NULL;
450  }
451 
452  p->no = peer_id;
453  /* Configure peer with configuration */
455  p->cfg,
456  p->no,
457  NULL,
458  &emsg);
459  if (NULL == p->peer)
460  {
462  "Testing library failed to create unique configuration based on `%s': `%s'\n",
463  cfgname,
464  emsg);
466  GNUNET_free (emsg);
467  return NULL;
468  }
469 
470  if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer))
471  {
473  "Testing library failed to create unique configuration based on `%s'\n",
474  cfgname);
476  return NULL;
477  }
478 
479  memset (&dummy,
480  '\0',
481  sizeof(dummy));
483  &p->id);
484  if (0 == memcmp (&dummy,
485  &p->id,
486  sizeof(struct GNUNET_PeerIdentity)))
487  {
489  "Testing library failed to obtain peer identity for peer %u\n",
490  p->no);
492  return NULL;
493  }
495  "Peer %u configured with identity `%s'\n",
496  p->no,
497  GNUNET_i2s_full (&p->id));
498  p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
499  NULL,
500  handlers,
501  p,
504  if (NULL == p->th)
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->ph = GNUNET_PEERSTORE_connect (p->cfg);
526  // FIXME Error handling
528  GNUNET_assert (NULL != p->ah);
529  // FIXME Error handling
531 
532  return p;
533 }
534 
535 
536 int
540  void *restart_cb_cls)
541 {
544 
545  /* shutdown */
547  "Stopping peer %u (`%s')\n",
548  p->no,
549  GNUNET_i2s (&p->id));
550  if (NULL != p->pic)
551  {
553  p->pic = NULL;
554  }
555  if (NULL != p->th)
556  {
558  p->th = NULL;
559  }
560  for (cc = p->tth->cc_head; NULL != cc; cc = ccn)
561  {
562  ccn = cc->next;
563  if ((cc->p1 == p) ||
564  (cc->p2 == p))
566  }
567  if (NULL != p->ats)
568  {
570  p->ats = NULL;
571  }
572  if (GNUNET_SYSERR ==
573  GNUNET_TESTING_peer_stop (p->peer))
574  {
576  "Failed to stop peer %u (`%s')\n",
577  p->no,
578  GNUNET_i2s (&p->id));
579  return GNUNET_SYSERR;
580  }
581 
582  sleep (5); // YUCK!
583 
585  "Restarting peer %u (`%s')\n",
586  p->no,
587  GNUNET_i2s (&p->id));
588  /* restart */
590  {
592  "Failed to restart peer %u (`%s')\n",
593  p->no,
594  GNUNET_i2s (&p->id));
595  return GNUNET_SYSERR;
596  }
597 
598  GNUNET_assert (NULL == p->start_cb);
599  p->start_cb = restart_cb;
600  p->start_cb_cls = restart_cb_cls;
601 
602  p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
603  NULL,
604  p->handlers,
605  p,
608  GNUNET_assert (NULL != p->th);
609  p->ats = GNUNET_ATS_connectivity_init (p->cfg);
610  p->pic = GNUNET_PEERSTORE_iterate (p->ph,
611  "transport",
612  &p->id,
615  p);
616  GNUNET_assert (NULL != p->pic);
617  return GNUNET_OK;
618 }
619 
620 
626 void
629 {
630  struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
633  /* shutdown */
635  "Stopping peer %u (`%s')\n",
636  p->no,
637  GNUNET_i2s (&p->id));
638 
639  for (cc = tth->cc_head; NULL != cc; cc = ccn)
640  {
641  ccn = cc->next;
642  if ((cc->p1 == p) ||
643  (cc->p2 == p))
645  }
646  if (NULL != p->pic)
647  {
649  p->pic = NULL;
650  }
651  if (NULL != p->th)
652  {
654  p->th = NULL;
655  }
656  if (NULL != p->ats)
657  {
659  p->ats = NULL;
660  }
661  if (NULL != p->ah)
662  {
664  p->ah = NULL;
665  }
666  if (NULL != p->ph)
667  {
669  "Disconnecting from PEERSTORE service\n");
671  p->ph = NULL;
672  }
673 
674  if (NULL != p->peer)
675  {
676  if (GNUNET_OK !=
677  GNUNET_TESTING_peer_stop (p->peer))
678  {
680  "Testing lib failed to stop peer %u (`%s')\n",
681  p->no,
682  GNUNET_i2s (&p->id));
683  }
685  p->peer = NULL;
686  }
687  if (NULL != p->hello)
688  {
689  GNUNET_free (p->hello);
690  p->hello = NULL;
691  }
692  if (NULL != p->cfg)
693  {
695  p->cfg = NULL;
696  }
697  if (NULL != p->handlers)
698  {
699  GNUNET_free (p->handlers);
700  p->handlers = NULL;
701  }
703  tth->p_tail,
704  p);
706  "Peer %u (`%s') stopped\n",
707  p->no,
708  GNUNET_i2s (&p->id));
709  if (NULL != p->rh_task)
710  GNUNET_SCHEDULER_cancel (p->rh_task);
711  p->rh_task = NULL;
712  GNUNET_free (p);
713 }
714 
715 
721 /*
722  static void
723  hello_offered (void *cls)
724  {
725  struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls;
726 
727  cc->oh = NULL;
728  cc->tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
729  &offer_hello,
730  cc);
731  }*/
732 
733 
734 static void
735 offer_hello (void *cls)
736 {
738  struct GNUNET_TRANSPORT_TESTING_PeerContext *p1 = cc->p1;
739  struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = cc->p2;
740  struct GNUNET_TIME_Absolute t;
741  enum GNUNET_NetworkType nt = 0;
742  char *addr;
743 
744  cc->tct = NULL;
745  {
746  char *p2_s = GNUNET_strdup (GNUNET_i2s (&p2->id));
747 
749  "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %s\n",
750  p1->no,
751  GNUNET_i2s (&p1->id),
752  p2->no,
753  p2_s,
754  p2->hello);
755  GNUNET_free (p2_s);
756  }
757 
759  p2->hello_size,
760  &p2->id,
761  &nt,
762  &t);
763  GNUNET_assert (NULL != addr);
764  GNUNET_assert (NULL != p1->hello);
766  &p2->id,
767  nt,
768  addr);
769  GNUNET_free (addr);
770 }
771 
772 
788  struct
791  void *cls)
792 {
793  struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
796 
797  ccn = NULL;
798  for (cc = tth->cc_head; NULL != cc; cc = cc->next)
799  {
800  if ((cc->p1 == p1) &&
801  (cc->p2 == p2))
802  {
803  ccn = cc;
804  break;
805  }
806  }
807 
809  cc->p1 = p1;
810  cc->p2 = p2;
811  cc->cb = cb;
812  if (NULL != cls)
813  cc->cb_cls = cls;
814  else
815  cc->cb_cls = cc;
816  if (NULL != ccn)
817  {
818  cc->p1_c = ccn->p1_c;
819  cc->p2_c = ccn->p2_c;
820  cc->connected = ccn->connected;
821  }
823  tth->cc_tail,
824  cc);
826  cc);
828  &p2->id,
829  1);
831  "New connect request %p\n",
832  cc);
833  return cc;
834 }
835 
836 
837 void
840  *cc)
841 {
842  struct GNUNET_TRANSPORT_TESTING_Handle *tth = cc->p1->tth;
843 
845  "Canceling connect request!\n");
846  if (NULL != cc->tct)
847  {
849  cc->tct = NULL;
850  }
851  if (NULL != cc->ats_sh)
852  {
854  cc->ats_sh = NULL;
855  }
857  tth->cc_tail,
858  cc);
859  GNUNET_free (cc);
860 }
861 
862 
868 void
870 {
875 
876  if (NULL == tth)
877  return;
878  cc = tth->cc_head;
879  while (NULL != cc)
880  {
881  ct = cc->next;
883  "Developer forgot to cancel connect request!\n");
885  cc = ct;
886  }
887  p = tth->p_head;
888  while (NULL != p)
889  {
890  t = p->next;
892  "Developer forgot to stop peer!\n");
894  p = t;
895  }
897  GNUNET_YES);
898 
899  GNUNET_free (tth);
900 }
901 
902 
910 {
912 
914  tth->tl_system = GNUNET_TESTING_system_create ("transport-testing",
915  NULL,
916  NULL,
917  NULL);
918  if (NULL == tth->tl_system)
919  {
921  "Failed to initialize testing library!\n");
922  GNUNET_free (tth);
923  return NULL;
924  }
925  return tth;
926 }
927 
928 
929 /* 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 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_NAT_AUTO_Test * nt
Handle to a NAT test operation.
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
static struct GNUNET_SCHEDULER_Task * t
Main task.
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:481
#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.
char * GNUNET_HELLO_extract_address(const void *raw, size_t raw_size, const struct GNUNET_PeerIdentity *pid, enum GNUNET_NetworkType *nt, struct GNUNET_TIME_Absolute *mono_time)
Check signature and extract address record.
Definition: hello-ng.c:108
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
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_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_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:39
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
void GNUNET_PEERSTORE_iterate_cancel(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iterate request Please do not call after the iterate request is done.
#define GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY
Key used for storing HELLOs in the peerstore.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h, int sync_first)
Disconnect from the PEERSTORE service.
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iterate(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 records matching supplied key information.
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:1299
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:975
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1485
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:477
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:1188
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:557
int GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer)
Start the peer.
Definition: testing.c:1381
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:1167
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1566
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:1359
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_done(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
Shutdown TRANSPORT application client.
struct GNUNET_TRANSPORT_ApplicationHandle * GNUNET_TRANSPORT_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the TRANSPORT application client handle.
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_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_application_validate(struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_NetworkType nt, const char *addr)
An application (or a communicator) has received a HELLO (or other address data of another peer) and w...
void GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
Disconnect from the transport service.
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Single PEERSTORE record.
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
Time for absolute times used by GNUnet, in microseconds.
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.
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_TRANSPORT_ApplicationHandle * ah
Application handle.
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_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.
static void hello_iter_cb(void *cb_cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
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 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 retrieve_hello(void *cls)
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,...)
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.
static void offer_hello(void *cls)
Offer the current HELLO of P2 to P1.
void(* GNUNET_TRANSPORT_TESTING_ConnectContextCallback)(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
Function called on matching connect requests.