diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-06-10 09:43:54 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-06-10 09:43:54 +0000 |
commit | 8adc5b8550b47b708777a09956a80c5ea273d461 (patch) | |
tree | b28b1e674fd23961cb1de2e376b738b9e36575df /src/core/test_core_api.c | |
parent | 5be3109144739c8e2dc4cbdda4611f954f77a26b (diff) | |
download | gnunet-8adc5b8550b47b708777a09956a80c5ea273d461.tar.gz gnunet-8adc5b8550b47b708777a09956a80c5ea273d461.zip |
fixing confs
Diffstat (limited to 'src/core/test_core_api.c')
-rw-r--r-- | src/core/test_core_api.c | 130 |
1 files changed, 73 insertions, 57 deletions
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index 212dd9d5f..c7f73120d 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c | |||
@@ -58,6 +58,8 @@ static struct PeerContext p2; | |||
58 | 58 | ||
59 | static GNUNET_SCHEDULER_TaskIdentifier err_task; | 59 | static GNUNET_SCHEDULER_TaskIdentifier err_task; |
60 | 60 | ||
61 | static GNUNET_SCHEDULER_TaskIdentifier con_task; | ||
62 | |||
61 | static int ok; | 63 | static int ok; |
62 | 64 | ||
63 | #if VERBOSE | 65 | #if VERBOSE |
@@ -67,6 +69,22 @@ static int ok; | |||
67 | #endif | 69 | #endif |
68 | 70 | ||
69 | 71 | ||
72 | static void | ||
73 | process_hello (void *cls, | ||
74 | const struct GNUNET_MessageHeader *message) | ||
75 | { | ||
76 | struct PeerContext *p = cls; | ||
77 | |||
78 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
79 | "Received (my) `%s' from transport service\n", | ||
80 | "HELLO"); | ||
81 | GNUNET_assert (message != NULL); | ||
82 | if ((p == &p1) && (p2.th != NULL)) | ||
83 | GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); | ||
84 | if ((p == &p2) && (p1.th != NULL)) | ||
85 | GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL); | ||
86 | } | ||
87 | |||
70 | 88 | ||
71 | static void | 89 | static void |
72 | terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 90 | terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -74,6 +92,8 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
74 | GNUNET_assert (ok == 6); | 92 | GNUNET_assert (ok == 6); |
75 | GNUNET_CORE_disconnect (p1.ch); | 93 | GNUNET_CORE_disconnect (p1.ch); |
76 | GNUNET_CORE_disconnect (p2.ch); | 94 | GNUNET_CORE_disconnect (p2.ch); |
95 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1); | ||
96 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2); | ||
77 | GNUNET_TRANSPORT_disconnect (p1.th); | 97 | GNUNET_TRANSPORT_disconnect (p1.th); |
78 | GNUNET_TRANSPORT_disconnect (p2.th); | 98 | GNUNET_TRANSPORT_disconnect (p2.th); |
79 | ok = 0; | 99 | ok = 0; |
@@ -89,6 +109,8 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
89 | GNUNET_break (0); | 109 | GNUNET_break (0); |
90 | GNUNET_CORE_disconnect (p1.ch); | 110 | GNUNET_CORE_disconnect (p1.ch); |
91 | GNUNET_CORE_disconnect (p2.ch); | 111 | GNUNET_CORE_disconnect (p2.ch); |
112 | GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1); | ||
113 | GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2); | ||
92 | GNUNET_TRANSPORT_disconnect (p1.th); | 114 | GNUNET_TRANSPORT_disconnect (p1.th); |
93 | GNUNET_TRANSPORT_disconnect (p2.th); | 115 | GNUNET_TRANSPORT_disconnect (p2.th); |
94 | ok = 42; | 116 | ok = 42; |
@@ -108,10 +130,6 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
108 | m = (struct GNUNET_MessageHeader *) buf; | 130 | m = (struct GNUNET_MessageHeader *) buf; |
109 | m->type = htons (MTYPE); | 131 | m->type = htons (MTYPE); |
110 | m->size = htons (sizeof (struct GNUNET_MessageHeader)); | 132 | m->size = htons (sizeof (struct GNUNET_MessageHeader)); |
111 | err_task = | ||
112 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120), | ||
113 | &terminate_task_error, NULL); | ||
114 | |||
115 | return sizeof (struct GNUNET_MessageHeader); | 133 | return sizeof (struct GNUNET_MessageHeader); |
116 | } | 134 | } |
117 | 135 | ||
@@ -128,13 +146,18 @@ connect_notify (void *cls, | |||
128 | sizeof (struct GNUNET_PeerIdentity))) | 146 | sizeof (struct GNUNET_PeerIdentity))) |
129 | return; | 147 | return; |
130 | GNUNET_assert (pc->connect_status == 0); | 148 | GNUNET_assert (pc->connect_status == 0); |
149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
150 | "Encrypted connection established to peer `%4s'\n", | ||
151 | GNUNET_i2s (peer)); | ||
152 | if (GNUNET_SCHEDULER_NO_TASK != con_task) | ||
153 | { | ||
154 | GNUNET_SCHEDULER_cancel (con_task); | ||
155 | con_task = GNUNET_SCHEDULER_NO_TASK; | ||
156 | } | ||
131 | pc->connect_status = 1; | 157 | pc->connect_status = 1; |
132 | if (pc == &p1) | 158 | if (pc == &p1) |
133 | { | 159 | { |
134 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
135 | "Encrypted connection established to peer `%4s'\n", | ||
136 | GNUNET_i2s (peer)); | ||
137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
138 | "Asking core (1) for transmission to peer `%4s'\n", | 161 | "Asking core (1) for transmission to peer `%4s'\n", |
139 | GNUNET_i2s (&p2.id)); | 162 | GNUNET_i2s (&p2.id)); |
140 | if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch, | 163 | if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch, |
@@ -206,7 +229,7 @@ process_mtype (void *cls, | |||
206 | GNUNET_assert (ok == 5); | 229 | GNUNET_assert (ok == 5); |
207 | OKPP; | 230 | OKPP; |
208 | GNUNET_SCHEDULER_cancel (err_task); | 231 | GNUNET_SCHEDULER_cancel (err_task); |
209 | GNUNET_SCHEDULER_add_now (&terminate_task, NULL); | 232 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task, NULL); |
210 | return GNUNET_OK; | 233 | return GNUNET_OK; |
211 | } | 234 | } |
212 | 235 | ||
@@ -218,6 +241,26 @@ static struct GNUNET_CORE_MessageHandler handlers[] = { | |||
218 | 241 | ||
219 | 242 | ||
220 | static void | 243 | static void |
244 | connect_task (void *cls, | ||
245 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
246 | { | ||
247 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
248 | { | ||
249 | con_task = GNUNET_SCHEDULER_NO_TASK; | ||
250 | return; | ||
251 | } | ||
252 | con_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
253 | &connect_task, | ||
254 | NULL); | ||
255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
256 | "Asking core (1) to connect to peer `%4s'\n", | ||
257 | GNUNET_i2s (&p2.id)); | ||
258 | GNUNET_CORE_peer_request_connect (p1.ch, | ||
259 | &p2.id, | ||
260 | NULL, NULL); | ||
261 | } | ||
262 | |||
263 | static void | ||
221 | init_notify (void *cls, | 264 | init_notify (void *cls, |
222 | struct GNUNET_CORE_Handle *server, | 265 | struct GNUNET_CORE_Handle *server, |
223 | const struct GNUNET_PeerIdentity *my_identity, | 266 | const struct GNUNET_PeerIdentity *my_identity, |
@@ -236,58 +279,28 @@ init_notify (void *cls, | |||
236 | GNUNET_assert (ok == 2); | 279 | GNUNET_assert (ok == 2); |
237 | OKPP; | 280 | OKPP; |
238 | /* connect p2 */ | 281 | /* connect p2 */ |
239 | GNUNET_CORE_connect (p2.cfg, 1, | 282 | p2.ch = GNUNET_CORE_connect (p2.cfg, 1, |
240 | &p2, | 283 | &p2, |
241 | &init_notify, | 284 | &init_notify, |
242 | &connect_notify, | 285 | &connect_notify, |
243 | &disconnect_notify, | 286 | &disconnect_notify, |
244 | NULL, | 287 | NULL, |
245 | &inbound_notify, | 288 | &inbound_notify, |
246 | GNUNET_YES, | 289 | GNUNET_YES, |
247 | &outbound_notify, GNUNET_YES, handlers); | 290 | &outbound_notify, GNUNET_YES, handlers); |
248 | } | 291 | } |
249 | else | 292 | else |
250 | { | 293 | { |
251 | GNUNET_assert (ok == 3); | 294 | GNUNET_assert (ok == 3); |
252 | OKPP; | 295 | OKPP; |
253 | GNUNET_assert (cls == &p2); | 296 | GNUNET_assert (cls == &p2); |
254 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 297 | con_task = GNUNET_SCHEDULER_add_now (&connect_task, |
255 | "Asking core (1) to connect to peer `%4s'\n", | 298 | NULL); |
256 | GNUNET_i2s (&p2.id)); | ||
257 | GNUNET_CORE_peer_request_connect (p1.ch, | ||
258 | &p2.id, | ||
259 | NULL, NULL); | ||
260 | } | 299 | } |
261 | } | 300 | } |
262 | 301 | ||
263 | 302 | ||
264 | static void | 303 | static void |
265 | process_hello (void *cls, | ||
266 | const struct GNUNET_MessageHeader *message) | ||
267 | { | ||
268 | struct PeerContext *p = cls; | ||
269 | |||
270 | GNUNET_TRANSPORT_get_hello_cancel (p->th, &process_hello, p); | ||
271 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
272 | "Received (my) `%s' from transport service\n", | ||
273 | "HELLO"); | ||
274 | GNUNET_assert (message != NULL); | ||
275 | p->hello = GNUNET_malloc (ntohs (message->size)); | ||
276 | memcpy (p->hello, message, ntohs (message->size)); | ||
277 | if ((p == &p1) && (p2.th != NULL)) | ||
278 | GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); | ||
279 | if ((p == &p2) && (p1.th != NULL)) | ||
280 | GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL); | ||
281 | |||
282 | if ((p == &p1) && (p2.hello != NULL)) | ||
283 | GNUNET_TRANSPORT_offer_hello (p1.th, p2.hello, NULL, NULL); | ||
284 | if ((p == &p2) && (p1.hello != NULL)) | ||
285 | GNUNET_TRANSPORT_offer_hello (p2.th, p1.hello, NULL, NULL); | ||
286 | } | ||
287 | |||
288 | |||
289 | |||
290 | static void | ||
291 | setup_peer (struct PeerContext *p, const char *cfgname) | 304 | setup_peer (struct PeerContext *p, const char *cfgname) |
292 | { | 305 | { |
293 | p->cfg = GNUNET_CONFIGURATION_create (); | 306 | p->cfg = GNUNET_CONFIGURATION_create (); |
@@ -316,14 +329,17 @@ run (void *cls, | |||
316 | OKPP; | 329 | OKPP; |
317 | setup_peer (&p1, "test_core_api_peer1.conf"); | 330 | setup_peer (&p1, "test_core_api_peer1.conf"); |
318 | setup_peer (&p2, "test_core_api_peer2.conf"); | 331 | setup_peer (&p2, "test_core_api_peer2.conf"); |
319 | GNUNET_CORE_connect (p1.cfg, 1, | 332 | err_task = |
320 | &p1, | 333 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120), |
321 | &init_notify, | 334 | &terminate_task_error, NULL); |
322 | &connect_notify, | 335 | p1.ch = GNUNET_CORE_connect (p1.cfg, 1, |
323 | &disconnect_notify, | 336 | &p1, |
324 | NULL, | 337 | &init_notify, |
325 | &inbound_notify, | 338 | &connect_notify, |
326 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); | 339 | &disconnect_notify, |
340 | NULL, | ||
341 | &inbound_notify, | ||
342 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); | ||
327 | } | 343 | } |
328 | 344 | ||
329 | static void | 345 | static void |