diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/hostlist/test_gnunet_daemon_hostlist.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/hostlist/test_gnunet_daemon_hostlist.c')
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist.c | 226 |
1 files changed, 114 insertions, 112 deletions
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index d6853c184..182340f9b 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c | |||
@@ -32,13 +32,14 @@ | |||
32 | /** | 32 | /** |
33 | * How long until we give up on transmitting the message? | 33 | * How long until we give up on transmitting the message? |
34 | */ | 34 | */ |
35 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 150) | 35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 150) |
36 | 36 | ||
37 | static int ok; | 37 | static int ok; |
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task *timeout_task; | 39 | static struct GNUNET_SCHEDULER_Task *timeout_task; |
40 | 40 | ||
41 | struct PeerContext { | 41 | struct PeerContext |
42 | { | ||
42 | struct GNUNET_CONFIGURATION_Handle *cfg; | 43 | struct GNUNET_CONFIGURATION_Handle *cfg; |
43 | struct GNUNET_TRANSPORT_CoreHandle *th; | 44 | struct GNUNET_TRANSPORT_CoreHandle *th; |
44 | struct GNUNET_MessageHeader *hello; | 45 | struct GNUNET_MessageHeader *hello; |
@@ -52,29 +53,29 @@ static struct PeerContext p2; | |||
52 | 53 | ||
53 | 54 | ||
54 | static void | 55 | static void |
55 | clean_up(void *cls) | 56 | clean_up (void *cls) |
56 | { | 57 | { |
57 | if (NULL != p1.th) | 58 | if (NULL != p1.th) |
59 | { | ||
60 | if (NULL != p1.ghh) | ||
58 | { | 61 | { |
59 | if (NULL != p1.ghh) | 62 | GNUNET_TRANSPORT_hello_get_cancel (p1.ghh); |
60 | { | 63 | p1.ghh = NULL; |
61 | GNUNET_TRANSPORT_hello_get_cancel(p1.ghh); | ||
62 | p1.ghh = NULL; | ||
63 | } | ||
64 | GNUNET_TRANSPORT_core_disconnect(p1.th); | ||
65 | p1.th = NULL; | ||
66 | } | 64 | } |
65 | GNUNET_TRANSPORT_core_disconnect (p1.th); | ||
66 | p1.th = NULL; | ||
67 | } | ||
67 | if (NULL != p2.th) | 68 | if (NULL != p2.th) |
69 | { | ||
70 | if (NULL != p2.ghh) | ||
68 | { | 71 | { |
69 | if (NULL != p2.ghh) | 72 | GNUNET_TRANSPORT_hello_get_cancel (p2.ghh); |
70 | { | 73 | p2.ghh = NULL; |
71 | GNUNET_TRANSPORT_hello_get_cancel(p2.ghh); | ||
72 | p2.ghh = NULL; | ||
73 | } | ||
74 | GNUNET_TRANSPORT_core_disconnect(p2.th); | ||
75 | p2.th = NULL; | ||
76 | } | 74 | } |
77 | GNUNET_SCHEDULER_shutdown(); | 75 | GNUNET_TRANSPORT_core_disconnect (p2.th); |
76 | p2.th = NULL; | ||
77 | } | ||
78 | GNUNET_SCHEDULER_shutdown (); | ||
78 | } | 79 | } |
79 | 80 | ||
80 | 81 | ||
@@ -82,12 +83,12 @@ clean_up(void *cls) | |||
82 | * Timeout, give up. | 83 | * Timeout, give up. |
83 | */ | 84 | */ |
84 | static void | 85 | static void |
85 | timeout_error(void *cls) | 86 | timeout_error (void *cls) |
86 | { | 87 | { |
87 | timeout_task = NULL; | 88 | timeout_task = NULL; |
88 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 89 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
89 | "Timeout trying to connect peers, test failed.\n"); | 90 | "Timeout trying to connect peers, test failed.\n"); |
90 | clean_up(NULL); | 91 | clean_up (NULL); |
91 | } | 92 | } |
92 | 93 | ||
93 | 94 | ||
@@ -100,92 +101,92 @@ timeout_error(void *cls) | |||
100 | * @param mq message queue to send messages to the peer | 101 | * @param mq message queue to send messages to the peer |
101 | */ | 102 | */ |
102 | static void * | 103 | static void * |
103 | notify_connect(void *cls, | 104 | notify_connect (void *cls, |
104 | const struct GNUNET_PeerIdentity *peer, | 105 | const struct GNUNET_PeerIdentity *peer, |
105 | struct GNUNET_MQ_Handle *mq) | 106 | struct GNUNET_MQ_Handle *mq) |
106 | { | 107 | { |
107 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); | 108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); |
108 | ok = 0; | 109 | ok = 0; |
109 | if (NULL != timeout_task) | 110 | if (NULL != timeout_task) |
110 | { | 111 | { |
111 | GNUNET_SCHEDULER_cancel(timeout_task); | 112 | GNUNET_SCHEDULER_cancel (timeout_task); |
112 | timeout_task = NULL; | 113 | timeout_task = NULL; |
113 | } | 114 | } |
114 | GNUNET_SCHEDULER_add_now(&clean_up, NULL); | 115 | GNUNET_SCHEDULER_add_now (&clean_up, NULL); |
115 | return NULL; | 116 | return NULL; |
116 | } | 117 | } |
117 | 118 | ||
118 | 119 | ||
119 | static void | 120 | static void |
120 | process_hello(void *cls, const struct GNUNET_MessageHeader *message) | 121 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
121 | { | 122 | { |
122 | struct PeerContext *p = cls; | 123 | struct PeerContext *p = cls; |
123 | 124 | ||
124 | GNUNET_TRANSPORT_hello_get_cancel(p->ghh); | 125 | GNUNET_TRANSPORT_hello_get_cancel (p->ghh); |
125 | p->ghh = NULL; | 126 | p->ghh = NULL; |
126 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
127 | "Received HELLO, starting hostlist service.\n"); | 128 | "Received HELLO, starting hostlist service.\n"); |
128 | } | 129 | } |
129 | 130 | ||
130 | 131 | ||
131 | static void | 132 | static void |
132 | setup_peer(struct PeerContext *p, const char *cfgname) | 133 | setup_peer (struct PeerContext *p, const char *cfgname) |
133 | { | 134 | { |
134 | char *binary; | 135 | char *binary; |
135 | 136 | ||
136 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); | 137 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); |
137 | p->cfg = GNUNET_CONFIGURATION_create(); | 138 | p->cfg = GNUNET_CONFIGURATION_create (); |
138 | p->arm_proc = GNUNET_OS_start_process(GNUNET_YES, | 139 | p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, |
139 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 140 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
140 | NULL, | 141 | NULL, |
141 | NULL, | 142 | NULL, |
142 | NULL, | 143 | NULL, |
143 | binary, | 144 | binary, |
144 | "gnunet-service-arm", | 145 | "gnunet-service-arm", |
145 | "-c", | 146 | "-c", |
146 | cfgname, | 147 | cfgname, |
147 | NULL); | 148 | NULL); |
148 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load(p->cfg, cfgname)); | 149 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
149 | p->th = GNUNET_TRANSPORT_core_connect(p->cfg, | 150 | p->th = GNUNET_TRANSPORT_core_connect (p->cfg, |
150 | NULL, | 151 | NULL, |
151 | NULL, | 152 | NULL, |
152 | p, | 153 | p, |
153 | ¬ify_connect, | 154 | ¬ify_connect, |
154 | NULL, | 155 | NULL, |
155 | NULL); | 156 | NULL); |
156 | GNUNET_assert(NULL != p->th); | 157 | GNUNET_assert (NULL != p->th); |
157 | p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg, | 158 | p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, |
158 | GNUNET_TRANSPORT_AC_ANY, | 159 | GNUNET_TRANSPORT_AC_ANY, |
159 | &process_hello, | 160 | &process_hello, |
160 | p); | 161 | p); |
161 | GNUNET_free(binary); | 162 | GNUNET_free (binary); |
162 | } | 163 | } |
163 | 164 | ||
164 | 165 | ||
165 | static void | 166 | static void |
166 | waitpid_task(void *cls) | 167 | waitpid_task (void *cls) |
167 | { | 168 | { |
168 | struct PeerContext *p = cls; | 169 | struct PeerContext *p = cls; |
169 | 170 | ||
170 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); | 171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); |
171 | if (0 != GNUNET_OS_process_kill(p->arm_proc, GNUNET_TERM_SIG)) | 172 | if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) |
172 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); | 173 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
173 | if (GNUNET_OK != GNUNET_OS_process_wait(p->arm_proc)) | 174 | if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc)) |
174 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 175 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
175 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
176 | "ARM process %u stopped\n", | 177 | "ARM process %u stopped\n", |
177 | GNUNET_OS_process_get_pid(p->arm_proc)); | 178 | GNUNET_OS_process_get_pid (p->arm_proc)); |
178 | GNUNET_OS_process_destroy(p->arm_proc); | 179 | GNUNET_OS_process_destroy (p->arm_proc); |
179 | p->arm_proc = NULL; | 180 | p->arm_proc = NULL; |
180 | GNUNET_CONFIGURATION_destroy(p->cfg); | 181 | GNUNET_CONFIGURATION_destroy (p->cfg); |
181 | } | 182 | } |
182 | 183 | ||
183 | 184 | ||
184 | static void | 185 | static void |
185 | stop_arm(struct PeerContext *p) | 186 | stop_arm (struct PeerContext *p) |
186 | { | 187 | { |
187 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); | 188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); |
188 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); | 189 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); |
189 | } | 190 | } |
190 | 191 | ||
191 | 192 | ||
@@ -193,68 +194,69 @@ stop_arm(struct PeerContext *p) | |||
193 | * Try again to connect to transport service. | 194 | * Try again to connect to transport service. |
194 | */ | 195 | */ |
195 | static void | 196 | static void |
196 | shutdown_task(void *cls) | 197 | shutdown_task (void *cls) |
197 | { | 198 | { |
198 | stop_arm(&p1); | 199 | stop_arm (&p1); |
199 | stop_arm(&p2); | 200 | stop_arm (&p2); |
200 | } | 201 | } |
201 | 202 | ||
202 | 203 | ||
203 | static void | 204 | static void |
204 | run(void *cls, | 205 | run (void *cls, |
205 | char *const *args, | 206 | char *const *args, |
206 | const char *cfgfile, | 207 | const char *cfgfile, |
207 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 208 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
208 | { | 209 | { |
209 | GNUNET_assert(ok == 1); | 210 | GNUNET_assert (ok == 1); |
210 | ok++; | 211 | ok++; |
211 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &timeout_error, NULL); | 212 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); |
212 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 213 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
213 | setup_peer(&p1, "test_gnunet_daemon_hostlist_peer1.conf"); | 214 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); |
214 | setup_peer(&p2, "test_gnunet_daemon_hostlist_peer2.conf"); | 215 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); |
215 | } | 216 | } |
216 | 217 | ||
217 | 218 | ||
218 | static int | 219 | static int |
219 | check() | 220 | check () |
220 | { | 221 | { |
221 | char *const argv[] = { "test-gnunet-daemon-hostlist", | 222 | char *const argv[] = { "test-gnunet-daemon-hostlist", |
222 | "-c", | 223 | "-c", |
223 | "test_gnunet_daemon_hostlist_data.conf", | 224 | "test_gnunet_daemon_hostlist_data.conf", |
224 | NULL }; | 225 | NULL }; |
225 | struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; | 226 | struct GNUNET_GETOPT_CommandLineOption options[] = |
227 | { GNUNET_GETOPT_OPTION_END }; | ||
226 | 228 | ||
227 | ok = 1; | 229 | ok = 1; |
228 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, | 230 | GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, |
229 | argv, | 231 | argv, |
230 | "test-gnunet-daemon-hostlist", | 232 | "test-gnunet-daemon-hostlist", |
231 | "nohelp", | 233 | "nohelp", |
232 | options, | 234 | options, |
233 | &run, | 235 | &run, |
234 | &ok); | 236 | &ok); |
235 | return ok; | 237 | return ok; |
236 | } | 238 | } |
237 | 239 | ||
238 | 240 | ||
239 | int | 241 | int |
240 | main(int argc, char *argv[]) | 242 | main (int argc, char *argv[]) |
241 | { | 243 | { |
242 | int ret; | 244 | int ret; |
243 | 245 | ||
244 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf", | 246 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", |
245 | "GNUNET_TEST_HOME"); | 247 | "GNUNET_TEST_HOME"); |
246 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf", | 248 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf", |
247 | "GNUNET_TEST_HOME"); | 249 | "GNUNET_TEST_HOME"); |
248 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf", | 250 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", |
249 | "GNUNET_TEST_HOME"); | 251 | "GNUNET_TEST_HOME"); |
250 | GNUNET_log_setup("test-gnunet-daemon-hostlist", "WARNING", NULL); | 252 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", "WARNING", NULL); |
251 | ret = check(); | 253 | ret = check (); |
252 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf", | 254 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", |
253 | "GNUNET_TEST_HOME"); | 255 | "GNUNET_TEST_HOME"); |
254 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf", | 256 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf", |
255 | "GNUNET_TEST_HOME"); | 257 | "GNUNET_TEST_HOME"); |
256 | GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf", | 258 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", |
257 | "GNUNET_TEST_HOME"); | 259 | "GNUNET_TEST_HOME"); |
258 | return ret; | 260 | return ret; |
259 | } | 261 | } |
260 | 262 | ||