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