diff options
Diffstat (limited to 'src/arm/test_arm_api.c')
-rw-r--r-- | src/arm/test_arm_api.c | 109 |
1 files changed, 70 insertions, 39 deletions
diff --git a/src/arm/test_arm_api.c b/src/arm/test_arm_api.c index f5283d714..0449c41d4 100644 --- a/src/arm/test_arm_api.c +++ b/src/arm/test_arm_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, 2011 GNUnet e.V. | 3 | Copyright (C) 2009, 2011, 2016 GNUnet e.V. |
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 |
@@ -28,60 +28,64 @@ | |||
28 | 28 | ||
29 | #define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 29 | #define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
30 | 30 | ||
31 | #define START_ARM GNUNET_YES | ||
32 | |||
33 | #define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 1500) | ||
34 | |||
35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
36 | 32 | ||
37 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 33 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
38 | 34 | ||
39 | static struct GNUNET_ARM_Handle *arm; | 35 | static struct GNUNET_ARM_Handle *arm; |
40 | 36 | ||
37 | static struct GNUNET_ARM_Operation *op; | ||
38 | |||
41 | static int ok = 1; | 39 | static int ok = 1; |
42 | 40 | ||
43 | static int phase = 0; | 41 | static int phase = 0; |
44 | 42 | ||
43 | |||
45 | static void | 44 | static void |
46 | arm_stop_cb (void *cls, | 45 | arm_stop_cb (void *cls, |
47 | enum GNUNET_ARM_RequestStatus status, | 46 | enum GNUNET_ARM_RequestStatus status, |
48 | const char *servicename, | ||
49 | enum GNUNET_ARM_Result result) | 47 | enum GNUNET_ARM_Result result) |
50 | { | 48 | { |
49 | op = NULL; | ||
51 | /* (6), a stop request should be sent to ARM successfully */ | 50 | /* (6), a stop request should be sent to ARM successfully */ |
52 | /* ARM should report that it is stopping */ | 51 | /* ARM should report that it is stopping */ |
53 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 52 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); |
54 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); | 53 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); |
55 | GNUNET_break (phase == 6); | 54 | GNUNET_break (phase == 6); |
56 | phase++; | 55 | phase++; |
57 | LOG ("Sent 'STOP' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 56 | LOG ("Sent 'STOP' request for arm to ARM %s\n", |
57 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | ||
58 | GNUNET_SCHEDULER_shutdown (); | ||
58 | } | 59 | } |
59 | 60 | ||
60 | 61 | ||
61 | static void | 62 | static void |
62 | resolver_stop_cb (void *cls, | 63 | resolver_stop_cb (void *cls, |
63 | enum GNUNET_ARM_RequestStatus status, | 64 | enum GNUNET_ARM_RequestStatus status, |
64 | const char *servicename, enum GNUNET_ARM_Result result) | 65 | enum GNUNET_ARM_Result result) |
65 | { | 66 | { |
67 | op = NULL; | ||
66 | /* (5), a stop request should be sent to ARM successfully. | 68 | /* (5), a stop request should be sent to ARM successfully. |
67 | * ARM should report that resolver is stopped. | 69 | * ARM should report that resolver is stopped. |
68 | */ | 70 | */ |
69 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 71 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); |
70 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); | 72 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); |
71 | GNUNET_break (phase == 5); | 73 | GNUNET_break (phase == 5); |
72 | LOG ("Sent 'STOP' request for resolver to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 74 | LOG ("Sent 'STOP' request for resolver to ARM %s\n", |
75 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | ||
73 | phase++; | 76 | phase++; |
74 | #if START_ARM | 77 | GNUNET_assert (NULL == op); |
75 | GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL); | 78 | op = GNUNET_ARM_request_service_stop (arm, |
76 | #else | 79 | "arm", |
77 | arm_stop_cb (NULL, GNUNET_ARM_STATUS_SENT_OK, "arm", GNUNET_ARM_SERVICE_STOPPING); | 80 | &arm_stop_cb, |
78 | arm_conn (NULL, GNUNET_NO); | 81 | NULL); |
79 | #endif | ||
80 | } | 82 | } |
81 | 83 | ||
82 | 84 | ||
83 | static void | 85 | static void |
84 | dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen) | 86 | dns_notify (void *cls, |
87 | const struct sockaddr *addr, | ||
88 | socklen_t addrlen) | ||
85 | { | 89 | { |
86 | if (addr == NULL) | 90 | if (addr == NULL) |
87 | { | 91 | { |
@@ -91,7 +95,11 @@ dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen) | |||
91 | LOG ("Finished resolving localhost\n"); | 95 | LOG ("Finished resolving localhost\n"); |
92 | if (ok != 0) | 96 | if (ok != 0) |
93 | ok = 2; | 97 | ok = 2; |
94 | GNUNET_ARM_request_service_stop (arm, "resolver", TIMEOUT, resolver_stop_cb, NULL); | 98 | GNUNET_assert (NULL == op); |
99 | op = GNUNET_ARM_request_service_stop (arm, | ||
100 | "resolver", | ||
101 | &resolver_stop_cb, | ||
102 | NULL); | ||
95 | return; | 103 | return; |
96 | } | 104 | } |
97 | /* (3), resolver should resolve localhost */ | 105 | /* (3), resolver should resolve localhost */ |
@@ -106,25 +114,22 @@ dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen) | |||
106 | static void | 114 | static void |
107 | resolver_start_cb (void *cls, | 115 | resolver_start_cb (void *cls, |
108 | enum GNUNET_ARM_RequestStatus status, | 116 | enum GNUNET_ARM_RequestStatus status, |
109 | const char *servicename, | ||
110 | enum GNUNET_ARM_Result result) | 117 | enum GNUNET_ARM_Result result) |
111 | { | 118 | { |
119 | op = NULL; | ||
112 | /* (2), the start request for resolver should be sent successfully | 120 | /* (2), the start request for resolver should be sent successfully |
113 | * ARM should report that resolver service is starting. | 121 | * ARM should report that resolver service is starting. |
114 | */ | 122 | */ |
115 | GNUNET_assert (status == GNUNET_ARM_REQUEST_SENT_OK); | 123 | GNUNET_assert (status == GNUNET_ARM_REQUEST_SENT_OK); |
116 | GNUNET_break (phase == 2); | 124 | GNUNET_break (phase == 2); |
117 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); | 125 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); |
118 | LOG ("Sent 'START' request for resolver to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 126 | LOG ("Sent 'START' request for resolver to ARM %s\n", |
127 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | ||
119 | phase++; | 128 | phase++; |
120 | GNUNET_RESOLVER_ip_get ("localhost", AF_INET, TIMEOUT, &dns_notify, NULL); | 129 | GNUNET_RESOLVER_ip_get ("localhost", |
121 | } | 130 | AF_INET, |
122 | 131 | TIMEOUT, | |
123 | 132 | &dns_notify, NULL); | |
124 | static void | ||
125 | trigger_disconnect (void *cls) | ||
126 | { | ||
127 | GNUNET_ARM_disconnect_and_free ((struct GNUNET_ARM_Handle *) cls); | ||
128 | } | 133 | } |
129 | 134 | ||
130 | 135 | ||
@@ -146,7 +151,12 @@ arm_conn (void *cls, | |||
146 | LOG ("Connected to ARM\n"); | 151 | LOG ("Connected to ARM\n"); |
147 | GNUNET_break (phase == 1); | 152 | GNUNET_break (phase == 1); |
148 | phase++; | 153 | phase++; |
149 | GNUNET_ARM_request_service_start (arm, "resolver", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, resolver_start_cb, NULL); | 154 | GNUNET_assert (NULL == op); |
155 | op = GNUNET_ARM_request_service_start (arm, | ||
156 | "resolver", | ||
157 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
158 | &resolver_start_cb, | ||
159 | NULL); | ||
150 | } | 160 | } |
151 | else | 161 | else |
152 | { | 162 | { |
@@ -157,7 +167,6 @@ arm_conn (void *cls, | |||
157 | ok = 3; | 167 | ok = 3; |
158 | else if (ok == 1) | 168 | else if (ok == 1) |
159 | ok = 0; | 169 | ok = 0; |
160 | GNUNET_SCHEDULER_add_now (&trigger_disconnect, arm); | ||
161 | } | 170 | } |
162 | } | 171 | } |
163 | 172 | ||
@@ -165,9 +174,9 @@ arm_conn (void *cls, | |||
165 | static void | 174 | static void |
166 | arm_start_cb (void *cls, | 175 | arm_start_cb (void *cls, |
167 | enum GNUNET_ARM_RequestStatus status, | 176 | enum GNUNET_ARM_RequestStatus status, |
168 | const char *servicename, | ||
169 | enum GNUNET_ARM_Result result) | 177 | enum GNUNET_ARM_Result result) |
170 | { | 178 | { |
179 | op = NULL; | ||
171 | /* (0) The request should be "sent" successfully | 180 | /* (0) The request should be "sent" successfully |
172 | * ("sent", because it isn't going anywhere, ARM API starts ARM service | 181 | * ("sent", because it isn't going anywhere, ARM API starts ARM service |
173 | * by itself). | 182 | * by itself). |
@@ -175,26 +184,48 @@ arm_start_cb (void *cls, | |||
175 | */ | 184 | */ |
176 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 185 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); |
177 | GNUNET_break (phase == 0); | 186 | GNUNET_break (phase == 0); |
178 | LOG ("Sent 'START' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 187 | LOG ("Sent 'START' request for arm to ARM %s\n", |
188 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | ||
179 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); | 189 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); |
180 | phase++; | 190 | phase++; |
181 | } | 191 | } |
182 | 192 | ||
183 | 193 | ||
184 | static void | 194 | static void |
185 | task (void *cls, char *const *args, const char *cfgfile, | 195 | do_shutdown (void *cls) |
196 | { | ||
197 | if (NULL != op) | ||
198 | { | ||
199 | GNUNET_ARM_operation_cancel (op); | ||
200 | op = NULL; | ||
201 | } | ||
202 | if (NULL != arm) | ||
203 | { | ||
204 | GNUNET_ARM_disconnect (arm); | ||
205 | arm = NULL; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | |||
210 | static void | ||
211 | task (void *cls, | ||
212 | char *const *args, | ||
213 | const char *cfgfile, | ||
186 | const struct GNUNET_CONFIGURATION_Handle *c) | 214 | const struct GNUNET_CONFIGURATION_Handle *c) |
187 | { | 215 | { |
188 | cfg = c; | 216 | cfg = c; |
189 | arm = GNUNET_ARM_connect (cfg, &arm_conn, NULL); | 217 | arm = GNUNET_ARM_connect (cfg, |
218 | &arm_conn, | ||
219 | NULL); | ||
190 | if (NULL == arm) | 220 | if (NULL == arm) |
191 | return; | 221 | return; |
192 | #if START_ARM | 222 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
193 | GNUNET_ARM_request_service_start (arm, "arm", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, arm_start_cb, NULL); | 223 | NULL); |
194 | #else | 224 | op = GNUNET_ARM_request_service_start (arm, |
195 | arm_start_cb (NULL, arm, GNUNET_ARM_REQUEST_SENT_OK, "arm", GNUNET_ARM_RESULT_STARTING); | 225 | "arm", |
196 | arm_conn (NULL, arm, GNUNET_YES); | 226 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
197 | #endif | 227 | &arm_start_cb, |
228 | NULL); | ||
198 | } | 229 | } |
199 | 230 | ||
200 | 231 | ||