aboutsummaryrefslogtreecommitdiff
path: root/src/arm
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/arm
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/arm')
-rw-r--r--src/arm/arm.h15
-rw-r--r--src/arm/arm_monitor_api.c145
-rw-r--r--src/arm/mockup-service.c70
-rw-r--r--src/arm/test_arm_api.c254
-rw-r--r--src/arm/test_exponential_backoff.c389
-rw-r--r--src/arm/test_gnunet_service_arm.c257
6 files changed, 572 insertions, 558 deletions
diff --git a/src/arm/arm.h b/src/arm/arm.h
index bddcd7cf3..15f24b3f6 100644
--- a/src/arm/arm.h
+++ b/src/arm/arm.h
@@ -38,7 +38,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
38/** 38/**
39 * Status update from ARM to client. 39 * Status update from ARM to client.
40 */ 40 */
41struct GNUNET_ARM_StatusMessage { 41struct GNUNET_ARM_StatusMessage
42{
42 /** 43 /**
43 * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_STATUS. 44 * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_STATUS.
44 */ 45 */
@@ -52,7 +53,8 @@ struct GNUNET_ARM_StatusMessage {
52 /* followed by a 0-terminated service name */ 53 /* followed by a 0-terminated service name */
53}; 54};
54 55
55struct GNUNET_ARM_Message { 56struct GNUNET_ARM_Message
57{
56 /** 58 /**
57 * Reply to client, type is #GNUNET_MESSAGE_TYPE_ARM_RESULT or 59 * Reply to client, type is #GNUNET_MESSAGE_TYPE_ARM_RESULT or
58 * #GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT. 60 * #GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT.
@@ -81,7 +83,8 @@ struct GNUNET_ARM_Message {
81/** 83/**
82 * Reply from ARM to client. 84 * Reply from ARM to client.
83 */ 85 */
84struct GNUNET_ARM_ResultMessage { 86struct GNUNET_ARM_ResultMessage
87{
85 /** 88 /**
86 * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_RESULT, with an ID. 89 * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_RESULT, with an ID.
87 */ 90 */
@@ -93,7 +96,8 @@ struct GNUNET_ARM_ResultMessage {
93 uint32_t result; 96 uint32_t result;
94}; 97};
95 98
96struct GNUNET_ARM_ServiceInfoMessage { 99struct GNUNET_ARM_ServiceInfoMessage
100{
97 /** 101 /**
98 * String pool index for the service's name. 102 * String pool index for the service's name.
99 */ 103 */
@@ -137,7 +141,8 @@ struct GNUNET_ARM_ServiceInfoMessage {
137 * '\0' terminated strings. header->size contains the 141 * '\0' terminated strings. header->size contains the
138 * total size (including all strings). 142 * total size (including all strings).
139 */ 143 */
140struct GNUNET_ARM_ListResultMessage { 144struct GNUNET_ARM_ListResultMessage
145{
141 /** 146 /**
142 * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, 147 * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT,
143 * with an ID. 148 * with an ID.
diff --git a/src/arm/arm_monitor_api.c b/src/arm/arm_monitor_api.c
index 00faaaef1..2c418d0ce 100644
--- a/src/arm/arm_monitor_api.c
+++ b/src/arm/arm_monitor_api.c
@@ -30,14 +30,15 @@
30#include "gnunet_protocols.h" 30#include "gnunet_protocols.h"
31#include "arm.h" 31#include "arm.h"
32 32
33#define INIT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) 33#define INIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
34 34
35#define LOG(kind, ...) GNUNET_log_from(kind, "arm-monitor-api", __VA_ARGS__) 35#define LOG(kind, ...) GNUNET_log_from (kind, "arm-monitor-api", __VA_ARGS__)
36 36
37/** 37/**
38 * Handle for interacting with ARM. 38 * Handle for interacting with ARM.
39 */ 39 */
40struct GNUNET_ARM_MonitorHandle { 40struct GNUNET_ARM_MonitorHandle
41{
41 /** 42 /**
42 * Our control connection to the ARM service. 43 * Our control connection to the ARM service.
43 */ 44 */
@@ -77,7 +78,7 @@ struct GNUNET_ARM_MonitorHandle {
77 * @return #GNUNET_OK on success 78 * @return #GNUNET_OK on success
78 */ 79 */
79static int 80static int
80reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h); 81reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h);
81 82
82 83
83/** 84/**
@@ -86,14 +87,14 @@ reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h);
86 * @param cls the `struct GNUNET_ARM_MonitorHandle` 87 * @param cls the `struct GNUNET_ARM_MonitorHandle`
87 */ 88 */
88static void 89static void
89reconnect_arm_monitor_task(void *cls) 90reconnect_arm_monitor_task (void *cls)
90{ 91{
91 struct GNUNET_ARM_MonitorHandle *h = cls; 92 struct GNUNET_ARM_MonitorHandle *h = cls;
92 93
93 h->reconnect_task = NULL; 94 h->reconnect_task = NULL;
94 LOG(GNUNET_ERROR_TYPE_DEBUG, 95 LOG (GNUNET_ERROR_TYPE_DEBUG,
95 "Connecting to ARM service for monitoring after delay\n"); 96 "Connecting to ARM service for monitoring after delay\n");
96 GNUNET_break(GNUNET_OK == reconnect_arm_monitor(h)); 97 GNUNET_break (GNUNET_OK == reconnect_arm_monitor (h));
97} 98}
98 99
99 100
@@ -104,18 +105,18 @@ reconnect_arm_monitor_task(void *cls)
104 * @param h our handle 105 * @param h our handle
105 */ 106 */
106static void 107static void
107reconnect_arm_monitor_later(struct GNUNET_ARM_MonitorHandle *h) 108reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h)
108{ 109{
109 if (NULL != h->mq) 110 if (NULL != h->mq)
110 { 111 {
111 GNUNET_MQ_destroy(h->mq); 112 GNUNET_MQ_destroy (h->mq);
112 h->mq = NULL; 113 h->mq = NULL;
113 } 114 }
114 GNUNET_assert(NULL == h->reconnect_task); 115 GNUNET_assert (NULL == h->reconnect_task);
115 h->reconnect_task = GNUNET_SCHEDULER_add_delayed(h->retry_backoff, 116 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff,
116 &reconnect_arm_monitor_task, 117 &reconnect_arm_monitor_task,
117 h); 118 h);
118 h->retry_backoff = GNUNET_TIME_STD_BACKOFF(h->retry_backoff); 119 h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff);
119} 120}
120 121
121 122
@@ -127,18 +128,18 @@ reconnect_arm_monitor_later(struct GNUNET_ARM_MonitorHandle *h)
127 * @return #GNUNET_OK if the message is well-formed 128 * @return #GNUNET_OK if the message is well-formed
128 */ 129 */
129static int 130static int
130check_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *msg) 131check_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *msg)
131{ 132{
132 size_t sl = 133 size_t sl =
133 ntohs(msg->header.size) - sizeof(struct GNUNET_ARM_StatusMessage); 134 ntohs (msg->header.size) - sizeof(struct GNUNET_ARM_StatusMessage);
134 const char *name = (const char *)&msg[1]; 135 const char *name = (const char *) &msg[1];
135 136
136 (void)cls; 137 (void) cls;
137 if ((0 == sl) || ('\0' != name[sl - 1])) 138 if ((0 == sl) || ('\0' != name[sl - 1]))
138 { 139 {
139 GNUNET_break(0); 140 GNUNET_break (0);
140 return GNUNET_SYSERR; 141 return GNUNET_SYSERR;
141 } 142 }
142 return GNUNET_OK; 143 return GNUNET_OK;
143} 144}
144 145
@@ -150,18 +151,18 @@ check_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *msg)
150 * @param res the message received from the arm service 151 * @param res the message received from the arm service
151 */ 152 */
152static void 153static void
153handle_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *res) 154handle_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *res)
154{ 155{
155 struct GNUNET_ARM_MonitorHandle *h = cls; 156 struct GNUNET_ARM_MonitorHandle *h = cls;
156 enum GNUNET_ARM_ServiceMonitorStatus status; 157 enum GNUNET_ARM_ServiceMonitorStatus status;
157 158
158 status = (enum GNUNET_ARM_ServiceMonitorStatus)ntohl(res->status); 159 status = (enum GNUNET_ARM_ServiceMonitorStatus) ntohl (res->status);
159 LOG(GNUNET_ERROR_TYPE_DEBUG, 160 LOG (GNUNET_ERROR_TYPE_DEBUG,
160 "Received notification from ARM for service `%s' with status %d\n", 161 "Received notification from ARM for service `%s' with status %d\n",
161 (const char *)&res[1], 162 (const char *) &res[1],
162 (int)status); 163 (int) status);
163 if (NULL != h->service_status) 164 if (NULL != h->service_status)
164 h->service_status(h->service_status_cls, (const char *)&res[1], status); 165 h->service_status (h->service_status_cls, (const char *) &res[1], status);
165} 166}
166 167
167 168
@@ -174,12 +175,12 @@ handle_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *res)
174 * @param error error code 175 * @param error error code
175 */ 176 */
176static void 177static void
177mq_error_handler(void *cls, enum GNUNET_MQ_Error error) 178mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
178{ 179{
179 struct GNUNET_ARM_MonitorHandle *h = cls; 180 struct GNUNET_ARM_MonitorHandle *h = cls;
180 181
181 (void)error; 182 (void) error;
182 reconnect_arm_monitor_later(h); 183 reconnect_arm_monitor_later (h);
183} 184}
184 185
185 186
@@ -190,29 +191,29 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
190 * @return #GNUNET_OK on success 191 * @return #GNUNET_OK on success
191 */ 192 */
192static int 193static int
193reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h) 194reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h)
194{ 195{
195 struct GNUNET_MQ_MessageHandler handlers[] = 196 struct GNUNET_MQ_MessageHandler handlers[] =
196 { GNUNET_MQ_hd_var_size(monitor_notify, 197 { GNUNET_MQ_hd_var_size (monitor_notify,
197 GNUNET_MESSAGE_TYPE_ARM_STATUS, 198 GNUNET_MESSAGE_TYPE_ARM_STATUS,
198 struct GNUNET_ARM_StatusMessage, 199 struct GNUNET_ARM_StatusMessage,
199 h), 200 h),
200 GNUNET_MQ_handler_end() }; 201 GNUNET_MQ_handler_end () };
201 struct GNUNET_MessageHeader *msg; 202 struct GNUNET_MessageHeader *msg;
202 struct GNUNET_MQ_Envelope *env; 203 struct GNUNET_MQ_Envelope *env;
203 204
204 GNUNET_assert(NULL == h->mq); 205 GNUNET_assert (NULL == h->mq);
205 h->mq = GNUNET_CLIENT_connect(h->cfg, "arm", handlers, &mq_error_handler, h); 206 h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h);
206 if (NULL == h->mq) 207 if (NULL == h->mq)
207 { 208 {
208 if (NULL != h->service_status) 209 if (NULL != h->service_status)
209 h->service_status(h->service_status_cls, 210 h->service_status (h->service_status_cls,
210 NULL, 211 NULL,
211 GNUNET_ARM_SERVICE_STOPPED); 212 GNUNET_ARM_SERVICE_STOPPED);
212 return GNUNET_SYSERR; 213 return GNUNET_SYSERR;
213 } 214 }
214 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR); 215 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR);
215 GNUNET_MQ_send(h->mq, env); 216 GNUNET_MQ_send (h->mq, env);
216 return GNUNET_OK; 217 return GNUNET_OK;
217} 218}
218 219
@@ -229,21 +230,21 @@ reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h)
229 * @return context to use for further ARM monitor operations, NULL on error. 230 * @return context to use for further ARM monitor operations, NULL on error.
230 */ 231 */
231struct GNUNET_ARM_MonitorHandle * 232struct GNUNET_ARM_MonitorHandle *
232GNUNET_ARM_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg, 233GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
233 GNUNET_ARM_ServiceMonitorCallback cont, 234 GNUNET_ARM_ServiceMonitorCallback cont,
234 void *cont_cls) 235 void *cont_cls)
235{ 236{
236 struct GNUNET_ARM_MonitorHandle *h; 237 struct GNUNET_ARM_MonitorHandle *h;
237 238
238 h = GNUNET_new(struct GNUNET_ARM_MonitorHandle); 239 h = GNUNET_new (struct GNUNET_ARM_MonitorHandle);
239 h->cfg = cfg; 240 h->cfg = cfg;
240 h->service_status = cont; 241 h->service_status = cont;
241 h->service_status_cls = cont_cls; 242 h->service_status_cls = cont_cls;
242 if (GNUNET_OK != reconnect_arm_monitor(h)) 243 if (GNUNET_OK != reconnect_arm_monitor (h))
243 { 244 {
244 GNUNET_free(h); 245 GNUNET_free (h);
245 return NULL; 246 return NULL;
246 } 247 }
247 return h; 248 return h;
248} 249}
249 250
@@ -254,19 +255,19 @@ GNUNET_ARM_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg,
254 * @param h the handle that was being used 255 * @param h the handle that was being used
255 */ 256 */
256void 257void
257GNUNET_ARM_monitor_stop(struct GNUNET_ARM_MonitorHandle *h) 258GNUNET_ARM_monitor_stop (struct GNUNET_ARM_MonitorHandle *h)
258{ 259{
259 if (NULL != h->mq) 260 if (NULL != h->mq)
260 { 261 {
261 GNUNET_MQ_destroy(h->mq); 262 GNUNET_MQ_destroy (h->mq);
262 h->mq = NULL; 263 h->mq = NULL;
263 } 264 }
264 if (NULL != h->reconnect_task) 265 if (NULL != h->reconnect_task)
265 { 266 {
266 GNUNET_SCHEDULER_cancel(h->reconnect_task); 267 GNUNET_SCHEDULER_cancel (h->reconnect_task);
267 h->reconnect_task = NULL; 268 h->reconnect_task = NULL;
268 } 269 }
269 GNUNET_free(h); 270 GNUNET_free (h);
270} 271}
271 272
272 273
diff --git a/src/arm/mockup-service.c b/src/arm/mockup-service.c
index 6134f17b3..9870afea1 100644
--- a/src/arm/mockup-service.c
+++ b/src/arm/mockup-service.c
@@ -33,15 +33,15 @@ static int special_ret = 0;
33 * @param message the actual message 33 * @param message the actual message
34 */ 34 */
35static void 35static void
36handle_stop(void *cls, const struct GNUNET_MessageHeader *message) 36handle_stop (void *cls, const struct GNUNET_MessageHeader *message)
37{ 37{
38 struct GNUNET_SERVICE_Client *client = cls; 38 struct GNUNET_SERVICE_Client *client = cls;
39 39
40 (void)message; 40 (void) message;
41 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 41 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
42 _("Initiating shutdown as requested by client.\n")); 42 _ ("Initiating shutdown as requested by client.\n"));
43 GNUNET_SERVICE_client_persist(client); 43 GNUNET_SERVICE_client_persist (client);
44 GNUNET_SCHEDULER_shutdown(); 44 GNUNET_SCHEDULER_shutdown ();
45 /* ARM won't exponentially increase restart delay if we 45 /* ARM won't exponentially increase restart delay if we
46 * terminate normally. This changes the return code. 46 * terminate normally. This changes the return code.
47 */ 47 */
@@ -58,12 +58,12 @@ handle_stop(void *cls, const struct GNUNET_MessageHeader *message)
58 * @return @a c 58 * @return @a c
59 */ 59 */
60static void * 60static void *
61client_connect_cb(void *cls, 61client_connect_cb (void *cls,
62 struct GNUNET_SERVICE_Client *c, 62 struct GNUNET_SERVICE_Client *c,
63 struct GNUNET_MQ_Handle *mq) 63 struct GNUNET_MQ_Handle *mq)
64{ 64{
65 (void)cls; 65 (void) cls;
66 (void)mq; 66 (void) mq;
67 return c; 67 return c;
68} 68}
69 69
@@ -76,23 +76,23 @@ client_connect_cb(void *cls,
76 * @param internal_cls should be equal to @a c 76 * @param internal_cls should be equal to @a c
77 */ 77 */
78static void 78static void
79client_disconnect_cb(void *cls, 79client_disconnect_cb (void *cls,
80 struct GNUNET_SERVICE_Client *c, 80 struct GNUNET_SERVICE_Client *c,
81 void *internal_cls) 81 void *internal_cls)
82{ 82{
83 (void)cls; 83 (void) cls;
84 GNUNET_assert(c == internal_cls); 84 GNUNET_assert (c == internal_cls);
85} 85}
86 86
87 87
88static void 88static void
89run(void *cls, 89run (void *cls,
90 const struct GNUNET_CONFIGURATION_Handle *cfg, 90 const struct GNUNET_CONFIGURATION_Handle *cfg,
91 struct GNUNET_SERVICE_Handle *service) 91 struct GNUNET_SERVICE_Handle *service)
92{ 92{
93 (void)cls; 93 (void) cls;
94 (void)cfg; 94 (void) cfg;
95 (void)service; 95 (void) service;
96 /* nothing to do */ 96 /* nothing to do */
97} 97}
98 98
@@ -100,23 +100,23 @@ run(void *cls,
100/** 100/**
101 * Define "main" method using service macro. 101 * Define "main" method using service macro.
102 */ 102 */
103GNUNET_SERVICE_MAIN("do-nothing", 103GNUNET_SERVICE_MAIN ("do-nothing",
104 GNUNET_SERVICE_OPTION_NONE, 104 GNUNET_SERVICE_OPTION_NONE,
105 &run, 105 &run,
106 &client_connect_cb, 106 &client_connect_cb,
107 &client_disconnect_cb, 107 &client_disconnect_cb,
108 NULL, 108 NULL,
109 GNUNET_MQ_hd_fixed_size(stop, 109 GNUNET_MQ_hd_fixed_size (stop,
110 GNUNET_MESSAGE_TYPE_ARM_STOP, 110 GNUNET_MESSAGE_TYPE_ARM_STOP,
111 struct GNUNET_MessageHeader, 111 struct GNUNET_MessageHeader,
112 NULL), 112 NULL),
113 GNUNET_MQ_handler_end()); 113 GNUNET_MQ_handler_end ());
114 114
115 115
116/** 116/**
117 * MINIMIZE heap size (way below 128k) since this process doesn't need much. 117 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
118 */ 118 */
119void __attribute__ ((destructor)) GNUNET_mockup_done() 119void __attribute__ ((destructor)) GNUNET_mockup_done ()
120{ 120{
121 _exit(special_ret); 121 _exit (special_ret);
122} 122}
diff --git a/src/arm/test_arm_api.c b/src/arm/test_arm_api.c
index 84d6f1bfd..5a06c823c 100644
--- a/src/arm/test_arm_api.c
+++ b/src/arm/test_arm_api.c
@@ -26,9 +26,9 @@
26#include "gnunet_arm_service.h" 26#include "gnunet_arm_service.h"
27#include "gnunet_resolver_service.h" 27#include "gnunet_resolver_service.h"
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 TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) 31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
32 32
33static const struct GNUNET_CONFIGURATION_Handle *cfg; 33static const struct GNUNET_CONFIGURATION_Handle *cfg;
34 34
@@ -42,139 +42,142 @@ static int phase = 0;
42 42
43 43
44static void 44static void
45arm_stop_cb(void *cls, 45arm_stop_cb (void *cls,
46 enum GNUNET_ARM_RequestStatus status, 46 enum GNUNET_ARM_RequestStatus status,
47 enum GNUNET_ARM_Result result) 47 enum GNUNET_ARM_Result result)
48{ 48{
49 op = NULL; 49 op = NULL;
50 /* (6), a stop request should be sent to ARM successfully */ 50 /* (6), a stop request should be sent to ARM successfully */
51 /* ARM should report that it is stopping */ 51 /* ARM should report that it is stopping */
52 GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); 52 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
53 GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); 53 GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
54 GNUNET_break(phase == 6); 54 GNUNET_break (phase == 6);
55 phase++; 55 phase++;
56 LOG("Sent 'STOP' request for arm to ARM %s\n", 56 LOG ("Sent 'STOP' request for arm to ARM %s\n",
57 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); 57 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" :
58 GNUNET_SCHEDULER_shutdown(); 58 "unsuccessfully");
59 GNUNET_SCHEDULER_shutdown ();
59} 60}
60 61
61 62
62static void 63static void
63resolver_stop_cb(void *cls, 64resolver_stop_cb (void *cls,
64 enum GNUNET_ARM_RequestStatus status, 65 enum GNUNET_ARM_RequestStatus status,
65 enum GNUNET_ARM_Result result) 66 enum GNUNET_ARM_Result result)
66{ 67{
67 op = NULL; 68 op = NULL;
68 /* (5), a stop request should be sent to ARM successfully. 69 /* (5), a stop request should be sent to ARM successfully.
69 * ARM should report that resolver is stopped. 70 * ARM should report that resolver is stopped.
70 */ 71 */
71 GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); 72 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
72 GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); 73 GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
73 GNUNET_break(phase == 5); 74 GNUNET_break (phase == 5);
74 LOG("Sent 'STOP' request for resolver to ARM %s\n", 75 LOG ("Sent 'STOP' request for resolver to ARM %s\n",
75 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); 76 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" :
77 "unsuccessfully");
76 phase++; 78 phase++;
77 GNUNET_assert(NULL == op); 79 GNUNET_assert (NULL == op);
78 op = GNUNET_ARM_request_service_stop(arm, 80 op = GNUNET_ARM_request_service_stop (arm,
79 "arm", 81 "arm",
80 &arm_stop_cb, 82 &arm_stop_cb,
81 NULL); 83 NULL);
82} 84}
83 85
84 86
85static void 87static void
86dns_notify(void *cls, 88dns_notify (void *cls,
87 const struct sockaddr *addr, 89 const struct sockaddr *addr,
88 socklen_t addrlen) 90 socklen_t addrlen)
89{ 91{
90 if (addr == NULL) 92 if (addr == NULL)
91 { 93 {
92 /* (4), resolver should finish resolving localhost */ 94 /* (4), resolver should finish resolving localhost */
93 GNUNET_break(phase == 4); 95 GNUNET_break (phase == 4);
94 phase++; 96 phase++;
95 LOG("Finished resolving localhost\n"); 97 LOG ("Finished resolving localhost\n");
96 if (ok != 0) 98 if (ok != 0)
97 ok = 2; 99 ok = 2;
98 GNUNET_assert(NULL == op); 100 GNUNET_assert (NULL == op);
99 op = GNUNET_ARM_request_service_stop(arm, 101 op = GNUNET_ARM_request_service_stop (arm,
100 "resolver", 102 "resolver",
101 &resolver_stop_cb, 103 &resolver_stop_cb,
102 NULL); 104 NULL);
103 return; 105 return;
104 } 106 }
105 /* (3), resolver should resolve localhost */ 107 /* (3), resolver should resolve localhost */
106 GNUNET_break(phase == 3); 108 GNUNET_break (phase == 3);
107 LOG("Resolved localhost\n"); 109 LOG ("Resolved localhost\n");
108 phase++; 110 phase++;
109 GNUNET_break(addr != NULL); 111 GNUNET_break (addr != NULL);
110 ok = 0; 112 ok = 0;
111} 113}
112 114
113 115
114static void 116static void
115resolver_start_cb(void *cls, 117resolver_start_cb (void *cls,
116 enum GNUNET_ARM_RequestStatus status, 118 enum GNUNET_ARM_RequestStatus status,
117 enum GNUNET_ARM_Result result) 119 enum GNUNET_ARM_Result result)
118{ 120{
119 op = NULL; 121 op = NULL;
120 /* (2), the start request for resolver should be sent successfully 122 /* (2), the start request for resolver should be sent successfully
121 * ARM should report that resolver service is starting. 123 * ARM should report that resolver service is starting.
122 */ 124 */
123 GNUNET_assert(status == GNUNET_ARM_REQUEST_SENT_OK); 125 GNUNET_assert (status == GNUNET_ARM_REQUEST_SENT_OK);
124 GNUNET_break(phase == 2); 126 GNUNET_break (phase == 2);
125 GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); 127 GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
126 LOG("Sent 'START' request for resolver to ARM %s\n", 128 LOG ("Sent 'START' request for resolver to ARM %s\n",
127 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); 129 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" :
130 "unsuccessfully");
128 phase++; 131 phase++;
129 GNUNET_RESOLVER_ip_get("localhost", 132 GNUNET_RESOLVER_ip_get ("localhost",
130 AF_INET, 133 AF_INET,
131 TIMEOUT, 134 TIMEOUT,
132 &dns_notify, NULL); 135 &dns_notify, NULL);
133} 136}
134 137
135 138
136static void 139static void
137arm_conn(void *cls, 140arm_conn (void *cls,
138 int connected) 141 int connected)
139{ 142{
140 if (GNUNET_SYSERR == connected) 143 if (GNUNET_SYSERR == connected)
141 { 144 {
142 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
143 _("Fatal error initializing ARM API.\n")); 146 _ ("Fatal error initializing ARM API.\n"));
144 GNUNET_SCHEDULER_shutdown(); 147 GNUNET_SCHEDULER_shutdown ();
145 GNUNET_assert(0); 148 GNUNET_assert (0);
146 return; 149 return;
147 } 150 }
148 if (GNUNET_YES == connected) 151 if (GNUNET_YES == connected)
149 { 152 {
150 /* (1), arm connection should be established */ 153 /* (1), arm connection should be established */
151 LOG("Connected to ARM\n"); 154 LOG ("Connected to ARM\n");
152 GNUNET_break(phase == 1); 155 GNUNET_break (phase == 1);
153 phase++; 156 phase++;
154 GNUNET_assert(NULL == op); 157 GNUNET_assert (NULL == op);
155 op = GNUNET_ARM_request_service_start(arm, 158 op = GNUNET_ARM_request_service_start (arm,
156 "resolver", 159 "resolver",
157 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 160 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
158 &resolver_start_cb, 161 &resolver_start_cb,
159 NULL); 162 NULL);
160 } 163 }
161 else 164 else
162 { 165 {
163 /* (7), ARM should stop (we disconnect from it) */ 166 /* (7), ARM should stop (we disconnect from it) */
164 LOG("Disconnected from ARM\n"); 167 LOG ("Disconnected from ARM\n");
165 GNUNET_break(phase == 7); 168 GNUNET_break (phase == 7);
166 if (phase != 7) 169 if (phase != 7)
167 ok = 3; 170 ok = 3;
168 else if (ok == 1) 171 else if (ok == 1)
169 ok = 0; 172 ok = 0;
170 } 173 }
171} 174}
172 175
173 176
174static void 177static void
175arm_start_cb(void *cls, 178arm_start_cb (void *cls,
176 enum GNUNET_ARM_RequestStatus status, 179 enum GNUNET_ARM_RequestStatus status,
177 enum GNUNET_ARM_Result result) 180 enum GNUNET_ARM_Result result)
178{ 181{
179 op = NULL; 182 op = NULL;
180 /* (0) The request should be "sent" successfully 183 /* (0) The request should be "sent" successfully
@@ -182,55 +185,56 @@ arm_start_cb(void *cls,
182 * by itself). 185 * by itself).
183 * ARM API should report that ARM service is starting. 186 * ARM API should report that ARM service is starting.
184 */ 187 */
185 GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); 188 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
186 GNUNET_break(phase == 0); 189 GNUNET_break (phase == 0);
187 LOG("Sent 'START' request for arm to ARM %s\n", 190 LOG ("Sent 'START' request for arm to ARM %s\n",
188 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); 191 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" :
189 GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); 192 "unsuccessfully");
193 GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
190 phase++; 194 phase++;
191} 195}
192 196
193 197
194static void 198static void
195do_shutdown(void *cls) 199do_shutdown (void *cls)
196{ 200{
197 if (NULL != op) 201 if (NULL != op)
198 { 202 {
199 GNUNET_ARM_operation_cancel(op); 203 GNUNET_ARM_operation_cancel (op);
200 op = NULL; 204 op = NULL;
201 } 205 }
202 if (NULL != arm) 206 if (NULL != arm)
203 { 207 {
204 GNUNET_ARM_disconnect(arm); 208 GNUNET_ARM_disconnect (arm);
205 arm = NULL; 209 arm = NULL;
206 } 210 }
207} 211}
208 212
209 213
210static void 214static void
211task(void *cls, 215task (void *cls,
212 char *const *args, 216 char *const *args,
213 const char *cfgfile, 217 const char *cfgfile,
214 const struct GNUNET_CONFIGURATION_Handle *c) 218 const struct GNUNET_CONFIGURATION_Handle *c)
215{ 219{
216 cfg = c; 220 cfg = c;
217 arm = GNUNET_ARM_connect(cfg, 221 arm = GNUNET_ARM_connect (cfg,
218 &arm_conn, 222 &arm_conn,
219 NULL); 223 NULL);
220 if (NULL == arm) 224 if (NULL == arm)
221 return; 225 return;
222 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 226 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
223 NULL); 227 NULL);
224 op = GNUNET_ARM_request_service_start(arm, 228 op = GNUNET_ARM_request_service_start (arm,
225 "arm", 229 "arm",
226 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 230 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
227 &arm_start_cb, 231 &arm_start_cb,
228 NULL); 232 NULL);
229} 233}
230 234
231 235
232int 236int
233main(int argc, char *argvx[]) 237main (int argc, char *argvx[])
234{ 238{
235 char *const argv[] = { 239 char *const argv[] = {
236 "test-arm-api", 240 "test-arm-api",
@@ -241,13 +245,13 @@ main(int argc, char *argvx[])
241 GNUNET_GETOPT_OPTION_END 245 GNUNET_GETOPT_OPTION_END
242 }; 246 };
243 247
244 GNUNET_log_setup("test-arm-api", 248 GNUNET_log_setup ("test-arm-api",
245 "WARNING", 249 "WARNING",
246 NULL); 250 NULL);
247 GNUNET_assert(GNUNET_OK == 251 GNUNET_assert (GNUNET_OK ==
248 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, 252 GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1,
249 argv, "test-arm-api", "nohelp", options, 253 argv, "test-arm-api", "nohelp", options,
250 &task, NULL)); 254 &task, NULL));
251 return ok; 255 return ok;
252} 256}
253 257
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c
index b13ab1cb8..5d1863f37 100644
--- a/src/arm/test_exponential_backoff.c
+++ b/src/arm/test_exponential_backoff.c
@@ -27,15 +27,16 @@
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_protocols.h" 28#include "gnunet_protocols.h"
29 29
30#define LOG(...) GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) 30#define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
31 31
32#define LOG_BACKOFF GNUNET_NO 32#define LOG_BACKOFF GNUNET_NO
33 33
34#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) 34#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
35 35
36#define SERVICE_TEST_TIMEOUT GNUNET_TIME_UNIT_FOREVER_REL 36#define SERVICE_TEST_TIMEOUT GNUNET_TIME_UNIT_FOREVER_REL
37 37
38#define FIVE_MILLISECONDS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 5) 38#define FIVE_MILLISECONDS GNUNET_TIME_relative_multiply ( \
39 GNUNET_TIME_UNIT_MILLISECONDS, 5)
39 40
40#define SERVICE "do-nothing" 41#define SERVICE "do-nothing"
41 42
@@ -74,7 +75,8 @@ static char *killLogFileName;
74/** 75/**
75 * Context for handling the shutdown of a service. 76 * Context for handling the shutdown of a service.
76 */ 77 */
77struct ShutdownContext { 78struct ShutdownContext
79{
78 /** 80 /**
79 * Connection to the service that is being shutdown. 81 * Connection to the service that is being shutdown.
80 */ 82 */
@@ -88,7 +90,7 @@ struct ShutdownContext {
88 90
89 91
90static void 92static void
91kill_task(void *cbData); 93kill_task (void *cbData);
92 94
93 95
94/** 96/**
@@ -97,9 +99,9 @@ kill_task(void *cbData);
97 * @param cls closure 99 * @param cls closure
98 */ 100 */
99static void 101static void
100service_shutdown_timeout(void *cls) 102service_shutdown_timeout (void *cls)
101{ 103{
102 GNUNET_assert(0); 104 GNUNET_assert (0);
103} 105}
104 106
105 107
@@ -112,196 +114,197 @@ service_shutdown_timeout(void *cls)
112 * @param error error code 114 * @param error error code
113 */ 115 */
114static void 116static void
115mq_error_handler(void *cls, 117mq_error_handler (void *cls,
116 enum GNUNET_MQ_Error error) 118 enum GNUNET_MQ_Error error)
117{ 119{
118 struct ShutdownContext *shutdown_ctx = cls; 120 struct ShutdownContext *shutdown_ctx = cls;
119 121
120 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
121 "Service shutdown complete (MQ error).\n"); 123 "Service shutdown complete (MQ error).\n");
122 GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task); 124 GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
123 GNUNET_MQ_destroy(shutdown_ctx->mq); 125 GNUNET_MQ_destroy (shutdown_ctx->mq);
124 GNUNET_free(shutdown_ctx); 126 GNUNET_free (shutdown_ctx);
125} 127}
126 128
127 129
128static void 130static void
129kill_task(void *cbData) 131kill_task (void *cbData)
130{ 132{
131 struct ShutdownContext *shutdown_ctx 133 struct ShutdownContext *shutdown_ctx
132 = GNUNET_new(struct ShutdownContext); 134 = GNUNET_new (struct ShutdownContext);
133 struct GNUNET_MQ_Envelope *env; 135 struct GNUNET_MQ_Envelope *env;
134 struct GNUNET_MessageHeader *msg; 136 struct GNUNET_MessageHeader *msg;
135 struct GNUNET_MQ_MessageHandler handlers[] = { 137 struct GNUNET_MQ_MessageHandler handlers[] = {
136 GNUNET_MQ_handler_end() 138 GNUNET_MQ_handler_end ()
137 }; 139 };
138 140
139 kt = NULL; 141 kt = NULL;
140 if (trialCount == 13) 142 if (trialCount == 13)
141 { 143 {
142 LOG("Saw enough kills, asking ARM to stop mock service for good\n"); 144 LOG ("Saw enough kills, asking ARM to stop mock service for good\n");
143 GNUNET_ARM_request_service_stop(arm, 145 GNUNET_ARM_request_service_stop (arm,
144 SERVICE, 146 SERVICE,
145 NULL, 147 NULL,
146 NULL); 148 NULL);
147 ok = 0; 149 ok = 0;
148 trialCount++; 150 trialCount++;
149 GNUNET_free(shutdown_ctx); 151 GNUNET_free (shutdown_ctx);
150 return; 152 return;
151 } 153 }
152 shutdown_ctx->mq = GNUNET_CLIENT_connect(cfg, 154 shutdown_ctx->mq = GNUNET_CLIENT_connect (cfg,
153 SERVICE, 155 SERVICE,
154 handlers, 156 handlers,
155 &mq_error_handler, 157 &mq_error_handler,
156 shutdown_ctx); 158 shutdown_ctx);
157 GNUNET_assert(NULL != shutdown_ctx->mq); 159 GNUNET_assert (NULL != shutdown_ctx->mq);
158 trialCount++; 160 trialCount++;
159 LOG("Sending a shutdown request to the mock service\n"); 161 LOG ("Sending a shutdown request to the mock service\n");
160 env = GNUNET_MQ_msg(msg, 162 env = GNUNET_MQ_msg (msg,
161 GNUNET_MESSAGE_TYPE_ARM_STOP); /* FIXME: abuse of message type */ 163 GNUNET_MESSAGE_TYPE_ARM_STOP); /* FIXME: abuse of message type */
162 GNUNET_MQ_send(shutdown_ctx->mq, 164 GNUNET_MQ_send (shutdown_ctx->mq,
163 env); 165 env);
164 shutdown_ctx->cancel_task 166 shutdown_ctx->cancel_task
165 = GNUNET_SCHEDULER_add_delayed(TIMEOUT, 167 = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
166 &service_shutdown_timeout, 168 &service_shutdown_timeout,
167 shutdown_ctx); 169 shutdown_ctx);
168} 170}
169 171
170 172
171static void 173static void
172trigger_disconnect(void *cls) 174trigger_disconnect (void *cls)
173{ 175{
174 GNUNET_ARM_disconnect(arm); 176 GNUNET_ARM_disconnect (arm);
175 GNUNET_ARM_monitor_stop(mon); 177 GNUNET_ARM_monitor_stop (mon);
176 if (NULL != kt) 178 if (NULL != kt)
177 { 179 {
178 GNUNET_SCHEDULER_cancel(kt); 180 GNUNET_SCHEDULER_cancel (kt);
179 kt = NULL; 181 kt = NULL;
180 } 182 }
181} 183}
182 184
183 185
184static void 186static void
185arm_stop_cb(void *cls, 187arm_stop_cb (void *cls,
186 enum GNUNET_ARM_RequestStatus status, 188 enum GNUNET_ARM_RequestStatus status,
187 enum GNUNET_ARM_Result result) 189 enum GNUNET_ARM_Result result)
188{ 190{
189 GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); 191 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
190 GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); 192 GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
191 LOG("ARM service stopped\n"); 193 LOG ("ARM service stopped\n");
192 GNUNET_SCHEDULER_shutdown(); 194 GNUNET_SCHEDULER_shutdown ();
193} 195}
194 196
195 197
196static void 198static void
197srv_status(void *cls, 199srv_status (void *cls,
198 const char *service, 200 const char *service,
199 enum GNUNET_ARM_ServiceMonitorStatus status) 201 enum GNUNET_ARM_ServiceMonitorStatus status)
200{ 202{
201 if (status == GNUNET_ARM_SERVICE_MONITORING_STARTED) 203 if (status == GNUNET_ARM_SERVICE_MONITORING_STARTED)
202 { 204 {
203 LOG("ARM monitor started, starting mock service\n"); 205 LOG ("ARM monitor started, starting mock service\n");
204 phase++; 206 phase++;
205 GNUNET_ARM_request_service_start(arm, 207 GNUNET_ARM_request_service_start (arm,
206 SERVICE, 208 SERVICE,
207 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 209 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
208 NULL, 210 NULL,
209 NULL); 211 NULL);
210 return; 212 return;
211 } 213 }
212 if (0 != strcasecmp(service, SERVICE)) 214 if (0 != strcasecmp (service, SERVICE))
213 return; /* not what we care about */ 215 return; /* not what we care about */
214 if (phase == 1) 216 if (phase == 1)
217 {
218 GNUNET_break (status == GNUNET_ARM_SERVICE_STARTING);
219 GNUNET_break (phase == 1);
220 LOG ("do-nothing is starting\n");
221 phase++;
222 ok = 1;
223 GNUNET_assert (NULL == kt);
224 startedWaitingAt = GNUNET_TIME_absolute_get ();
225 kt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
226 &kill_task,
227 NULL);
228 }
229 else if (phase == 2)
230 {
231 /* We passively monitor ARM for status updates. ARM should tell us
232 * when do-nothing dies (no need to run a service upness test ourselves).
233 */
234 if (status == GNUNET_ARM_SERVICE_STARTING)
215 { 235 {
216 GNUNET_break(status == GNUNET_ARM_SERVICE_STARTING); 236 waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt);
217 GNUNET_break(phase == 1); 237 LOG ("Waited for: %s\n",
218 LOG("do-nothing is starting\n"); 238 GNUNET_STRINGS_relative_time_to_string (waitedFor,
219 phase++; 239 GNUNET_YES));
220 ok = 1; 240
221 GNUNET_assert(NULL == kt); 241 LOG ("do-nothing is starting, killing it...\n");
222 startedWaitingAt = GNUNET_TIME_absolute_get(); 242 GNUNET_assert (NULL == kt);
223 kt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 243 kt = GNUNET_SCHEDULER_add_now (&kill_task, &ok);
224 &kill_task,
225 NULL);
226 } 244 }
227 else if (phase == 2) 245 else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14))
228 { 246 {
229 /* We passively monitor ARM for status updates. ARM should tell us 247 phase++;
230 * when do-nothing dies (no need to run a service upness test ourselves). 248 LOG ("do-nothing stopped working %u times, we are done here\n",
231 */ 249 (unsigned int) trialCount);
232 if (status == GNUNET_ARM_SERVICE_STARTING) 250 GNUNET_ARM_request_service_stop (arm,
233 { 251 "arm",
234 waitedFor = GNUNET_TIME_absolute_get_duration(startedWaitingAt); 252 &arm_stop_cb,
235 LOG("Waited for: %s\n", 253 NULL);
236 GNUNET_STRINGS_relative_time_to_string(waitedFor,
237 GNUNET_YES));
238
239 LOG("do-nothing is starting, killing it...\n");
240 GNUNET_assert(NULL == kt);
241 kt = GNUNET_SCHEDULER_add_now(&kill_task, &ok);
242 }
243 else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14))
244 {
245 phase++;
246 LOG("do-nothing stopped working %u times, we are done here\n",
247 (unsigned int)trialCount);
248 GNUNET_ARM_request_service_stop(arm,
249 "arm",
250 &arm_stop_cb,
251 NULL);
252 }
253 } 254 }
255 }
254} 256}
255 257
256 258
257static void 259static void
258arm_start_cb(void *cls, 260arm_start_cb (void *cls,
259 enum GNUNET_ARM_RequestStatus status, 261 enum GNUNET_ARM_RequestStatus status,
260 enum GNUNET_ARM_Result result) 262 enum GNUNET_ARM_Result result)
261{ 263{
262 GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); 264 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
263 GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); 265 GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
264 GNUNET_break(phase == 0); 266 GNUNET_break (phase == 0);
265 LOG("Sent 'START' request for arm to ARM %s\n", 267 LOG ("Sent 'START' request for arm to ARM %s\n",
266 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); 268 (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" :
269 "unsuccessfully");
267} 270}
268 271
269 272
270static void 273static void
271task(void *cls, 274task (void *cls,
272 char *const *args, 275 char *const *args,
273 const char *cfgfile, 276 const char *cfgfile,
274 const struct GNUNET_CONFIGURATION_Handle *c) 277 const struct GNUNET_CONFIGURATION_Handle *c)
275{ 278{
276 cfg = c; 279 cfg = c;
277 arm = GNUNET_ARM_connect(cfg, NULL, NULL); 280 arm = GNUNET_ARM_connect (cfg, NULL, NULL);
278 if (NULL == arm) 281 if (NULL == arm)
279 { 282 {
280 GNUNET_break(0); 283 GNUNET_break (0);
281 return; 284 return;
282 } 285 }
283 mon = GNUNET_ARM_monitor_start(cfg, 286 mon = GNUNET_ARM_monitor_start (cfg,
284 &srv_status, 287 &srv_status,
285 NULL); 288 NULL);
286 if (NULL == mon) 289 if (NULL == mon)
287 { 290 {
288 GNUNET_break(0); 291 GNUNET_break (0);
289 GNUNET_ARM_disconnect(arm); 292 GNUNET_ARM_disconnect (arm);
290 arm = NULL; 293 arm = NULL;
291 return; 294 return;
292 } 295 }
293 GNUNET_ARM_request_service_start(arm, 296 GNUNET_ARM_request_service_start (arm,
294 "arm", 297 "arm",
295 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 298 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
296 &arm_start_cb, 299 &arm_start_cb,
297 NULL); 300 NULL);
298 GNUNET_SCHEDULER_add_shutdown(&trigger_disconnect, 301 GNUNET_SCHEDULER_add_shutdown (&trigger_disconnect,
299 NULL); 302 NULL);
300} 303}
301 304
302 305
303static int 306static int
304check() 307check ()
305{ 308{
306 char *const argv[] = { 309 char *const argv[] = {
307 "test-exponential-backoff", 310 "test-exponential-backoff",
@@ -313,14 +316,14 @@ check()
313 }; 316 };
314 317
315 /* Running ARM and running the do_nothing task */ 318 /* Running ARM and running the do_nothing task */
316 GNUNET_assert(GNUNET_OK == 319 GNUNET_assert (GNUNET_OK ==
317 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, 320 GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1,
318 argv, 321 argv,
319 "test-exponential-backoff", 322 "test-exponential-backoff",
320 "nohelp", 323 "nohelp",
321 options, 324 options,
322 &task, 325 &task,
323 NULL)); 326 NULL));
324 return ok; 327 return ok;
325} 328}
326 329
@@ -334,78 +337,78 @@ check()
334 337
335 338
336static int 339static int
337init() 340init ()
338{ 341{
339 struct GNUNET_CONFIGURATION_Handle *cfg; 342 struct GNUNET_CONFIGURATION_Handle *cfg;
340 char pwd[PATH_MAX]; 343 char pwd[PATH_MAX];
341 char *binary; 344 char *binary;
342 345
343 cfg = GNUNET_CONFIGURATION_create(); 346 cfg = GNUNET_CONFIGURATION_create ();
344 if (GNUNET_OK != GNUNET_CONFIGURATION_parse(cfg, 347 if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg,
345 "test_arm_api_data.conf")) 348 "test_arm_api_data.conf"))
346 { 349 {
347 GNUNET_CONFIGURATION_destroy(cfg); 350 GNUNET_CONFIGURATION_destroy (cfg);
348 return GNUNET_SYSERR;
349 }
350 if (NULL == getcwd(pwd, PATH_MAX))
351 return GNUNET_SYSERR; 351 return GNUNET_SYSERR;
352 GNUNET_assert(0 < GNUNET_asprintf(&binary, 352 }
353 "%s/%s", 353 if (NULL == getcwd (pwd, PATH_MAX))
354 pwd, 354 return GNUNET_SYSERR;
355 BINARY)); 355 GNUNET_assert (0 < GNUNET_asprintf (&binary,
356 GNUNET_CONFIGURATION_set_value_string(cfg, 356 "%s/%s",
357 SERVICE, 357 pwd,
358 "BINARY", 358 BINARY));
359 binary); 359 GNUNET_CONFIGURATION_set_value_string (cfg,
360 GNUNET_free(binary); 360 SERVICE,
361 if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg, 361 "BINARY",
362 CFGFILENAME)) 362 binary);
363 { 363 GNUNET_free (binary);
364 GNUNET_CONFIGURATION_destroy(cfg); 364 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg,
365 return GNUNET_SYSERR; 365 CFGFILENAME))
366 } 366 {
367 GNUNET_CONFIGURATION_destroy(cfg); 367 GNUNET_CONFIGURATION_destroy (cfg);
368 return GNUNET_SYSERR;
369 }
370 GNUNET_CONFIGURATION_destroy (cfg);
368 371
369#if LOG_BACKOFF 372#if LOG_BACKOFF
370 killLogFileName = GNUNET_DISK_mktemp("exponential-backoff-waiting.log"); 373 killLogFileName = GNUNET_DISK_mktemp ("exponential-backoff-waiting.log");
371 if (NULL == (killLogFilePtr = fopen(killLogFileName, 374 if (NULL == (killLogFilePtr = fopen (killLogFileName,
372 "w"))) 375 "w")))
373 { 376 {
374 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, 377 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
375 "fopen", 378 "fopen",
376 killLogFileName); 379 killLogFileName);
377 GNUNET_free(killLogFileName); 380 GNUNET_free (killLogFileName);
378 return GNUNET_SYSERR; 381 return GNUNET_SYSERR;
379 } 382 }
380#endif 383#endif
381 return GNUNET_OK; 384 return GNUNET_OK;
382} 385}
383 386
384 387
385static void 388static void
386houseKeep() 389houseKeep ()
387{ 390{
388#if LOG_BACKOFF 391#if LOG_BACKOFF
389 GNUNET_assert(0 == fclose(killLogFilePtr)); 392 GNUNET_assert (0 == fclose (killLogFilePtr));
390 GNUNET_free(killLogFileName); 393 GNUNET_free (killLogFileName);
391#endif 394#endif
392 (void)unlink(CFGFILENAME); 395 (void) unlink (CFGFILENAME);
393} 396}
394 397
395 398
396int 399int
397main(int argc, char *argv[]) 400main (int argc, char *argv[])
398{ 401{
399 int ret; 402 int ret;
400 403
401 GNUNET_log_setup("test-exponential-backoff", 404 GNUNET_log_setup ("test-exponential-backoff",
402 "WARNING", 405 "WARNING",
403 NULL); 406 NULL);
404 407
405 if (GNUNET_OK != init()) 408 if (GNUNET_OK != init ())
406 return 1; 409 return 1;
407 ret = check(); 410 ret = check ();
408 houseKeep(); 411 houseKeep ();
409 return ret; 412 return ret;
410} 413}
411 414
diff --git a/src/arm/test_gnunet_service_arm.c b/src/arm/test_gnunet_service_arm.c
index cb2c14438..45053a41d 100644
--- a/src/arm/test_gnunet_service_arm.c
+++ b/src/arm/test_gnunet_service_arm.c
@@ -34,9 +34,10 @@
34 * (by checking if running before starting, so really this time is always waited on 34 * (by checking if running before starting, so really this time is always waited on
35 * startup (annoying)). 35 * startup (annoying)).
36 */ 36 */
37#define START_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 50) 37#define START_TIMEOUT GNUNET_TIME_relative_multiply ( \
38 GNUNET_TIME_UNIT_MILLISECONDS, 50)
38 39
39#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) 40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
40 41
41 42
42static int ret = 1; 43static int ret = 1;
@@ -51,141 +52,141 @@ static const char hostname[] = "www.gnu.org"; /* any domain should do */
51 52
52 53
53static void 54static void
54trigger_disconnect(void *cls) 55trigger_disconnect (void *cls)
55{ 56{
56 GNUNET_ARM_disconnect(arm); 57 GNUNET_ARM_disconnect (arm);
57 arm = NULL; 58 arm = NULL;
58} 59}
59 60
60 61
61static void 62static void
62arm_stop_cb(void *cls, 63arm_stop_cb (void *cls,
63 enum GNUNET_ARM_RequestStatus status, 64 enum GNUNET_ARM_RequestStatus status,
64 enum GNUNET_ARM_Result result) 65 enum GNUNET_ARM_Result result)
65{ 66{
66 GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); 67 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
67 GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); 68 GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
68 if (result != GNUNET_ARM_RESULT_STOPPED) 69 if (result != GNUNET_ARM_RESULT_STOPPED)
69 { 70 {
70 GNUNET_break(0); 71 GNUNET_break (0);
71 ret = 4; 72 ret = 4;
72 } 73 }
73 GNUNET_SCHEDULER_add_now(&trigger_disconnect, NULL); 74 GNUNET_SCHEDULER_add_now (&trigger_disconnect, NULL);
74} 75}
75 76
76 77
77static void 78static void
78service_list(void *cls, 79service_list (void *cls,
79 enum GNUNET_ARM_RequestStatus rs, 80 enum GNUNET_ARM_RequestStatus rs,
80 unsigned int count, 81 unsigned int count,
81 const struct GNUNET_ARM_ServiceInfo *list) 82 const struct GNUNET_ARM_ServiceInfo *list)
82{ 83{
83 unsigned int i; 84 unsigned int i;
84 85
85 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 86 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
86 "%u services are are currently running\n", 87 "%u services are are currently running\n",
87 count); 88 count);
88 if (GNUNET_ARM_REQUEST_SENT_OK != rs) 89 if (GNUNET_ARM_REQUEST_SENT_OK != rs)
89 goto stop_arm; 90 goto stop_arm;
90 for (i = 0; i < count; i++) 91 for (i = 0; i < count; i++)
92 {
93 if ((0 == strcasecmp (list[i].name, "resolver")) &&
94 (0 == strcasecmp (list[i].binary, "gnunet-service-resolver")))
91 { 95 {
92 if ((0 == strcasecmp(list[i].name, "resolver")) && 96 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
93 (0 == strcasecmp(list[i].binary, "gnunet-service-resolver"))) 97 "Got service list, now stopping arm\n");
94 { 98 ret = 0;
95 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
96 "Got service list, now stopping arm\n");
97 ret = 0;
98 }
99 } 99 }
100 }
100 101
101stop_arm: 102stop_arm:
102 GNUNET_ARM_request_service_stop(arm, 103 GNUNET_ARM_request_service_stop (arm,
103 "arm", 104 "arm",
104 &arm_stop_cb, 105 &arm_stop_cb,
105 NULL); 106 NULL);
106} 107}
107 108
108 109
109static void 110static void
110hostname_resolve_cb(void *cls, 111hostname_resolve_cb (void *cls,
111 const struct sockaddr *addr, 112 const struct sockaddr *addr,
112 socklen_t addrlen) 113 socklen_t addrlen)
113{ 114{
114 if ((0 == ret) || (4 == ret) || (1 == resolved_ok)) 115 if ((0 == ret) || (4 == ret) || (1 == resolved_ok))
115 return; 116 return;
116 if (NULL == addr) 117 if (NULL == addr)
117 { 118 {
118 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
119 "Failed to resolve hostname!\n"); 120 "Failed to resolve hostname!\n");
120 GNUNET_break(0); 121 GNUNET_break (0);
121 ret = 3; 122 ret = 3;
122 GNUNET_ARM_request_service_stop(arm, 123 GNUNET_ARM_request_service_stop (arm,
123 "arm", 124 "arm",
124 &arm_stop_cb, 125 &arm_stop_cb,
125 NULL); 126 NULL);
126 return; 127 return;
127 } 128 }
128 if (0 == asked_for_a_list) 129 if (0 == asked_for_a_list)
129 { 130 {
130 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
131 "Resolved hostname, now checking the service list\n"); 132 "Resolved hostname, now checking the service list\n");
132 GNUNET_ARM_request_service_list(arm, 133 GNUNET_ARM_request_service_list (arm,
133 &service_list, 134 &service_list,
134 NULL); 135 NULL);
135 asked_for_a_list = 1; 136 asked_for_a_list = 1;
136 resolved_ok = 1; 137 resolved_ok = 1;
137 } 138 }
138} 139}
139 140
140 141
141static void 142static void
142arm_start_cb(void *cls, 143arm_start_cb (void *cls,
143 enum GNUNET_ARM_RequestStatus status, 144 enum GNUNET_ARM_RequestStatus status,
144 enum GNUNET_ARM_Result result) 145 enum GNUNET_ARM_Result result)
145{ 146{
146 GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); 147 GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
147 GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); 148 GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
148 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
149 "Trying to resolve a hostname via the resolver service!\n"); 150 "Trying to resolve a hostname via the resolver service!\n");
150 /* connect to the resolver service */ 151 /* connect to the resolver service */
151 if (NULL == 152 if (NULL ==
152 GNUNET_RESOLVER_ip_get(hostname, 153 GNUNET_RESOLVER_ip_get (hostname,
153 AF_UNSPEC, 154 AF_UNSPEC,
154 TIMEOUT, 155 TIMEOUT,
155 &hostname_resolve_cb, 156 &hostname_resolve_cb,
156 NULL)) 157 NULL))
157 { 158 {
158 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
159 "Unable initiate connection to resolver service\n"); 160 "Unable initiate connection to resolver service\n");
160 GNUNET_break(0); 161 GNUNET_break (0);
161 ret = 2; 162 ret = 2;
162 GNUNET_ARM_request_service_stop(arm, 163 GNUNET_ARM_request_service_stop (arm,
163 "arm", 164 "arm",
164 &arm_stop_cb, 165 &arm_stop_cb,
165 NULL); 166 NULL);
166 } 167 }
167} 168}
168 169
169 170
170static void 171static void
171run(void *cls, 172run (void *cls,
172 char *const *args, 173 char *const *args,
173 const char *cfgfile, 174 const char *cfgfile,
174 const struct GNUNET_CONFIGURATION_Handle *c) 175 const struct GNUNET_CONFIGURATION_Handle *c)
175{ 176{
176 arm = GNUNET_ARM_connect(c, 177 arm = GNUNET_ARM_connect (c,
177 NULL, 178 NULL,
178 NULL); 179 NULL);
179 GNUNET_ARM_request_service_start(arm, 180 GNUNET_ARM_request_service_start (arm,
180 "arm", 181 "arm",
181 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 182 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
182 &arm_start_cb, 183 &arm_start_cb,
183 NULL); 184 NULL);
184} 185}
185 186
186 187
187int 188int
188main(int argc, char *av[]) 189main (int argc, char *av[])
189{ 190{
190 static char *const argv[] = { 191 static char *const argv[] = {
191 "test-gnunet-service-arm", 192 "test-gnunet-service-arm",
@@ -203,62 +204,62 @@ main(int argc, char *av[])
203 struct addrinfo *ai; 204 struct addrinfo *ai;
204 int ret; 205 int ret;
205 206
206 if (0 != (ret = getaddrinfo(hostname, NULL, NULL, &ai))) 207 if (0 != (ret = getaddrinfo (hostname, NULL, NULL, &ai)))
207 { 208 {
208 fprintf(stderr, 209 fprintf (stderr,
209 "Failed to resolve `%s', testcase not run.\n", 210 "Failed to resolve `%s', testcase not run.\n",
210 hostname); 211 hostname);
211 return 77; 212 return 77;
212 } 213 }
213 freeaddrinfo(ai); 214 freeaddrinfo (ai);
214 } 215 }
215#elif HAVE_GETHOSTBYNAME2 216#elif HAVE_GETHOSTBYNAME2
216 { 217 {
217 struct hostent *host; 218 struct hostent *host;
218 219
219 host = gethostbyname2(hostname, AF_INET); 220 host = gethostbyname2 (hostname, AF_INET);
220 if (NULL == host) 221 if (NULL == host)
221 host = gethostbyname2(hostname, AF_INET6); 222 host = gethostbyname2 (hostname, AF_INET6);
222 if (NULL == host) 223 if (NULL == host)
223 { 224 {
224 fprintf(stderr, 225 fprintf (stderr,
225 "Failed to resolve `%s', testcase not run.\n", 226 "Failed to resolve `%s', testcase not run.\n",
226 hostname); 227 hostname);
227 return 77; 228 return 77;
228 } 229 }
229 } 230 }
230#elif HAVE_GETHOSTBYNAME 231#elif HAVE_GETHOSTBYNAME
231 { 232 {
232 struct hostent *host; 233 struct hostent *host;
233 234
234 host = gethostbyname(hostname); 235 host = gethostbyname (hostname);
235 if (NULL == host) 236 if (NULL == host)
236 { 237 {
237 fprintf(stderr, 238 fprintf (stderr,
238 "Failed to resolve `%s', testcase not run.\n", 239 "Failed to resolve `%s', testcase not run.\n",
239 hostname); 240 hostname);
240 return 77; 241 return 77;
241 } 242 }
242 } 243 }
243#else 244#else
244 fprintf(stderr, 245 fprintf (stderr,
245 "libc fails to have resolver function, testcase not run.\n"); 246 "libc fails to have resolver function, testcase not run.\n");
246 return 77; 247 return 77;
247#endif 248#endif
248 GNUNET_log_setup("test-gnunet-service-arm", 249 GNUNET_log_setup ("test-gnunet-service-arm",
249 "WARNING", 250 "WARNING",
250 NULL); 251 NULL);
251 GNUNET_break(GNUNET_OK == 252 GNUNET_break (GNUNET_OK ==
252 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, 253 GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1,
253 argv, "test-gnunet-service-arm", 254 argv, "test-gnunet-service-arm",
254 "nohelp", options, 255 "nohelp", options,
255 &run, NULL)); 256 &run, NULL));
256 if (0 != ret) 257 if (0 != ret)
257 { 258 {
258 fprintf(stderr, 259 fprintf (stderr,
259 "Test failed with error code %d\n", 260 "Test failed with error code %d\n",
260 ret); 261 ret);
261 } 262 }
262 return ret; 263 return ret;
263} 264}
264 265