diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-10-29 14:20:22 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-10-29 14:20:22 +0000 |
commit | 8459c76076092899a74aa7e4451ed24faf91684b (patch) | |
tree | f66e960ec08f0270387afcbed3e10ea2cb04d6cd /src/core/test_core_api.c | |
parent | 6486831b520ad18632aa117ee8c15305d6b89c29 (diff) | |
download | gnunet-8459c76076092899a74aa7e4451ed24faf91684b.tar.gz gnunet-8459c76076092899a74aa7e4451ed24faf91684b.zip |
-preparations for replacement of try_connect call
Diffstat (limited to 'src/core/test_core_api.c')
-rw-r--r-- | src/core/test_core_api.c | 83 |
1 files changed, 41 insertions, 42 deletions
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index 6f946e2fa..b1c6c8212 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 Christian Grothoff (and other contributing authors) | 3 | Copyright (C) 2009, 2010, 2015 Christian Grothoff (and other contributing authors) |
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 |
@@ -24,11 +24,9 @@ | |||
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_arm_service.h" | 25 | #include "gnunet_arm_service.h" |
26 | #include "gnunet_core_service.h" | 26 | #include "gnunet_core_service.h" |
27 | #include "gnunet_getopt_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_os_lib.h" | ||
29 | #include "gnunet_program_lib.h" | ||
30 | #include "gnunet_scheduler_lib.h" | ||
31 | #include "gnunet_transport_service.h" | 28 | #include "gnunet_transport_service.h" |
29 | #include "gnunet_ats_service.h" | ||
32 | 30 | ||
33 | #define MTYPE 12345 | 31 | #define MTYPE 12345 |
34 | 32 | ||
@@ -39,6 +37,8 @@ struct PeerContext | |||
39 | struct GNUNET_PeerIdentity id; | 37 | struct GNUNET_PeerIdentity id; |
40 | struct GNUNET_TRANSPORT_Handle *th; | 38 | struct GNUNET_TRANSPORT_Handle *th; |
41 | struct GNUNET_TRANSPORT_GetHelloHandle *ghh; | 39 | struct GNUNET_TRANSPORT_GetHelloHandle *ghh; |
40 | struct GNUNET_ATS_ConnectivityHandle *ats; | ||
41 | struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; | ||
42 | struct GNUNET_MessageHeader *hello; | 42 | struct GNUNET_MessageHeader *hello; |
43 | int connect_status; | 43 | int connect_status; |
44 | struct GNUNET_OS_Process *arm_proc; | 44 | struct GNUNET_OS_Process *arm_proc; |
@@ -48,9 +48,9 @@ static struct PeerContext p1; | |||
48 | 48 | ||
49 | static struct PeerContext p2; | 49 | static struct PeerContext p2; |
50 | 50 | ||
51 | static struct GNUNET_SCHEDULER_Task * err_task; | 51 | static struct GNUNET_SCHEDULER_Task *err_task; |
52 | 52 | ||
53 | static struct GNUNET_SCHEDULER_Task * con_task; | 53 | static struct GNUNET_SCHEDULER_Task *con_task; |
54 | 54 | ||
55 | static int ok; | 55 | static int ok; |
56 | 56 | ||
@@ -74,22 +74,39 @@ process_hello (void *cls, | |||
74 | 74 | ||
75 | 75 | ||
76 | static void | 76 | static void |
77 | terminate_peer (struct PeerContext *p) | ||
78 | { | ||
79 | if (NULL != p->ch) | ||
80 | { | ||
81 | GNUNET_CORE_disconnect (p->ch); | ||
82 | p->ch = NULL; | ||
83 | } | ||
84 | if (NULL != p->th) | ||
85 | { | ||
86 | GNUNET_TRANSPORT_get_hello_cancel (p->ghh); | ||
87 | GNUNET_TRANSPORT_disconnect (p->th); | ||
88 | p->th = NULL; | ||
89 | } | ||
90 | if (NULL != p->ats_sh) | ||
91 | { | ||
92 | GNUNET_ATS_connectivity_suggest_cancel (p->ats_sh); | ||
93 | p->ats_sh = NULL; | ||
94 | } | ||
95 | if (NULL != p->ats) | ||
96 | { | ||
97 | GNUNET_ATS_connectivity_done (p->ats); | ||
98 | p->ats = NULL; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | |||
103 | static void | ||
77 | terminate_task (void *cls, | 104 | terminate_task (void *cls, |
78 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 105 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
79 | { | 106 | { |
80 | GNUNET_assert (ok == 6); | 107 | GNUNET_assert (ok == 6); |
81 | GNUNET_CORE_disconnect (p1.ch); | 108 | terminate_peer (&p1); |
82 | p1.ch = NULL; | 109 | terminate_peer (&p2); |
83 | GNUNET_CORE_disconnect (p2.ch); | ||
84 | p2.ch = NULL; | ||
85 | GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); | ||
86 | p1.ghh = NULL; | ||
87 | GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); | ||
88 | p2.ghh = NULL; | ||
89 | GNUNET_TRANSPORT_disconnect (p1.th); | ||
90 | p1.th = NULL; | ||
91 | GNUNET_TRANSPORT_disconnect (p2.th); | ||
92 | p2.th = NULL; | ||
93 | if (NULL != con_task) | 110 | if (NULL != con_task) |
94 | { | 111 | { |
95 | GNUNET_SCHEDULER_cancel (con_task); | 112 | GNUNET_SCHEDULER_cancel (con_task); |
@@ -107,28 +124,8 @@ terminate_task_error (void *cls, | |||
107 | "ENDING ANGRILY %u\n", | 124 | "ENDING ANGRILY %u\n", |
108 | ok); | 125 | ok); |
109 | GNUNET_break (0); | 126 | GNUNET_break (0); |
110 | if (NULL != p1.ch) | 127 | terminate_peer (&p1); |
111 | { | 128 | terminate_peer (&p2); |
112 | GNUNET_CORE_disconnect (p1.ch); | ||
113 | p1.ch = NULL; | ||
114 | } | ||
115 | if (NULL != p2.ch) | ||
116 | { | ||
117 | GNUNET_CORE_disconnect (p2.ch); | ||
118 | p2.ch = NULL; | ||
119 | } | ||
120 | if (p1.th != NULL) | ||
121 | { | ||
122 | GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); | ||
123 | GNUNET_TRANSPORT_disconnect (p1.th); | ||
124 | p1.th = NULL; | ||
125 | } | ||
126 | if (p2.th != NULL) | ||
127 | { | ||
128 | GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); | ||
129 | GNUNET_TRANSPORT_disconnect (p2.th); | ||
130 | p2.th = NULL; | ||
131 | } | ||
132 | if (NULL != con_task) | 129 | if (NULL != con_task) |
133 | { | 130 | { |
134 | GNUNET_SCHEDULER_cancel (con_task); | 131 | GNUNET_SCHEDULER_cancel (con_task); |
@@ -317,7 +314,9 @@ setup_peer (struct PeerContext *p, | |||
317 | "-c", cfgname, NULL); | 314 | "-c", cfgname, NULL); |
318 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 315 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
319 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); | 316 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); |
320 | GNUNET_assert (p->th != NULL); | 317 | GNUNET_assert (NULL != p->th); |
318 | p->ats = GNUNET_ATS_connectivity_init (p->cfg); | ||
319 | GNUNET_assert (NULL != p->ats); | ||
321 | p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); | 320 | p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); |
322 | GNUNET_free (binary); | 321 | GNUNET_free (binary); |
323 | } | 322 | } |