diff options
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/transport-testing.c | 38 | ||||
-rw-r--r-- | src/transport/transport-testing.h | 40 |
2 files changed, 68 insertions, 10 deletions
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index 24e4e8797..16e7a1e25 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c | |||
@@ -41,10 +41,10 @@ struct ConnectingContext | |||
41 | }; | 41 | }; |
42 | 42 | ||
43 | static void | 43 | static void |
44 | exchange_hello_last (void *cls, | 44 | exchange_hello_last (void *cb_cls, |
45 | const struct GNUNET_MessageHeader *message); | 45 | const struct GNUNET_MessageHeader *message); |
46 | static void | 46 | static void |
47 | exchange_hello (void *cls, | 47 | exchange_hello (void *cb_cls, |
48 | const struct GNUNET_MessageHeader *message); | 48 | const struct GNUNET_MessageHeader *message); |
49 | 49 | ||
50 | static void | 50 | static void |
@@ -120,10 +120,10 @@ notify_receive (void *cls, | |||
120 | 120 | ||
121 | 121 | ||
122 | static void | 122 | static void |
123 | exchange_hello_last (void *cls, | 123 | exchange_hello_last (void *cb_cls, |
124 | const struct GNUNET_MessageHeader *message) | 124 | const struct GNUNET_MessageHeader *message) |
125 | { | 125 | { |
126 | struct ConnectingContext * cc = cls; | 126 | struct ConnectingContext * cc = cb_cls; |
127 | struct PeerContext *me = cc->p2; | 127 | struct PeerContext *me = cc->p2; |
128 | //struct PeerContext *p1 = cc->p1; | 128 | //struct PeerContext *p1 = cc->p1; |
129 | 129 | ||
@@ -140,10 +140,10 @@ exchange_hello_last (void *cls, | |||
140 | 140 | ||
141 | 141 | ||
142 | static void | 142 | static void |
143 | exchange_hello (void *cls, | 143 | exchange_hello (void *cb_cls, |
144 | const struct GNUNET_MessageHeader *message) | 144 | const struct GNUNET_MessageHeader *message) |
145 | { | 145 | { |
146 | struct ConnectingContext * cc = cls; | 146 | struct ConnectingContext * cc = cb_cls; |
147 | struct PeerContext *me = cc->p1; | 147 | struct PeerContext *me = cc->p1; |
148 | //struct PeerContext *p2 = cc->p2; | 148 | //struct PeerContext *p2 = cc->p2; |
149 | 149 | ||
@@ -183,6 +183,15 @@ try_connect (void *cls, | |||
183 | cc); | 183 | cc); |
184 | } | 184 | } |
185 | 185 | ||
186 | |||
187 | /** | ||
188 | * Start a peer with the given configuration | ||
189 | * @param rec receive callback | ||
190 | * @param nc connect callback | ||
191 | * @param nd disconnect callback | ||
192 | * @param cb_cls closure for callback | ||
193 | * @return the peer context | ||
194 | */ | ||
186 | struct PeerContext * | 195 | struct PeerContext * |
187 | GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname, | 196 | GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname, |
188 | GNUNET_TRANSPORT_ReceiveCallback rec, | 197 | GNUNET_TRANSPORT_ReceiveCallback rec, |
@@ -222,6 +231,10 @@ GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname, | |||
222 | return p; | 231 | return p; |
223 | } | 232 | } |
224 | 233 | ||
234 | /** | ||
235 | * shutdown the given peer | ||
236 | * @param p the peer | ||
237 | */ | ||
225 | void | 238 | void |
226 | GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext * p) | 239 | GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext * p) |
227 | { | 240 | { |
@@ -245,11 +258,20 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext * p) | |||
245 | GNUNET_free (p); | 258 | GNUNET_free (p); |
246 | } | 259 | } |
247 | 260 | ||
261 | /** | ||
262 | * Connect the two given peers and call the callback when both peers report the | ||
263 | * inbound connect. Remarks: start_peer's notify_connect callback can be called | ||
264 | * before. | ||
265 | * @param p1 peer 1 | ||
266 | * @param p2 peer 2 | ||
267 | * @param cb the callback to call | ||
268 | * @param cb_cls callback cls | ||
269 | */ | ||
248 | void | 270 | void |
249 | GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext * p1, | 271 | GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext * p1, |
250 | struct PeerContext * p2, | 272 | struct PeerContext * p2, |
251 | GNUNET_TRANSPORT_TESTING_connect_cb cb, | 273 | GNUNET_TRANSPORT_TESTING_connect_cb cb, |
252 | void * cls) | 274 | void * cb_cls) |
253 | { | 275 | { |
254 | struct ConnectingContext * cc = GNUNET_malloc (sizeof (struct ConnectingContext)); | 276 | struct ConnectingContext * cc = GNUNET_malloc (sizeof (struct ConnectingContext)); |
255 | 277 | ||
@@ -260,7 +282,7 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext * p1, | |||
260 | cc->p2 = p2; | 282 | cc->p2 = p2; |
261 | 283 | ||
262 | cc->cb = cb; | 284 | cc->cb = cb; |
263 | cc->cb_cls = cls; | 285 | cc->cb_cls = cb_cls; |
264 | 286 | ||
265 | cc->th_p1 = GNUNET_TRANSPORT_connect(cc->p1->cfg, NULL, | 287 | cc->th_p1 = GNUNET_TRANSPORT_connect(cc->p1->cfg, NULL, |
266 | cc, | 288 | cc, |
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index cfcffaff6..25a772001 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h | |||
@@ -27,31 +27,51 @@ | |||
27 | 27 | ||
28 | #include "platform.h" | 28 | #include "platform.h" |
29 | #include "gnunet_common.h" | 29 | #include "gnunet_common.h" |
30 | #include "gnunet_hello_lib.h" | ||
31 | #include "gnunet_getopt_lib.h" | 30 | #include "gnunet_getopt_lib.h" |
32 | #include "gnunet_os_lib.h" | 31 | #include "gnunet_os_lib.h" |
33 | #include "gnunet_program_lib.h" | 32 | #include "gnunet_program_lib.h" |
34 | #include "gnunet_transport_service.h" | 33 | #include "gnunet_transport_service.h" |
35 | #include "transport.h" | ||
36 | 34 | ||
37 | 35 | ||
36 | /** | ||
37 | * Context for a single peer | ||
38 | */ | ||
38 | struct PeerContext | 39 | struct PeerContext |
39 | { | 40 | { |
40 | struct GNUNET_CONFIGURATION_Handle *cfg; | 41 | struct GNUNET_CONFIGURATION_Handle *cfg; |
42 | |||
41 | struct GNUNET_TRANSPORT_Handle *th; | 43 | struct GNUNET_TRANSPORT_Handle *th; |
44 | |||
42 | struct GNUNET_PeerIdentity id; | 45 | struct GNUNET_PeerIdentity id; |
46 | |||
43 | struct GNUNET_OS_Process *arm_proc; | 47 | struct GNUNET_OS_Process *arm_proc; |
44 | 48 | ||
45 | GNUNET_TRANSPORT_ReceiveCallback rec; | 49 | GNUNET_TRANSPORT_ReceiveCallback rec; |
50 | |||
46 | GNUNET_TRANSPORT_NotifyConnect nc; | 51 | GNUNET_TRANSPORT_NotifyConnect nc; |
52 | |||
47 | GNUNET_TRANSPORT_NotifyDisconnect nd; | 53 | GNUNET_TRANSPORT_NotifyDisconnect nd; |
54 | |||
48 | void * cb_cls; | 55 | void * cb_cls; |
49 | 56 | ||
50 | char * servicehome; | 57 | char * servicehome; |
51 | }; | 58 | }; |
52 | 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 | */ | ||
53 | typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1, struct PeerContext * p2, void *cls); | 64 | typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1, struct PeerContext * p2, void *cls); |
54 | 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 | */ | ||
55 | struct PeerContext * | 75 | struct PeerContext * |
56 | GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname, | 76 | GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname, |
57 | GNUNET_TRANSPORT_ReceiveCallback rec, | 77 | GNUNET_TRANSPORT_ReceiveCallback rec, |
@@ -59,9 +79,25 @@ GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname, | |||
59 | GNUNET_TRANSPORT_NotifyDisconnect nd, | 79 | GNUNET_TRANSPORT_NotifyDisconnect nd, |
60 | void * cb_cls); | 80 | void * cb_cls); |
61 | 81 | ||
82 | |||
83 | /** | ||
84 | * shutdown the given peer | ||
85 | * @param p the peer | ||
86 | */ | ||
87 | |||
62 | void | 88 | void |
63 | GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext * pc); | 89 | GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext * pc); |
64 | 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 | */ | ||
65 | void | 101 | void |
66 | GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext * p1, | 102 | GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext * p1, |
67 | struct PeerContext * p2, | 103 | struct PeerContext * p2, |