aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hostlist/test_gnunet_daemon_hostlist_reconnect.c')
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_reconnect.c245
1 files changed, 123 insertions, 122 deletions
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
index 783da1d20..ce17cfe4d 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.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
37static int ok; 37static int ok;
38 38
39static struct GNUNET_SCHEDULER_Task *timeout_task; 39static struct GNUNET_SCHEDULER_Task *timeout_task;
40 40
41struct PeerContext { 41struct 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;
@@ -55,12 +56,12 @@ static struct PeerContext p2;
55 * Timeout, give up. 56 * Timeout, give up.
56 */ 57 */
57static void 58static void
58timeout_error(void *cls) 59timeout_error (void *cls)
59{ 60{
60 timeout_task = NULL; 61 timeout_task = NULL;
61 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 62 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
62 "Timeout trying to connect peers, test failed.\n"); 63 "Timeout trying to connect peers, test failed.\n");
63 GNUNET_SCHEDULER_shutdown(); 64 GNUNET_SCHEDULER_shutdown ();
64} 65}
65 66
66 67
@@ -74,87 +75,87 @@ timeout_error(void *cls)
74 * @return NULL 75 * @return NULL
75 */ 76 */
76static void * 77static void *
77notify_connect(void *cls, 78notify_connect (void *cls,
78 const struct GNUNET_PeerIdentity *peer, 79 const struct GNUNET_PeerIdentity *peer,
79 struct GNUNET_MQ_Handle *mq) 80 struct GNUNET_MQ_Handle *mq)
80{ 81{
81 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); 82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n");
82 ok = 0; 83 ok = 0;
83 GNUNET_SCHEDULER_shutdown(); 84 GNUNET_SCHEDULER_shutdown ();
84 return NULL; 85 return NULL;
85} 86}
86 87
87 88
88static void 89static void
89process_hello(void *cls, const struct GNUNET_MessageHeader *message) 90process_hello (void *cls, const struct GNUNET_MessageHeader *message)
90{ 91{
91 struct PeerContext *p = cls; 92 struct PeerContext *p = cls;
92 93
93 GNUNET_TRANSPORT_hello_get_cancel(p->ghh); 94 GNUNET_TRANSPORT_hello_get_cancel (p->ghh);
94 p->ghh = NULL; 95 p->ghh = NULL;
95 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 96 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
96 "Received HELLO, starting hostlist service.\n"); 97 "Received HELLO, starting hostlist service.\n");
97} 98}
98 99
99 100
100static void 101static void
101setup_peer(struct PeerContext *p, const char *cfgname) 102setup_peer (struct PeerContext *p, const char *cfgname)
102{ 103{
103 char *binary; 104 char *binary;
104 105
105 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); 106 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
106 p->cfg = GNUNET_CONFIGURATION_create(); 107 p->cfg = GNUNET_CONFIGURATION_create ();
107 p->arm_proc = GNUNET_OS_start_process(GNUNET_YES, 108 p->arm_proc = GNUNET_OS_start_process (GNUNET_YES,
108 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 109 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
109 NULL, 110 NULL,
110 NULL, 111 NULL,
111 NULL, 112 NULL,
112 binary, 113 binary,
113 "gnunet-service-arm", 114 "gnunet-service-arm",
114 "-c", 115 "-c",
115 cfgname, 116 cfgname,
116 NULL); 117 NULL);
117 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load(p->cfg, cfgname)); 118 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
118 p->th = GNUNET_TRANSPORT_core_connect(p->cfg, 119 p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
119 NULL, 120 NULL,
120 NULL, 121 NULL,
121 p, 122 p,
122 &notify_connect, 123 &notify_connect,
123 NULL, 124 NULL,
124 NULL); 125 NULL);
125 GNUNET_assert(NULL != p->th); 126 GNUNET_assert (NULL != p->th);
126 p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg, 127 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
127 GNUNET_TRANSPORT_AC_ANY, 128 GNUNET_TRANSPORT_AC_ANY,
128 &process_hello, 129 &process_hello,
129 p); 130 p);
130 GNUNET_free(binary); 131 GNUNET_free (binary);
131} 132}
132 133
133 134
134static void 135static void
135waitpid_task(void *cls) 136waitpid_task (void *cls)
136{ 137{
137 struct PeerContext *p = cls; 138 struct PeerContext *p = cls;
138 139
139 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); 140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n");
140 if (0 != GNUNET_OS_process_kill(p->arm_proc, GNUNET_TERM_SIG)) 141 if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG))
141 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); 142 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
142 if (GNUNET_OK != GNUNET_OS_process_wait(p->arm_proc)) 143 if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc))
143 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "waitpid"); 144 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
144 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
145 "ARM process %u stopped\n", 146 "ARM process %u stopped\n",
146 GNUNET_OS_process_get_pid(p->arm_proc)); 147 GNUNET_OS_process_get_pid (p->arm_proc));
147 GNUNET_OS_process_destroy(p->arm_proc); 148 GNUNET_OS_process_destroy (p->arm_proc);
148 p->arm_proc = NULL; 149 p->arm_proc = NULL;
149 GNUNET_CONFIGURATION_destroy(p->cfg); 150 GNUNET_CONFIGURATION_destroy (p->cfg);
150} 151}
151 152
152 153
153static void 154static void
154stop_arm(struct PeerContext *p) 155stop_arm (struct PeerContext *p)
155{ 156{
156 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); 157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n");
157 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); 158 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p);
158} 159}
159 160
160 161
@@ -162,55 +163,55 @@ stop_arm(struct PeerContext *p)
162 * Try again to connect to transport service. 163 * Try again to connect to transport service.
163 */ 164 */
164static void 165static void
165shutdown_task(void *cls) 166shutdown_task (void *cls)
166{ 167{
167 if (NULL != timeout_task) 168 if (NULL != timeout_task)
168 { 169 {
169 GNUNET_SCHEDULER_cancel(timeout_task); 170 GNUNET_SCHEDULER_cancel (timeout_task);
170 timeout_task = NULL; 171 timeout_task = NULL;
171 } 172 }
172 if (NULL != p1.ghh) 173 if (NULL != p1.ghh)
173 { 174 {
174 GNUNET_TRANSPORT_hello_get_cancel(p1.ghh); 175 GNUNET_TRANSPORT_hello_get_cancel (p1.ghh);
175 p1.ghh = NULL; 176 p1.ghh = NULL;
176 } 177 }
177 if (NULL != p1.th) 178 if (NULL != p1.th)
178 { 179 {
179 GNUNET_TRANSPORT_core_disconnect(p1.th); 180 GNUNET_TRANSPORT_core_disconnect (p1.th);
180 p1.th = NULL; 181 p1.th = NULL;
181 } 182 }
182 if (NULL != p2.ghh) 183 if (NULL != p2.ghh)
183 { 184 {
184 GNUNET_TRANSPORT_hello_get_cancel(p2.ghh); 185 GNUNET_TRANSPORT_hello_get_cancel (p2.ghh);
185 p2.ghh = NULL; 186 p2.ghh = NULL;
186 } 187 }
187 if (NULL != p2.th) 188 if (NULL != p2.th)
188 { 189 {
189 GNUNET_TRANSPORT_core_disconnect(p2.th); 190 GNUNET_TRANSPORT_core_disconnect (p2.th);
190 p2.th = NULL; 191 p2.th = NULL;
191 } 192 }
192 stop_arm(&p1); 193 stop_arm (&p1);
193 stop_arm(&p2); 194 stop_arm (&p2);
194} 195}
195 196
196 197
197static void 198static void
198run(void *cls, 199run (void *cls,
199 char *const *args, 200 char *const *args,
200 const char *cfgfile, 201 const char *cfgfile,
201 const struct GNUNET_CONFIGURATION_Handle *cfg) 202 const struct GNUNET_CONFIGURATION_Handle *cfg)
202{ 203{
203 GNUNET_assert(ok == 1); 204 GNUNET_assert (ok == 1);
204 ok++; 205 ok++;
205 timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &timeout_error, NULL); 206 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
206 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 207 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
207 setup_peer(&p1, "test_gnunet_daemon_hostlist_peer1.conf"); 208 setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
208 setup_peer(&p2, "test_gnunet_daemon_hostlist_peer2.conf"); 209 setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");
209} 210}
210 211
211 212
212int 213int
213main(int argcx, char *argvx[]) 214main (int argcx, char *argvx[])
214{ 215{
215 static char *const argv[] = { "test-gnunet-daemon-hostlist", 216 static char *const argv[] = { "test-gnunet-daemon-hostlist",
216 "-c", 217 "-c",
@@ -220,41 +221,41 @@ main(int argcx, char *argvx[])
220 GNUNET_GETOPT_OPTION_END 221 GNUNET_GETOPT_OPTION_END
221 }; 222 };
222 223
223 GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf", 224 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
224 "GNUNET_TEST_HOME"); 225 "GNUNET_TEST_HOME");
225 GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf", 226 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf",
226 "GNUNET_TEST_HOME"); 227 "GNUNET_TEST_HOME");
227 GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf", 228 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
228 "GNUNET_TEST_HOME"); 229 "GNUNET_TEST_HOME");
229 GNUNET_log_setup("test-gnunet-daemon-hostlist", "WARNING", NULL); 230 GNUNET_log_setup ("test-gnunet-daemon-hostlist", "WARNING", NULL);
230 ok = 1; 231 ok = 1;
231 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, 232 GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1,
232 argv, 233 argv,
233 "test-gnunet-daemon-hostlist", 234 "test-gnunet-daemon-hostlist",
234 "nohelp", 235 "nohelp",
235 options, 236 options,
236 &run, 237 &run,
237 &ok); 238 &ok);
238 if (0 == ok) 239 if (0 == ok)
239 { 240 {
240 fprintf(stderr, "%s", "."); 241 fprintf (stderr, "%s", ".");
241 /* now do it again */ 242 /* now do it again */
242 ok = 1; 243 ok = 1;
243 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, 244 GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1,
244 argv, 245 argv,
245 "test-gnunet-daemon-hostlist", 246 "test-gnunet-daemon-hostlist",
246 "nohelp", 247 "nohelp",
247 options, 248 options,
248 &run, 249 &run,
249 &ok); 250 &ok);
250 fprintf(stderr, "%s", ".\n"); 251 fprintf (stderr, "%s", ".\n");
251 } 252 }
252 GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer1.conf", 253 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
253 "GNUNET_TEST_HOME"); 254 "GNUNET_TEST_HOME");
254 GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_peer2.conf", 255 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf",
255 "GNUNET_TEST_HOME"); 256 "GNUNET_TEST_HOME");
256 GNUNET_DISK_purge_cfg_dir("test_gnunet_daemon_hostlist_data.conf", 257 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
257 "GNUNET_TEST_HOME"); 258 "GNUNET_TEST_HOME");
258 return ok; 259 return ok;
259} 260}
260 261