diff options
Diffstat (limited to 'src/hostlist/test_gnunet_daemon_hostlist_reconnect.c')
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_reconnect.c | 96 |
1 files changed, 44 insertions, 52 deletions
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c index 7b6c858d4..d1227da4c 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c | |||
@@ -41,7 +41,7 @@ | |||
41 | static int ok; | 41 | static int ok; |
42 | 42 | ||
43 | static GNUNET_SCHEDULER_TaskIdentifier timeout_task; | 43 | static GNUNET_SCHEDULER_TaskIdentifier timeout_task; |
44 | 44 | ||
45 | struct PeerContext | 45 | struct PeerContext |
46 | { | 46 | { |
47 | struct GNUNET_CONFIGURATION_Handle *cfg; | 47 | struct GNUNET_CONFIGURATION_Handle *cfg; |
@@ -61,15 +61,15 @@ static void | |||
61 | clean_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 61 | clean_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
62 | { | 62 | { |
63 | if (p1.th != NULL) | 63 | if (p1.th != NULL) |
64 | { | 64 | { |
65 | GNUNET_TRANSPORT_disconnect (p1.th); | 65 | GNUNET_TRANSPORT_disconnect (p1.th); |
66 | p1.th = NULL; | 66 | p1.th = NULL; |
67 | } | 67 | } |
68 | if (p2.th != NULL) | 68 | if (p2.th != NULL) |
69 | { | 69 | { |
70 | GNUNET_TRANSPORT_disconnect (p2.th); | 70 | GNUNET_TRANSPORT_disconnect (p2.th); |
71 | p2.th = NULL; | 71 | p2.th = NULL; |
72 | } | 72 | } |
73 | GNUNET_SCHEDULER_shutdown (); | 73 | GNUNET_SCHEDULER_shutdown (); |
74 | } | 74 | } |
75 | 75 | ||
@@ -81,7 +81,7 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
81 | { | 81 | { |
82 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | 82 | timeout_task = GNUNET_SCHEDULER_NO_TASK; |
83 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 83 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
84 | "Timeout trying to connect peers, test failed.\n"); | 84 | "Timeout trying to connect peers, test failed.\n"); |
85 | clean_up (NULL, tc); | 85 | clean_up (NULL, tc); |
86 | } | 86 | } |
87 | 87 | ||
@@ -97,35 +97,34 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
97 | */ | 97 | */ |
98 | static void | 98 | static void |
99 | notify_connect (void *cls, | 99 | notify_connect (void *cls, |
100 | const struct GNUNET_PeerIdentity * peer, | 100 | const struct GNUNET_PeerIdentity *peer, |
101 | const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count) | 101 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
102 | uint32_t ats_count) | ||
102 | { | 103 | { |
103 | if (peer == NULL) | 104 | if (peer == NULL) |
104 | return; | 105 | return; |
105 | #if VERBOSE | 106 | #if VERBOSE |
106 | fprintf (stderr, "Peer %s connected\n", GNUNET_i2s (peer)); | 107 | fprintf (stderr, "Peer %s connected\n", GNUNET_i2s (peer)); |
107 | #endif | 108 | #endif |
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); |
109 | "Peers connected, shutting down.\n"); | ||
110 | ok = 0; | 110 | ok = 0; |
111 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | 111 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) |
112 | { | 112 | { |
113 | GNUNET_SCHEDULER_cancel (timeout_task); | 113 | GNUNET_SCHEDULER_cancel (timeout_task); |
114 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | 114 | timeout_task = GNUNET_SCHEDULER_NO_TASK; |
115 | } | 115 | } |
116 | GNUNET_SCHEDULER_add_now (&clean_up, NULL); | 116 | GNUNET_SCHEDULER_add_now (&clean_up, NULL); |
117 | } | 117 | } |
118 | 118 | ||
119 | 119 | ||
120 | static void | 120 | static void |
121 | process_hello (void *cls, | 121 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
122 | const struct GNUNET_MessageHeader *message) | ||
123 | { | 122 | { |
124 | struct PeerContext *p = cls; | 123 | struct PeerContext *p = cls; |
125 | 124 | ||
126 | GNUNET_TRANSPORT_get_hello_cancel (p->th, &process_hello, p); | 125 | GNUNET_TRANSPORT_get_hello_cancel (p->th, &process_hello, p); |
127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
128 | "Received HELLO, starting hostlist service.\n"); | 127 | "Received HELLO, starting hostlist service.\n"); |
129 | } | 128 | } |
130 | 129 | ||
131 | 130 | ||
@@ -135,35 +134,34 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
135 | p->cfg = GNUNET_CONFIGURATION_create (); | 134 | p->cfg = GNUNET_CONFIGURATION_create (); |
136 | #if START_ARM | 135 | #if START_ARM |
137 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 136 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
138 | "gnunet-service-arm", | 137 | "gnunet-service-arm", |
139 | #if VERBOSE | 138 | #if VERBOSE |
140 | "-L", "DEBUG", | 139 | "-L", "DEBUG", |
141 | #endif | 140 | #endif |
142 | "-c", cfgname, NULL); | 141 | "-c", cfgname, NULL); |
143 | #endif | 142 | #endif |
144 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 143 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
145 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, | 144 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, |
146 | ¬ify_connect, NULL); | 145 | ¬ify_connect, NULL); |
147 | GNUNET_assert (p->th != NULL); | 146 | GNUNET_assert (p->th != NULL); |
148 | GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); | 147 | GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); |
149 | } | 148 | } |
150 | 149 | ||
151 | 150 | ||
152 | static void | 151 | static void |
153 | waitpid_task (void *cls, | 152 | waitpid_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
154 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
155 | { | 153 | { |
156 | struct PeerContext *p = cls; | 154 | struct PeerContext *p = cls; |
157 | 155 | ||
158 | #if START_ARM | 156 | #if START_ARM |
159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); |
160 | "Killing ARM process.\n"); | ||
161 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 158 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) |
162 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 159 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
163 | if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) | 160 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
164 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 161 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
166 | "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); | 163 | "ARM process %u stopped\n", |
164 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
167 | GNUNET_OS_process_close (p->arm_proc); | 165 | GNUNET_OS_process_close (p->arm_proc); |
168 | p->arm_proc = NULL; | 166 | p->arm_proc = NULL; |
169 | #endif | 167 | #endif |
@@ -174,10 +172,8 @@ waitpid_task (void *cls, | |||
174 | static void | 172 | static void |
175 | stop_arm (struct PeerContext *p) | 173 | stop_arm (struct PeerContext *p) |
176 | { | 174 | { |
177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); |
178 | "Asking ARM to stop core service\n"); | 176 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); |
179 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
180 | &waitpid_task, p); | ||
181 | } | 177 | } |
182 | 178 | ||
183 | 179 | ||
@@ -195,17 +191,13 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
195 | static void | 191 | static void |
196 | run (void *cls, | 192 | run (void *cls, |
197 | char *const *args, | 193 | char *const *args, |
198 | const char *cfgfile, | 194 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
199 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
200 | { | 195 | { |
201 | GNUNET_assert (ok == 1); | 196 | GNUNET_assert (ok == 1); |
202 | ok++; | 197 | ok++; |
203 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 198 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); |
204 | &timeout_error, | ||
205 | NULL); | ||
206 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 199 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
207 | &shutdown_task, | 200 | &shutdown_task, NULL); |
208 | NULL); | ||
209 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); | 201 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); |
210 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); | 202 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); |
211 | } | 203 | } |
@@ -227,7 +219,7 @@ check () | |||
227 | ok = 1; | 219 | ok = 1; |
228 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 220 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
229 | argv, "test-gnunet-daemon-hostlist", | 221 | argv, "test-gnunet-daemon-hostlist", |
230 | "nohelp", options, &run, &ok); | 222 | "nohelp", options, &run, &ok); |
231 | return ok; | 223 | return ok; |
232 | } | 224 | } |
233 | 225 | ||
@@ -235,7 +227,7 @@ check () | |||
235 | int | 227 | int |
236 | main (int argc, char *argv[]) | 228 | main (int argc, char *argv[]) |
237 | { | 229 | { |
238 | 230 | ||
239 | int ret; | 231 | int ret; |
240 | 232 | ||
241 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); | 233 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); |
@@ -250,16 +242,16 @@ main (int argc, char *argv[]) | |||
250 | NULL); | 242 | NULL); |
251 | ret = check (); | 243 | ret = check (); |
252 | if (ret == 0) | 244 | if (ret == 0) |
253 | { | 245 | { |
254 | fprintf (stderr, "."); | 246 | fprintf (stderr, "."); |
255 | /* now do it again */ | 247 | /* now do it again */ |
256 | ret = check (); | 248 | ret = check (); |
257 | fprintf (stderr, ".\n"); | 249 | fprintf (stderr, ".\n"); |
258 | } | 250 | } |
259 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); | 251 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); |
260 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); | 252 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); |
261 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-3"); | 253 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-3"); |
262 | return ret; | 254 | return ret; |
263 | } | 255 | } |
264 | 256 | ||
265 | /* end of test_gnunet_daemon_hostlist_reconnect.c */ | 257 | /* end of test_gnunet_daemon_hostlist_reconnect.c */ |