25a7720013d22121103267a3180e149e30d813ea
[oweals/gnunet.git] / src / transport / transport-testing.h
1 /*
2      This file is part of GNUnet.
3      (C) 2006, 2009 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 2, or (at your
8      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      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file transport_testing.h
23  * @brief testing lib for transport service
24  *
25  * @author Matthias Wachs
26  */
27
28 #include "platform.h"
29 #include "gnunet_common.h"
30 #include "gnunet_getopt_lib.h"
31 #include "gnunet_os_lib.h"
32 #include "gnunet_program_lib.h"
33 #include "gnunet_transport_service.h"
34
35
36 /**
37  * Context for a single peer
38  */
39 struct PeerContext
40 {
41   struct GNUNET_CONFIGURATION_Handle *cfg;
42
43   struct GNUNET_TRANSPORT_Handle *th;
44
45   struct GNUNET_PeerIdentity id;
46
47   struct GNUNET_OS_Process *arm_proc;
48
49   GNUNET_TRANSPORT_ReceiveCallback rec;
50
51   GNUNET_TRANSPORT_NotifyConnect nc;
52
53   GNUNET_TRANSPORT_NotifyDisconnect nd;
54
55   void * cb_cls;
56
57   char * servicehome;
58 };
59
60 /**
61  * Callback when two peers are connected and both have called the connect callback
62  * to notify clients about a new peer
63  */
64 typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1, struct PeerContext * p2, void *cls);
65
66
67 /**
68  * Start a peer with the given configuration
69  * @param rec receive callback
70  * @param nc connect callback
71  * @param nd disconnect callback
72  * @param cb_cls closure for callback
73  * @return the peer context
74  */
75 struct PeerContext *
76 GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname,
77     GNUNET_TRANSPORT_ReceiveCallback rec,
78     GNUNET_TRANSPORT_NotifyConnect nc,
79     GNUNET_TRANSPORT_NotifyDisconnect nd,
80     void * cb_cls);
81
82
83 /**
84  * shutdown the given peer
85  * @param p the peer
86  */
87
88 void
89 GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext * pc);
90
91
92 /**
93  * Connect the given peers and call the callback when both peers report the
94  * inbound connection. Remarks: start_peer's notify_connect callback can be called
95  * before.
96  * @param p1 peer 1
97  * @param p2 peer 2
98  * @param cb the callback to call
99  * @param cb_cls callback cls
100  */
101 void
102 GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext * p1,
103     struct PeerContext * p2,
104     GNUNET_TRANSPORT_TESTING_connect_cb cb,
105     void * cls);
106
107 /* end of transport_testing.h */