aboutsummaryrefslogtreecommitdiff
path: root/src/core/test_core_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-30 17:29:00 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-30 17:29:00 +0000
commit24dc89edc8d7f9eb5f23cd3e804fd9732858fbee (patch)
tree8c2062b0309958537a8e2daca5ce448625250686 /src/core/test_core_api.c
parentfc0a7982cd82e6f1915589a89c61dbe9d58aedb3 (diff)
downloadgnunet-24dc89edc8d7f9eb5f23cd3e804fd9732858fbee.tar.gz
gnunet-24dc89edc8d7f9eb5f23cd3e804fd9732858fbee.zip
converting core tests to hello_get API
Diffstat (limited to 'src/core/test_core_api.c')
-rw-r--r--src/core/test_core_api.c97
1 files changed, 65 insertions, 32 deletions
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c
index b012aa213..3f0b77bd1 100644
--- a/src/core/test_core_api.c
+++ b/src/core/test_core_api.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2015 GNUnet e.V. 3 Copyright (C) 2009, 2010, 2015, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -26,6 +26,7 @@
26#include "gnunet_core_service.h" 26#include "gnunet_core_service.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_transport_service.h" 28#include "gnunet_transport_service.h"
29#include "gnunet_transport_hello_service.h"
29#include "gnunet_ats_service.h" 30#include "gnunet_ats_service.h"
30 31
31#define MTYPE 12345 32#define MTYPE 12345
@@ -36,7 +37,7 @@ struct PeerContext
36 struct GNUNET_CORE_Handle *ch; 37 struct GNUNET_CORE_Handle *ch;
37 struct GNUNET_PeerIdentity id; 38 struct GNUNET_PeerIdentity id;
38 struct GNUNET_TRANSPORT_OfferHelloHandle *oh; 39 struct GNUNET_TRANSPORT_OfferHelloHandle *oh;
39 struct GNUNET_TRANSPORT_GetHelloHandle *ghh; 40 struct GNUNET_TRANSPORT_HelloGetHandle *ghh;
40 struct GNUNET_ATS_ConnectivityHandle *ats; 41 struct GNUNET_ATS_ConnectivityHandle *ats;
41 struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; 42 struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh;
42 struct GNUNET_MessageHeader *hello; 43 struct GNUNET_MessageHeader *hello;
@@ -71,7 +72,7 @@ process_hello (void *cls,
71 struct PeerContext *p = cls; 72 struct PeerContext *p = cls;
72 73
73 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 74 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
74 "Received (my) `%s' from transport service\n", "HELLO"); 75 "Received (my) HELLO from transport service\n");
75 GNUNET_assert (message != NULL); 76 GNUNET_assert (message != NULL);
76 if ((p == &p1) && (NULL == p2.oh)) 77 if ((p == &p1) && (NULL == p2.oh))
77 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, message, 78 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, message,
@@ -95,7 +96,7 @@ terminate_peer (struct PeerContext *p)
95 } 96 }
96 if (NULL != p->ghh) 97 if (NULL != p->ghh)
97 { 98 {
98 GNUNET_TRANSPORT_get_hello_cancel (p->ghh); 99 GNUNET_TRANSPORT_hello_get_cancel (p->ghh);
99 p->ghh = NULL; 100 p->ghh = NULL;
100 } 101 }
101 if (NULL != p->oh) 102 if (NULL != p->oh)
@@ -140,7 +141,9 @@ terminate_task_error (void *cls)
140 141
141 142
142static size_t 143static size_t
143transmit_ready (void *cls, size_t size, void *buf) 144transmit_ready (void *cls,
145 size_t size,
146 void *buf)
144{ 147{
145 struct PeerContext *p = cls; 148 struct PeerContext *p = cls;
146 struct GNUNET_MessageHeader *m; 149 struct GNUNET_MessageHeader *m;
@@ -162,20 +165,23 @@ connect_notify (void *cls,
162{ 165{
163 struct PeerContext *pc = cls; 166 struct PeerContext *pc = cls;
164 167
165 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) 168 if (0 == memcmp (&pc->id,
169 peer,
170 sizeof (struct GNUNET_PeerIdentity)))
166 return; 171 return;
167 GNUNET_assert (pc->connect_status == 0); 172 GNUNET_assert (pc->connect_status == 0);
168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
169 "Encrypted connection established to peer `%4s'\n", 174 "Encrypted connection established to peer `%s'\n",
170 GNUNET_i2s (peer)); 175 GNUNET_i2s (peer));
171 pc->connect_status = 1; 176 pc->connect_status = 1;
172 if (pc == &p1) 177 if (pc == &p1)
173 { 178 {
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 "Asking core (1) for transmission to peer `%4s'\n", 180 "Asking core (1) for transmission to peer `%s'\n",
176 GNUNET_i2s (&p2.id)); 181 GNUNET_i2s (&p2.id));
177 if (NULL == 182 if (NULL ==
178 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_YES, 183 GNUNET_CORE_notify_transmit_ready (p1.ch,
184 GNUNET_YES,
179 GNUNET_CORE_PRIO_BEST_EFFORT, 185 GNUNET_CORE_PRIO_BEST_EFFORT,
180 GNUNET_TIME_relative_multiply 186 GNUNET_TIME_relative_multiply
181 (GNUNET_TIME_UNIT_SECONDS, 145), 187 (GNUNET_TIME_UNIT_SECONDS, 145),
@@ -184,7 +190,7 @@ connect_notify (void *cls,
184 &transmit_ready, &p1)) 190 &transmit_ready, &p1))
185 { 191 {
186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", 193 "RECEIVED NULL when asking core (1) for transmission to peer `%s'\n",
188 GNUNET_i2s (&p2.id)); 194 GNUNET_i2s (&p2.id));
189 } 195 }
190 } 196 }
@@ -192,34 +198,41 @@ connect_notify (void *cls,
192 198
193 199
194static void 200static void
195disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) 201disconnect_notify (void *cls,
202 const struct GNUNET_PeerIdentity *peer)
196{ 203{
197 struct PeerContext *pc = cls; 204 struct PeerContext *pc = cls;
198 205
199 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) 206 if (0 == memcmp (&pc->id,
207 peer,
208 sizeof (struct GNUNET_PeerIdentity)))
200 return; 209 return;
201 pc->connect_status = 0; 210 pc->connect_status = 0;
202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted connection to `%4s' cut\n", 211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
212 "Encrypted connection to `%s' cut\n",
203 GNUNET_i2s (peer)); 213 GNUNET_i2s (peer));
204} 214}
205 215
206 216
207static int 217static int
208inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 218inbound_notify (void *cls,
219 const struct GNUNET_PeerIdentity *other,
209 const struct GNUNET_MessageHeader *message) 220 const struct GNUNET_MessageHeader *message)
210{ 221{
211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
212 "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); 223 "Core provides inbound data from `%s'.\n",
224 GNUNET_i2s (other));
213 return GNUNET_OK; 225 return GNUNET_OK;
214} 226}
215 227
216 228
217static int 229static int
218outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 230outbound_notify (void *cls,
231 const struct GNUNET_PeerIdentity *other,
219 const struct GNUNET_MessageHeader *message) 232 const struct GNUNET_MessageHeader *message)
220{ 233{
221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
222 "Core notifies about outbound data for `%4s'.\n", 235 "Core notifies about outbound data for `%s'.\n",
223 GNUNET_i2s (other)); 236 GNUNET_i2s (other));
224 return GNUNET_OK; 237 return GNUNET_OK;
225} 238}
@@ -231,12 +244,13 @@ process_mtype (void *cls,
231 const struct GNUNET_MessageHeader *message) 244 const struct GNUNET_MessageHeader *message)
232{ 245{
233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
234 "Receiving message from `%4s'.\n", 247 "Receiving message from `%s'.\n",
235 GNUNET_i2s (peer)); 248 GNUNET_i2s (peer));
236 GNUNET_assert (ok == 5); 249 GNUNET_assert (ok == 5);
237 OKPP; 250 OKPP;
238 GNUNET_SCHEDULER_cancel (err_task); 251 GNUNET_SCHEDULER_cancel (err_task);
239 err_task = GNUNET_SCHEDULER_add_now (&terminate_task, NULL); 252 err_task = GNUNET_SCHEDULER_add_now (&terminate_task,
253 NULL);
240 return GNUNET_OK; 254 return GNUNET_OK;
241} 255}
242 256
@@ -254,7 +268,7 @@ init_notify (void *cls,
254 struct PeerContext *p = cls; 268 struct PeerContext *p = cls;
255 269
256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
257 "Core connection to `%4s' established\n", 271 "Core connection to `%s' established\n",
258 GNUNET_i2s (my_identity)); 272 GNUNET_i2s (my_identity));
259 p->id = *my_identity; 273 p->id = *my_identity;
260 if (cls == &p1) 274 if (cls == &p1)
@@ -262,10 +276,14 @@ init_notify (void *cls,
262 GNUNET_assert (ok == 2); 276 GNUNET_assert (ok == 2);
263 OKPP; 277 OKPP;
264 /* connect p2 */ 278 /* connect p2 */
265 p2.ch = 279 p2.ch = GNUNET_CORE_connect (p2.cfg,
266 GNUNET_CORE_connect (p2.cfg, &p2, &init_notify, &connect_notify, 280 &p2,
267 &disconnect_notify, &inbound_notify, GNUNET_YES, 281 &init_notify,
268 &outbound_notify, GNUNET_YES, handlers); 282 &connect_notify,
283 &disconnect_notify,
284 &inbound_notify, GNUNET_YES,
285 &outbound_notify, GNUNET_YES,
286 handlers);
269 } 287 }
270 else 288 else
271 { 289 {
@@ -288,15 +306,23 @@ setup_peer (struct PeerContext *p,
288 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 306 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
289 p->cfg = GNUNET_CONFIGURATION_create (); 307 p->cfg = GNUNET_CONFIGURATION_create ();
290 p->arm_proc = 308 p->arm_proc =
291 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 309 GNUNET_OS_start_process (GNUNET_YES,
310 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
292 NULL, NULL, NULL, 311 NULL, NULL, NULL,
293 binary, 312 binary,
294 "gnunet-service-arm", 313 "gnunet-service-arm",
295 "-c", cfgname, NULL); 314 "-c",
296 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 315 cfgname,
316 NULL);
317 GNUNET_assert (GNUNET_OK ==
318 GNUNET_CONFIGURATION_load (p->cfg,
319 cfgname));
297 p->ats = GNUNET_ATS_connectivity_init (p->cfg); 320 p->ats = GNUNET_ATS_connectivity_init (p->cfg);
298 GNUNET_assert (NULL != p->ats); 321 GNUNET_assert (NULL != p->ats);
299 p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg, &process_hello, p); 322 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
323 GNUNET_TRANSPORT_AC_ANY,
324 &process_hello,
325 p);
300 GNUNET_free (binary); 326 GNUNET_free (binary);
301} 327}
302 328
@@ -342,9 +368,11 @@ stop_arm (struct PeerContext *p)
342 368
343 369
344int 370int
345main (int argc, char *argv1[]) 371main (int argc,
372 char *argv1[])
346{ 373{
347 char *const argv[] = { "test-core-api", 374 char *const argv[] = {
375 "test-core-api",
348 "-c", 376 "-c",
349 "test_core_api_data.conf", 377 "test_core_api_data.conf",
350 NULL 378 NULL
@@ -356,8 +384,13 @@ main (int argc, char *argv1[])
356 GNUNET_log_setup ("test-core-api", 384 GNUNET_log_setup ("test-core-api",
357 "WARNING", 385 "WARNING",
358 NULL); 386 NULL);
359 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, 387 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
360 "test-core-api", "nohelp", options, &run, &ok); 388 argv,
389 "test-core-api",
390 "nohelp",
391 options,
392 &run,
393 &ok);
361 stop_arm (&p1); 394 stop_arm (&p1);
362 stop_arm (&p2); 395 stop_arm (&p2);
363 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); 396 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");