GNUnet  0.10.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
59  void *cb_cls)
60 {
61  struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
64 
65  for (cc = tth->cc_head; NULL != cc; cc = ccn)
66  {
67  ccn = cc->next;
68  if ((cc->p1 == p1) &&
69  (cc->p2 == p2))
70  cb(cb_cls,
71  cc);
72  }
73 }
74 
75 
76 static void
77 set_p1c(void *cls,
79 {
80  int *found = cls;
81 
82  if (NULL != found)
83  *found = GNUNET_YES;
84  cx->p1_c = GNUNET_YES;
85 }
86 
87 
88 static void
89 set_mq(void *cls,
91 {
92  struct GNUNET_MQ_Handle *mq = cls;
93 
94  cx->mq = mq;
95 }
96 
97 
98 static void
99 set_p2c(void *cls,
101 {
102  int *found = cls;
103 
104  if (NULL != found)
105  *found = GNUNET_YES;
106  cx->p2_c = GNUNET_YES;
107 }
108 
109 
110 static void
111 clear_p1c(void *cls,
113 {
114  int *found = cls;
115 
116  if (NULL != found)
117  *found = GNUNET_YES;
118  cx->p1_c = GNUNET_NO;
119 }
120 
121 
122 static void
123 clear_p2c(void *cls,
125 {
126  int *found = cls;
127 
128  if (NULL != found)
129  *found = GNUNET_YES;
130  cx->p2_c = GNUNET_NO;
131 }
132 
133 
134 static void *
135 notify_connect(void *cls,
136  const struct GNUNET_PeerIdentity *peer,
137  struct GNUNET_MQ_Handle *mq)
138 {
140  struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
141  char *p2_s;
145  int found;
146  void *ret;
147 
148  p2 = find_peer_context(p->tth,
149  peer);
150  if (NULL != p->nc)
151  ret = p->nc(p->cb_cls,
152  peer,
153  mq);
154  else
155  ret = NULL;
156 
157  if (NULL != p2)
158  GNUNET_asprintf(&p2_s,
159  "%u (`%s')",
160  p2->no,
161  GNUNET_i2s(&p2->id));
162  else
163  GNUNET_asprintf(&p2_s,
164  "`%s'",
165  GNUNET_i2s(peer));
167  "Peers %s connected to peer %u (`%s')\n",
168  p2_s,
169  p->no,
170  GNUNET_i2s(&p->id));
171  GNUNET_free(p2_s);
172  /* update flags in connecting contexts */
173  found = GNUNET_NO;
175  p2,
176  &set_p1c,
177  &found);
178  if (GNUNET_NO == found)
179  {
181  cc->p1 = p;
182  cc->p2 = p2;
183  cc->p1_c = GNUNET_YES;
185  tth->cc_tail,
186  cc);
187  }
188  found = GNUNET_NO;
190  p,
191  &set_p2c,
192  &found);
193  if (GNUNET_NO == found)
194  {
196  cc->p1 = p2;
197  cc->p2 = p;
198  cc->p1_c = GNUNET_YES;
200  tth->cc_tail,
201  cc);
202  }
204  p2,
205  &set_mq,
206  mq);
207  /* update set connected flag for all requests */
208  for (cc = tth->cc_head; NULL != cc; cc = cc->next)
209  {
210  if (GNUNET_YES == cc->connected)
211  continue;
212  if ((GNUNET_YES == cc->p1_c) &&
213  (GNUNET_YES == cc->p2_c))
214  {
215  cc->connected = GNUNET_YES;
216  /* stop trying to connect */
217  if (NULL != cc->tct)
218  {
220  cc->tct = NULL;
221  }
222  if (NULL != cc->oh)
223  {
225  cc->oh = NULL;
226  }
227  if (NULL != cc->ats_sh)
228  {
230  cc->ats_sh = NULL;
231  }
232  }
233  }
234  /* then notify application */
235  for (cc = tth->cc_head; NULL != cc; cc = ccn)
236  {
237  ccn = cc->next;
238  if ((GNUNET_YES == cc->connected) &&
239  (NULL != cc->cb))
240  {
241  cc->cb(cc->cb_cls);
242  cc->cb = NULL; /* only notify once! */
243  }
244  }
245  return ret;
246 }
247 
248 
254 static void
255 offer_hello(void *cls);
256 
257 
258 static void
260  const struct GNUNET_PeerIdentity *peer,
261  void *handler_cls)
262 {
264  struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
265  char *p2_s;
266  /* Find PeerContext */
267  int no = 0;
268  struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL;
270 
271  p2 = find_peer_context(p->tth,
272  peer);
273  no = p->no;
274  if (NULL != p2)
275  GNUNET_asprintf(&p2_s,
276  "%u (`%s')",
277  p2->no,
278  GNUNET_i2s(&p2->id));
279  else
280  GNUNET_asprintf(&p2_s,
281  "`%s'",
282  GNUNET_i2s(peer));
284  "Peers %s disconnected from peer %u (`%s')\n",
285  p2_s,
286  no,
287  GNUNET_i2s(&p->id));
288  GNUNET_free(p2_s);
289  /* notify about disconnect */
290  if (NULL != p->nd)
291  p->nd(p->cb_cls,
292  peer,
293  handler_cls);
294  if (NULL == p2)
295  return;
296  /* clear MQ, it is now invalid */
298  p2,
299  &set_mq,
300  NULL);
301  /* update set connected flags for all requests */
303  p2,
304  &clear_p1c,
305  NULL);
307  p,
308  &clear_p2c,
309  NULL);
310  /* resume connectivity requests as necessary */
311  for (cc = tth->cc_head; NULL != cc; cc = cc->next)
312  {
313  if (GNUNET_NO == cc->connected)
314  continue;
315  if ((GNUNET_YES != cc->p1_c) ||
316  (GNUNET_YES != cc->p2_c))
317  {
318  cc->connected = GNUNET_NO;
319  /* start trying to connect */
320  if ((NULL == cc->tct) &&
321  (NULL == cc->oh))
323  cc);
324  if (NULL == cc->ats_sh)
326  &p2->id,
327  1);
328  }
329  }
330 }
331 
332 
333 static void
335  const struct GNUNET_MessageHeader *message)
336 {
338  struct GNUNET_PeerIdentity hello_id;
339 
341  GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)message,
342  &hello_id));
343  GNUNET_assert(0 == memcmp(&hello_id,
344  &p->id,
345  sizeof(hello_id)));
347  p->hello = (struct GNUNET_HELLO_Message *)GNUNET_copy_message(message);
348 
349  if (NULL != p->start_cb)
350  {
352  "Peer %u (`%s') successfully started\n",
353  p->no,
354  GNUNET_i2s(&p->id));
355  p->start_cb(p->start_cb_cls);
356  p->start_cb = NULL;
357  }
358 }
359 
360 
376  const char *cfgname,
377  int peer_id,
378  const struct GNUNET_MQ_MessageHandler *handlers,
381  void *cb_cls,
383  void *start_cb_cls)
384 {
385  char *emsg = NULL;
387  struct GNUNET_PeerIdentity dummy;
388  unsigned int i;
389 
390  if (GNUNET_NO == GNUNET_DISK_file_test(cfgname))
391  {
393  "File not found: `%s'\n",
394  cfgname);
395  return NULL;
396  }
397 
399  p->tth = tth;
400  p->nc = nc;
401  p->nd = nd;
402  if (NULL != handlers)
403  {
404  for (i = 0; NULL != handlers[i].cb; i++)
405  ;
406  p->handlers = GNUNET_new_array(i + 1,
407  struct GNUNET_MQ_MessageHandler);
409  handlers,
410  i * sizeof(struct GNUNET_MQ_MessageHandler));
411  }
412  if (NULL != cb_cls)
413  p->cb_cls = cb_cls;
414  else
415  p->cb_cls = p;
416  p->start_cb = start_cb;
417  if (NULL != start_cb_cls)
418  p->start_cb_cls = start_cb_cls;
419  else
420  p->start_cb_cls = p;
422  tth->p_tail,
423  p);
424 
425  /* Create configuration and call testing lib to modify it */
428  GNUNET_CONFIGURATION_load(p->cfg, cfgname));
429  if (GNUNET_SYSERR ==
431  p->cfg))
432  {
434  "Testing library failed to create unique configuration based on `%s'\n",
435  cfgname);
437  GNUNET_free(p);
438  return NULL;
439  }
440 
441  p->no = peer_id;
442  /* Configure peer with configuration */
444  p->cfg,
445  p->no,
446  NULL,
447  &emsg);
448  if (NULL == p->peer)
449  {
451  "Testing library failed to create unique configuration based on `%s': `%s'\n",
452  cfgname,
453  emsg);
455  GNUNET_free_non_null(emsg);
456  return NULL;
457  }
458  GNUNET_free_non_null(emsg);
460  {
462  "Testing library failed to create unique configuration based on `%s'\n",
463  cfgname);
465  return NULL;
466  }
467 
468  memset(&dummy,
469  '\0',
470  sizeof(dummy));
472  &p->id);
473  if (0 == memcmp(&dummy,
474  &p->id,
475  sizeof(struct GNUNET_PeerIdentity)))
476  {
478  "Testing library failed to obtain peer identity for peer %u\n",
479  p->no);
481  return NULL;
482  }
484  "Peer %u configured with identity `%s'\n",
485  p->no,
486  GNUNET_i2s_full(&p->id));
489  NULL,
490  handlers,
491  p,
494  NULL);
495  if ((NULL == p->th) ||
496  (NULL == p->tmh))
497  {
499  "Failed to connect to transport service for peer `%s': `%s'\n",
500  cfgname,
501  emsg);
503  return NULL;
504  }
506  if (NULL == p->ats)
507  {
509  "Failed to connect to ATS service for peer `%s': `%s'\n",
510  cfgname,
511  emsg);
513  return NULL;
514  }
517  &get_hello,
518  p);
519  GNUNET_assert(NULL != p->ghh);
520  return p;
521 }
522 
523 
532 int
535  void *restart_cb_cls)
536 {
539 
540  /* shutdown */
542  "Stopping peer %u (`%s')\n",
543  p->no,
544  GNUNET_i2s(&p->id));
545  if (NULL != p->ghh)
546  {
548  p->ghh = NULL;
549  }
550  if (NULL != p->th)
551  {
553  p->th = NULL;
554  }
555  if (NULL != p->tmh)
556  {
558  p->tmh = 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 ==
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 
603  NULL,
604  p->handlers,
605  p,
608  NULL);
609  GNUNET_assert(NULL != p->th);
613  &get_hello,
614  p);
615  GNUNET_assert(NULL != p->ghh);
616  return GNUNET_OK;
617 }
618 
619 
625 void
627 {
628  struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
631 
632  for (cc = tth->cc_head; NULL != cc; cc = ccn)
633  {
634  ccn = cc->next;
635  if ((cc->p1 == p) ||
636  (cc->p2 == p))
638  }
639  if (NULL != p->ghh)
640  {
642  p->ghh = NULL;
643  }
644  if (NULL != p->tmh)
645  {
647  p->tmh = NULL;
648  }
649  if (NULL != p->th)
650  {
652  p->th = NULL;
653  }
654  if (NULL != p->peer)
655  {
656  if (GNUNET_OK !=
658  {
660  "Testing lib failed to stop peer %u (`%s')\n",
661  p->no,
662  GNUNET_i2s(&p->id));
663  }
665  p->peer = NULL;
666  }
667  if (NULL != p->ats)
668  {
670  p->ats = NULL;
671  }
672  if (NULL != p->hello)
673  {
674  GNUNET_free(p->hello);
675  p->hello = NULL;
676  }
677  if (NULL != p->cfg)
678  {
680  p->cfg = NULL;
681  }
682  if (NULL != p->handlers)
683  {
684  GNUNET_free(p->handlers);
685  p->handlers = NULL;
686  }
688  tth->p_tail,
689  p);
691  "Peer %u (`%s') stopped\n",
692  p->no,
693  GNUNET_i2s(&p->id));
694  GNUNET_free(p);
695 }
696 
697 
702 static void
703 hello_offered(void *cls)
704 {
706 
707  cc->oh = NULL;
709  &offer_hello,
710  cc);
711 }
712 
713 
719 static void
720 offer_hello(void *cls)
721 {
723  struct GNUNET_TRANSPORT_TESTING_PeerContext *p1 = cc->p1;
724  struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = cc->p2;
725 
726  cc->tct = NULL;
727  {
728  char *p2_s = GNUNET_strdup(GNUNET_i2s(&p2->id));
729 
731  "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n",
732  p1->no,
733  GNUNET_i2s(&p1->id),
734  p2->no,
735  p2_s,
736  GNUNET_HELLO_size(cc->p2->hello));
737  GNUNET_free(p2_s);
738  }
739 
740  if (NULL != cc->oh)
742  cc->oh =
744  (const struct GNUNET_MessageHeader *)cc->p2->hello,
745  &hello_offered,
746  cc);
747 }
748 
749 
766  void *cls)
767 {
768  struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
771 
772  ccn = NULL;
773  for (cc = tth->cc_head; NULL != cc; cc = cc->next)
774  {
775  if ((cc->p1 == p1) &&
776  (cc->p2 == p2))
777  {
778  ccn = cc;
779  break;
780  }
781  }
782 
784  cc->p1 = p1;
785  cc->p2 = p2;
786  cc->cb = cb;
787  if (NULL != cls)
788  cc->cb_cls = cls;
789  else
790  cc->cb_cls = cc;
791  if (NULL != ccn)
792  {
793  cc->p1_c = ccn->p1_c;
794  cc->p2_c = ccn->p2_c;
795  cc->connected = ccn->connected;
796  }
798  tth->cc_tail,
799  cc);
801  cc);
803  &p2->id,
804  1);
806  "New connect request %p\n",
807  cc);
808  return cc;
809 }
810 
811 
819 void
821 {
822  struct GNUNET_TRANSPORT_TESTING_Handle *tth = cc->p1->tth;
823 
825  "Canceling connect request!\n");
826  if (NULL != cc->tct)
827  {
829  cc->tct = NULL;
830  }
831  if (NULL != cc->oh)
832  {
834  cc->oh = NULL;
835  }
836  if (NULL != cc->ats_sh)
837  {
839  cc->ats_sh = NULL;
840  }
842  tth->cc_tail,
843  cc);
844  GNUNET_free(cc);
845 }
846 
847 
853 void
855 {
860 
861  if (NULL == tth)
862  return;
863  cc = tth->cc_head;
864  while (NULL != cc)
865  {
866  ct = cc->next;
868  "Developer forgot to cancel connect request!\n");
870  cc = ct;
871  }
872  p = tth->p_head;
873  while (NULL != p)
874  {
875  t = p->next;
877  "Developer forgot to stop peer!\n");
879  p = t;
880  }
882  GNUNET_YES);
883 
884  GNUNET_free(tth);
885 }
886 
887 
895 {
897 
899  tth->tl_system = GNUNET_TESTING_system_create("transport-testing",
900  NULL,
901  NULL,
902  NULL);
903  if (NULL == tth->tl_system)
904  {
906  "Failed to initialize testing library!\n");
907  GNUNET_free(tth);
908  return NULL;
909  }
910  return tth;
911 }
912 
913 /* end of transport-testing.c */
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
int 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:541
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:662
Handle for a request to connect two peers.
static void * notify_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * next
Kept in a DLL.
A HELLO message is used to exchange information about transports with other peers.
static void get_hello(void *cb_cls, const struct GNUNET_MessageHeader *message)
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.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_TRANSPORT_TESTING_Handle * tth
Transport testing handle this peer belongs to.
struct GNUNET_CONFIGURATION_Handle * cfg
Peer&#39;s configuration.
int GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer)
Start the peer.
Definition: testing.c:1355
static struct GNUNET_TRANSPORT_TESTING_PeerContext * find_peer_context(struct GNUNET_TRANSPORT_TESTING_Handle *tth, const struct GNUNET_PeerIdentity *peer)
struct GNUNET_PeerIdentity id
Peer identity.
struct GNUNET_TRANSPORT_OfferHelloHandle * oh
Handle by which we inform the peer about the HELLO of the other peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TRANSPORT_TESTING_Handle * GNUNET_TRANSPORT_TESTING_init()
Initialize the transport testing.
Context for a single peer.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_TRANSPORT_NotifyDisconnect nd
Notify disconnect callback.
static void clear_p2c(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
#define GNUNET_NO
Definition: gnunet_common.h:78
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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.
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_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_ATS_ConnectivitySuggestHandle * ats_sh
Handle by which we ask ATS to faciliate the connection.
struct GNUNET_MQ_MessageHandler * handlers
Receive callback.
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define LOG(kind,...)
unsigned int no
An unique number to identify the peer.
struct GNUNET_TRANSPORT_TESTING_PeerContext * next
Next element in the DLL.
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc_head
head DLL of connect contexts
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1460
struct GNUNET_TESTING_System * tl_system
Testing library system handle.
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:1141
static void clear_p1c(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
void GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth)
Clean up the transport testing.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
GNUNET_SCHEDULER_TaskCallback start_cb
Startup completed callback.
int GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
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:1162
static void set_p1c(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
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.
struct GNUNET_MQ_Handle * mq
Message queue for sending from p1 to p2.
static void notify_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)
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. ...
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
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:1237
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 struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
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:1264
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
int p1_c
Set if peer1 says the connection is up to peer2.
void(* GNUNET_TRANSPORT_TESTING_ConnectContextCallback)(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
Function called on matching connect requests.
struct GNUNET_TRANSPORT_ManipulationHandle * tmh
Peer&#39;s transport service manipulation handle.
GNUNET_MQ_MessageCallback cb
Callback, called every time a new message of the specified type has been receied. ...
struct GNUNET_TRANSPORT_CoreHandle * th
Peer&#39;s transport service handle.
Message handler for a specific message type.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p_head
head DLL of peers
void GNUNET_TRANSPORT_offer_hello_cancel(struct GNUNET_TRANSPORT_OfferHelloHandle *ohh)
Cancel the request to transport to offer the HELLO message.
struct GNUNET_ATS_ConnectivityHandle * ats
Peer&#39;s ATS handle.
struct GNUNET_TESTING_Peer * peer
Peer&#39;s testing handle.
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
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:530
struct GNUNET_TRANSPORT_TESTING_PeerContext * p2
Peer we want to connect.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
int connected
GNUNET_YES if both p1_c and p2_c are GNUNET_YES.
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 ...
GNUNET_SCHEDULER_TaskCallback cb
Function to call upon completion.
GNUNET_TRANSPORT_NotifyConnect nc
Notify connect callback.
static void set_p2c(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
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&#39;s HELLO message.
Handle to a message queue.
Definition: mq.c:84
struct GNUNET_ATS_ConnectivityHandle * GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the ATS connectivity suggestion client handle.
static void offer_hello(void *cls)
Offer the current HELLO of P2 to P1.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_TRANSPORT_ManipulationHandle * GNUNET_TRANSPORT_manipulation_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the transport service.
static void set_mq(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
struct GNUNET_HELLO_Message * hello
Peers HELLO Message.
static void hello_offered(void *cls)
Function called after the HELLO was passed to the transport service.
void GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
Disconnect from the transport service.
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.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
struct GNUNET_TRANSPORT_TESTING_PeerContext * p1
Peer we want to connect.
void GNUNET_TRANSPORT_manipulation_disconnect(struct GNUNET_TRANSPORT_ManipulationHandle *handle)
Disconnect from 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.
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:643
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:1333
Header for all communications.
static void start_cb(void *cls)
Function called once we have successfully launched a peer.
#define GNUNET_YES
Definition: gnunet_common.h:77
void * cb_cls
Closure for the nc and nd callbacks.
struct GNUNET_SCHEDULER_Task * tct
Task by which we accomplish the connection.
void GNUNET_TRANSPORT_TESTING_stop_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *p)
Shutdown the given peer.
int p2_c
Set if peer2 says the connection is up to peer1.
struct GNUNET_TRANSPORT_HelloGetHandle * ghh
Peer&#39;s transport get hello handle to retrieve peer&#39;s HELLO message.
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.
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1552
void GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch)
Client is done with ATS connectivity management, release resources.
void * start_cb_cls
Closure for start_cb.
testing lib for transport service
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void GNUNET_TRANSPORT_hello_get_cancel(struct GNUNET_TRANSPORT_HelloGetHandle *ghh)
Stop receiving updates about changes to our HELLO message.
struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc_tail
head DLL of connect contexts
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_TRANSPORT_TESTING_PeerContext * p_tail
tail DLL of peers
struct GNUNET_MessageHeader * GNUNET_copy_message(const struct GNUNET_MessageHeader *msg)
Create a copy of the given message.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956