diff options
Diffstat (limited to 'src/arm/arm_monitor_api.c')
-rw-r--r-- | src/arm/arm_monitor_api.c | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/src/arm/arm_monitor_api.c b/src/arm/arm_monitor_api.c index 15f91c036..55b12240f 100644 --- a/src/arm/arm_monitor_api.c +++ b/src/arm/arm_monitor_api.c | |||
@@ -32,7 +32,7 @@ | |||
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. |
@@ -69,7 +69,6 @@ struct GNUNET_ARM_MonitorHandle | |||
69 | * Closure for @e service_status. | 69 | * Closure for @e service_status. |
70 | */ | 70 | */ |
71 | void *service_status_cls; | 71 | void *service_status_cls; |
72 | |||
73 | }; | 72 | }; |
74 | 73 | ||
75 | 74 | ||
@@ -115,9 +114,9 @@ reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h) | |||
115 | h->mq = NULL; | 114 | h->mq = NULL; |
116 | } | 115 | } |
117 | GNUNET_assert (NULL == h->reconnect_task); | 116 | GNUNET_assert (NULL == h->reconnect_task); |
118 | h->reconnect_task | 117 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, |
119 | = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, | 118 | &reconnect_arm_monitor_task, |
120 | &reconnect_arm_monitor_task, h); | 119 | h); |
121 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); | 120 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); |
122 | } | 121 | } |
123 | 122 | ||
@@ -130,14 +129,14 @@ reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h) | |||
130 | * @return #GNUNET_OK if the message is well-formed | 129 | * @return #GNUNET_OK if the message is well-formed |
131 | */ | 130 | */ |
132 | static int | 131 | static int |
133 | check_monitor_notify (void *cls, | 132 | check_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *msg) |
134 | const struct GNUNET_ARM_StatusMessage *msg) | ||
135 | { | 133 | { |
136 | size_t sl = ntohs (msg->header.size) - sizeof (struct GNUNET_ARM_StatusMessage); | 134 | size_t sl = |
135 | ntohs (msg->header.size) - sizeof (struct GNUNET_ARM_StatusMessage); | ||
137 | const char *name = (const char *) &msg[1]; | 136 | const char *name = (const char *) &msg[1]; |
138 | 137 | ||
139 | if ( (0 == sl) || | 138 | (void) cls; |
140 | ('\0' != name[sl-1]) ) | 139 | if ((0 == sl) || ('\0' != name[sl - 1])) |
141 | { | 140 | { |
142 | GNUNET_break (0); | 141 | GNUNET_break (0); |
143 | return GNUNET_SYSERR; | 142 | return GNUNET_SYSERR; |
@@ -153,8 +152,7 @@ check_monitor_notify (void *cls, | |||
153 | * @param res the message received from the arm service | 152 | * @param res the message received from the arm service |
154 | */ | 153 | */ |
155 | static void | 154 | static void |
156 | handle_monitor_notify (void *cls, | 155 | handle_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *res) |
157 | const struct GNUNET_ARM_StatusMessage *res) | ||
158 | { | 156 | { |
159 | struct GNUNET_ARM_MonitorHandle *h = cls; | 157 | struct GNUNET_ARM_MonitorHandle *h = cls; |
160 | enum GNUNET_ARM_ServiceStatus status; | 158 | enum GNUNET_ARM_ServiceStatus status; |
@@ -165,9 +163,7 @@ handle_monitor_notify (void *cls, | |||
165 | (const char *) &res[1], | 163 | (const char *) &res[1], |
166 | (int) status); | 164 | (int) status); |
167 | if (NULL != h->service_status) | 165 | if (NULL != h->service_status) |
168 | h->service_status (h->service_status_cls, | 166 | h->service_status (h->service_status_cls, (const char *) &res[1], status); |
169 | (const char *) &res[1], | ||
170 | status); | ||
171 | } | 167 | } |
172 | 168 | ||
173 | 169 | ||
@@ -180,11 +176,11 @@ handle_monitor_notify (void *cls, | |||
180 | * @param error error code | 176 | * @param error error code |
181 | */ | 177 | */ |
182 | static void | 178 | static void |
183 | mq_error_handler (void *cls, | 179 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
184 | enum GNUNET_MQ_Error error) | ||
185 | { | 180 | { |
186 | struct GNUNET_ARM_MonitorHandle *h = cls; | 181 | struct GNUNET_ARM_MonitorHandle *h = cls; |
187 | 182 | ||
183 | (void) error; | ||
188 | reconnect_arm_monitor_later (h); | 184 | reconnect_arm_monitor_later (h); |
189 | } | 185 | } |
190 | 186 | ||
@@ -198,22 +194,17 @@ mq_error_handler (void *cls, | |||
198 | static int | 194 | static int |
199 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) | 195 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) |
200 | { | 196 | { |
201 | struct GNUNET_MQ_MessageHandler handlers[] = { | 197 | struct GNUNET_MQ_MessageHandler handlers[] = |
202 | GNUNET_MQ_hd_var_size (monitor_notify, | 198 | {GNUNET_MQ_hd_var_size (monitor_notify, |
203 | GNUNET_MESSAGE_TYPE_ARM_STATUS, | 199 | GNUNET_MESSAGE_TYPE_ARM_STATUS, |
204 | struct GNUNET_ARM_StatusMessage, | 200 | struct GNUNET_ARM_StatusMessage, |
205 | h), | 201 | h), |
206 | GNUNET_MQ_handler_end () | 202 | GNUNET_MQ_handler_end ()}; |
207 | }; | ||
208 | struct GNUNET_MessageHeader *msg; | 203 | struct GNUNET_MessageHeader *msg; |
209 | struct GNUNET_MQ_Envelope *env; | 204 | struct GNUNET_MQ_Envelope *env; |
210 | 205 | ||
211 | GNUNET_assert (NULL == h->mq); | 206 | GNUNET_assert (NULL == h->mq); |
212 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 207 | h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h); |
213 | "arm", | ||
214 | handlers, | ||
215 | &mq_error_handler, | ||
216 | h); | ||
217 | if (NULL == h->mq) | 208 | if (NULL == h->mq) |
218 | { | 209 | { |
219 | if (NULL != h->service_status) | 210 | if (NULL != h->service_status) |
@@ -222,10 +213,8 @@ reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) | |||
222 | GNUNET_ARM_SERVICE_STOPPED); | 213 | GNUNET_ARM_SERVICE_STOPPED); |
223 | return GNUNET_SYSERR; | 214 | return GNUNET_SYSERR; |
224 | } | 215 | } |
225 | env = GNUNET_MQ_msg (msg, | 216 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR); |
226 | GNUNET_MESSAGE_TYPE_ARM_MONITOR); | 217 | GNUNET_MQ_send (h->mq, env); |
227 | GNUNET_MQ_send (h->mq, | ||
228 | env); | ||
229 | return GNUNET_OK; | 218 | return GNUNET_OK; |
230 | } | 219 | } |
231 | 220 | ||