diff options
Diffstat (limited to 'src/ats/ats_api_connectivity.c')
-rw-r--r-- | src/ats/ats_api_connectivity.c | 216 |
1 files changed, 110 insertions, 106 deletions
diff --git a/src/ats/ats_api_connectivity.c b/src/ats/ats_api_connectivity.c index 2ff734c25..1b8e82777 100644 --- a/src/ats/ats_api_connectivity.c +++ b/src/ats/ats_api_connectivity.c | |||
@@ -28,13 +28,15 @@ | |||
28 | #include "ats.h" | 28 | #include "ats.h" |
29 | 29 | ||
30 | 30 | ||
31 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-connectivity-api", __VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from (kind, "ats-connectivity-api", \ |
32 | __VA_ARGS__) | ||
32 | 33 | ||
33 | 34 | ||
34 | /** | 35 | /** |
35 | * Handle for ATS address suggestion requests. | 36 | * Handle for ATS address suggestion requests. |
36 | */ | 37 | */ |
37 | struct GNUNET_ATS_ConnectivitySuggestHandle { | 38 | struct GNUNET_ATS_ConnectivitySuggestHandle |
39 | { | ||
38 | /** | 40 | /** |
39 | * ID of the peer for which address suggestion was requested. | 41 | * ID of the peer for which address suggestion was requested. |
40 | */ | 42 | */ |
@@ -55,7 +57,8 @@ struct GNUNET_ATS_ConnectivitySuggestHandle { | |||
55 | /** | 57 | /** |
56 | * Handle to the ATS subsystem for connectivity management. | 58 | * Handle to the ATS subsystem for connectivity management. |
57 | */ | 59 | */ |
58 | struct GNUNET_ATS_ConnectivityHandle { | 60 | struct GNUNET_ATS_ConnectivityHandle |
61 | { | ||
59 | /** | 62 | /** |
60 | * Our configuration. | 63 | * Our configuration. |
61 | */ | 64 | */ |
@@ -91,7 +94,7 @@ struct GNUNET_ATS_ConnectivityHandle { | |||
91 | * @param ch handle to use to re-connect. | 94 | * @param ch handle to use to re-connect. |
92 | */ | 95 | */ |
93 | static void | 96 | static void |
94 | reconnect(struct GNUNET_ATS_ConnectivityHandle *ch); | 97 | reconnect (struct GNUNET_ATS_ConnectivityHandle *ch); |
95 | 98 | ||
96 | 99 | ||
97 | /** | 100 | /** |
@@ -100,12 +103,12 @@ reconnect(struct GNUNET_ATS_ConnectivityHandle *ch); | |||
100 | * @param cls handle to use to re-connect. | 103 | * @param cls handle to use to re-connect. |
101 | */ | 104 | */ |
102 | static void | 105 | static void |
103 | reconnect_task(void *cls) | 106 | reconnect_task (void *cls) |
104 | { | 107 | { |
105 | struct GNUNET_ATS_ConnectivityHandle *ch = cls; | 108 | struct GNUNET_ATS_ConnectivityHandle *ch = cls; |
106 | 109 | ||
107 | ch->task = NULL; | 110 | ch->task = NULL; |
108 | reconnect(ch); | 111 | reconnect (ch); |
109 | } | 112 | } |
110 | 113 | ||
111 | 114 | ||
@@ -115,17 +118,17 @@ reconnect_task(void *cls) | |||
115 | * @param ch our handle | 118 | * @param ch our handle |
116 | */ | 119 | */ |
117 | static void | 120 | static void |
118 | force_reconnect(struct GNUNET_ATS_ConnectivityHandle *ch) | 121 | force_reconnect (struct GNUNET_ATS_ConnectivityHandle *ch) |
119 | { | 122 | { |
120 | if (NULL != ch->mq) | 123 | if (NULL != ch->mq) |
121 | { | 124 | { |
122 | GNUNET_MQ_destroy(ch->mq); | 125 | GNUNET_MQ_destroy (ch->mq); |
123 | ch->mq = NULL; | 126 | ch->mq = NULL; |
124 | } | 127 | } |
125 | ch->backoff = GNUNET_TIME_STD_BACKOFF(ch->backoff); | 128 | ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff); |
126 | ch->task = GNUNET_SCHEDULER_add_delayed(ch->backoff, | 129 | ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff, |
127 | &reconnect_task, | 130 | &reconnect_task, |
128 | ch); | 131 | ch); |
129 | } | 132 | } |
130 | 133 | ||
131 | 134 | ||
@@ -137,15 +140,15 @@ force_reconnect(struct GNUNET_ATS_ConnectivityHandle *ch) | |||
137 | * @param error details about the error | 140 | * @param error details about the error |
138 | */ | 141 | */ |
139 | static void | 142 | static void |
140 | error_handler(void *cls, | 143 | error_handler (void *cls, |
141 | enum GNUNET_MQ_Error error) | 144 | enum GNUNET_MQ_Error error) |
142 | { | 145 | { |
143 | struct GNUNET_ATS_ConnectivityHandle *ch = cls; | 146 | struct GNUNET_ATS_ConnectivityHandle *ch = cls; |
144 | 147 | ||
145 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 148 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
146 | "ATS connection died (code %d), reconnecting\n", | 149 | "ATS connection died (code %d), reconnecting\n", |
147 | (int)error); | 150 | (int) error); |
148 | force_reconnect(ch); | 151 | force_reconnect (ch); |
149 | } | 152 | } |
150 | 153 | ||
151 | 154 | ||
@@ -159,9 +162,9 @@ error_handler(void *cls, | |||
159 | * failure (message queue no longer exists) | 162 | * failure (message queue no longer exists) |
160 | */ | 163 | */ |
161 | static int | 164 | static int |
162 | transmit_suggestion(void *cls, | 165 | transmit_suggestion (void *cls, |
163 | const struct GNUNET_PeerIdentity *peer, | 166 | const struct GNUNET_PeerIdentity *peer, |
164 | void *value) | 167 | void *value) |
165 | { | 168 | { |
166 | struct GNUNET_ATS_ConnectivityHandle *ch = cls; | 169 | struct GNUNET_ATS_ConnectivityHandle *ch = cls; |
167 | struct GNUNET_ATS_ConnectivitySuggestHandle *sh = value; | 170 | struct GNUNET_ATS_ConnectivitySuggestHandle *sh = value; |
@@ -170,10 +173,10 @@ transmit_suggestion(void *cls, | |||
170 | 173 | ||
171 | if (NULL == ch->mq) | 174 | if (NULL == ch->mq) |
172 | return GNUNET_SYSERR; | 175 | return GNUNET_SYSERR; |
173 | ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS); | 176 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS); |
174 | m->strength = htonl(sh->strength); | 177 | m->strength = htonl (sh->strength); |
175 | m->peer = *peer; | 178 | m->peer = *peer; |
176 | GNUNET_MQ_send(ch->mq, ev); | 179 | GNUNET_MQ_send (ch->mq, ev); |
177 | return GNUNET_OK; | 180 | return GNUNET_OK; |
178 | } | 181 | } |
179 | 182 | ||
@@ -184,33 +187,33 @@ transmit_suggestion(void *cls, | |||
184 | * @param ch handle to use to re-connect. | 187 | * @param ch handle to use to re-connect. |
185 | */ | 188 | */ |
186 | static void | 189 | static void |
187 | reconnect(struct GNUNET_ATS_ConnectivityHandle *ch) | 190 | reconnect (struct GNUNET_ATS_ConnectivityHandle *ch) |
188 | { | 191 | { |
189 | static const struct GNUNET_MQ_MessageHandler handlers[] = | 192 | static const struct GNUNET_MQ_MessageHandler handlers[] = |
190 | { { NULL, 0, 0 } }; | 193 | { { NULL, 0, 0 } }; |
191 | struct GNUNET_MQ_Envelope *ev; | 194 | struct GNUNET_MQ_Envelope *ev; |
192 | struct ClientStartMessage *init; | 195 | struct ClientStartMessage *init; |
193 | 196 | ||
194 | GNUNET_assert(NULL == ch->mq); | 197 | GNUNET_assert (NULL == ch->mq); |
195 | ch->mq = GNUNET_CLIENT_connect(ch->cfg, | 198 | ch->mq = GNUNET_CLIENT_connect (ch->cfg, |
196 | "ats", | 199 | "ats", |
197 | handlers, | 200 | handlers, |
198 | &error_handler, | 201 | &error_handler, |
199 | ch); | 202 | ch); |
200 | if (NULL == ch->mq) | 203 | if (NULL == ch->mq) |
201 | { | 204 | { |
202 | force_reconnect(ch); | 205 | force_reconnect (ch); |
203 | return; | 206 | return; |
204 | } | 207 | } |
205 | ev = GNUNET_MQ_msg(init, | 208 | ev = GNUNET_MQ_msg (init, |
206 | GNUNET_MESSAGE_TYPE_ATS_START); | 209 | GNUNET_MESSAGE_TYPE_ATS_START); |
207 | init->start_flag = htonl(START_FLAG_CONNECTION_SUGGESTION); | 210 | init->start_flag = htonl (START_FLAG_CONNECTION_SUGGESTION); |
208 | GNUNET_MQ_send(ch->mq, ev); | 211 | GNUNET_MQ_send (ch->mq, ev); |
209 | if (NULL == ch->mq) | 212 | if (NULL == ch->mq) |
210 | return; | 213 | return; |
211 | GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, | 214 | GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests, |
212 | &transmit_suggestion, | 215 | &transmit_suggestion, |
213 | ch); | 216 | ch); |
214 | } | 217 | } |
215 | 218 | ||
216 | 219 | ||
@@ -221,15 +224,15 @@ reconnect(struct GNUNET_ATS_ConnectivityHandle *ch) | |||
221 | * @return ats connectivity handle, NULL on error | 224 | * @return ats connectivity handle, NULL on error |
222 | */ | 225 | */ |
223 | struct GNUNET_ATS_ConnectivityHandle * | 226 | struct GNUNET_ATS_ConnectivityHandle * |
224 | GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg) | 227 | GNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg) |
225 | { | 228 | { |
226 | struct GNUNET_ATS_ConnectivityHandle *ch; | 229 | struct GNUNET_ATS_ConnectivityHandle *ch; |
227 | 230 | ||
228 | ch = GNUNET_new(struct GNUNET_ATS_ConnectivityHandle); | 231 | ch = GNUNET_new (struct GNUNET_ATS_ConnectivityHandle); |
229 | ch->cfg = cfg; | 232 | ch->cfg = cfg; |
230 | ch->sug_requests = GNUNET_CONTAINER_multipeermap_create(32, | 233 | ch->sug_requests = GNUNET_CONTAINER_multipeermap_create (32, |
231 | GNUNET_YES); | 234 | GNUNET_YES); |
232 | reconnect(ch); | 235 | reconnect (ch); |
233 | return ch; | 236 | return ch; |
234 | } | 237 | } |
235 | 238 | ||
@@ -244,13 +247,13 @@ GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
244 | * @return #GNUNET_OK (continue to iterate) | 247 | * @return #GNUNET_OK (continue to iterate) |
245 | */ | 248 | */ |
246 | static int | 249 | static int |
247 | free_sug_handle(void *cls, | 250 | free_sug_handle (void *cls, |
248 | const struct GNUNET_PeerIdentity *key, | 251 | const struct GNUNET_PeerIdentity *key, |
249 | void *value) | 252 | void *value) |
250 | { | 253 | { |
251 | struct GNUNET_ATS_ConnectivitySuggestHandle *cur = value; | 254 | struct GNUNET_ATS_ConnectivitySuggestHandle *cur = value; |
252 | 255 | ||
253 | GNUNET_free(cur); | 256 | GNUNET_free (cur); |
254 | return GNUNET_OK; | 257 | return GNUNET_OK; |
255 | } | 258 | } |
256 | 259 | ||
@@ -261,23 +264,23 @@ free_sug_handle(void *cls, | |||
261 | * @param ch handle to release | 264 | * @param ch handle to release |
262 | */ | 265 | */ |
263 | void | 266 | void |
264 | GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch) | 267 | GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch) |
265 | { | 268 | { |
266 | if (NULL != ch->mq) | 269 | if (NULL != ch->mq) |
267 | { | 270 | { |
268 | GNUNET_MQ_destroy(ch->mq); | 271 | GNUNET_MQ_destroy (ch->mq); |
269 | ch->mq = NULL; | 272 | ch->mq = NULL; |
270 | } | 273 | } |
271 | if (NULL != ch->task) | 274 | if (NULL != ch->task) |
272 | { | 275 | { |
273 | GNUNET_SCHEDULER_cancel(ch->task); | 276 | GNUNET_SCHEDULER_cancel (ch->task); |
274 | ch->task = NULL; | 277 | ch->task = NULL; |
275 | } | 278 | } |
276 | GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, | 279 | GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests, |
277 | &free_sug_handle, | 280 | &free_sug_handle, |
278 | NULL); | 281 | NULL); |
279 | GNUNET_CONTAINER_multipeermap_destroy(ch->sug_requests); | 282 | GNUNET_CONTAINER_multipeermap_destroy (ch->sug_requests); |
280 | GNUNET_free(ch); | 283 | GNUNET_free (ch); |
281 | } | 284 | } |
282 | 285 | ||
283 | 286 | ||
@@ -293,36 +296,36 @@ GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch) | |||
293 | * @return suggest handle, NULL if a request is already pending | 296 | * @return suggest handle, NULL if a request is already pending |
294 | */ | 297 | */ |
295 | struct GNUNET_ATS_ConnectivitySuggestHandle * | 298 | struct GNUNET_ATS_ConnectivitySuggestHandle * |
296 | GNUNET_ATS_connectivity_suggest(struct GNUNET_ATS_ConnectivityHandle *ch, | 299 | GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch, |
297 | const struct GNUNET_PeerIdentity *peer, | 300 | const struct GNUNET_PeerIdentity *peer, |
298 | uint32_t strength) | 301 | uint32_t strength) |
299 | { | 302 | { |
300 | struct GNUNET_ATS_ConnectivitySuggestHandle *s; | 303 | struct GNUNET_ATS_ConnectivitySuggestHandle *s; |
301 | 304 | ||
302 | s = GNUNET_new(struct GNUNET_ATS_ConnectivitySuggestHandle); | 305 | s = GNUNET_new (struct GNUNET_ATS_ConnectivitySuggestHandle); |
303 | s->ch = ch; | 306 | s->ch = ch; |
304 | s->id = *peer; | 307 | s->id = *peer; |
305 | s->strength = strength; | 308 | s->strength = strength; |
306 | if (GNUNET_OK != | 309 | if (GNUNET_OK != |
307 | GNUNET_CONTAINER_multipeermap_put(ch->sug_requests, | 310 | GNUNET_CONTAINER_multipeermap_put (ch->sug_requests, |
308 | &s->id, | 311 | &s->id, |
309 | s, | 312 | s, |
310 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 313 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
311 | { | 314 | { |
312 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 315 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
313 | "Not requesting ATS to suggest address for `%s', request already pending\n", | 316 | "Not requesting ATS to suggest address for `%s', request already pending\n", |
314 | GNUNET_i2s(peer)); | 317 | GNUNET_i2s (peer)); |
315 | GNUNET_free(s); | 318 | GNUNET_free (s); |
316 | return NULL; | 319 | return NULL; |
317 | } | 320 | } |
318 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 321 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
319 | "Requesting ATS to suggest address for `%s'\n", | 322 | "Requesting ATS to suggest address for `%s'\n", |
320 | GNUNET_i2s(peer)); | 323 | GNUNET_i2s (peer)); |
321 | if (NULL == ch->mq) | 324 | if (NULL == ch->mq) |
322 | return s; | 325 | return s; |
323 | (void)transmit_suggestion(ch, | 326 | (void) transmit_suggestion (ch, |
324 | &s->id, | 327 | &s->id, |
325 | s); | 328 | s); |
326 | return s; | 329 | return s; |
327 | } | 330 | } |
328 | 331 | ||
@@ -333,30 +336,31 @@ GNUNET_ATS_connectivity_suggest(struct GNUNET_ATS_ConnectivityHandle *ch, | |||
333 | * @param sh handle to stop | 336 | * @param sh handle to stop |
334 | */ | 337 | */ |
335 | void | 338 | void |
336 | GNUNET_ATS_connectivity_suggest_cancel(struct GNUNET_ATS_ConnectivitySuggestHandle *sh) | 339 | GNUNET_ATS_connectivity_suggest_cancel (struct |
340 | GNUNET_ATS_ConnectivitySuggestHandle *sh) | ||
337 | { | 341 | { |
338 | struct GNUNET_ATS_ConnectivityHandle *ch = sh->ch; | 342 | struct GNUNET_ATS_ConnectivityHandle *ch = sh->ch; |
339 | struct GNUNET_MQ_Envelope *ev; | 343 | struct GNUNET_MQ_Envelope *ev; |
340 | struct RequestAddressMessage *m; | 344 | struct RequestAddressMessage *m; |
341 | 345 | ||
342 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 346 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
343 | "Telling ATS we no longer care for an address for `%s'\n", | 347 | "Telling ATS we no longer care for an address for `%s'\n", |
344 | GNUNET_i2s(&sh->id)); | 348 | GNUNET_i2s (&sh->id)); |
345 | GNUNET_assert(GNUNET_OK == | 349 | GNUNET_assert (GNUNET_OK == |
346 | GNUNET_CONTAINER_multipeermap_remove(ch->sug_requests, | 350 | GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests, |
347 | &sh->id, | 351 | &sh->id, |
348 | sh)); | 352 | sh)); |
349 | if (NULL == ch->mq) | 353 | if (NULL == ch->mq) |
350 | { | 354 | { |
351 | GNUNET_free(sh); | 355 | GNUNET_free (sh); |
352 | return; | 356 | return; |
353 | } | 357 | } |
354 | ev = GNUNET_MQ_msg(m, | 358 | ev = GNUNET_MQ_msg (m, |
355 | GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL); | 359 | GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL); |
356 | m->strength = htonl(0); | 360 | m->strength = htonl (0); |
357 | m->peer = sh->id; | 361 | m->peer = sh->id; |
358 | GNUNET_MQ_send(ch->mq, ev); | 362 | GNUNET_MQ_send (ch->mq, ev); |
359 | GNUNET_free(sh); | 363 | GNUNET_free (sh); |
360 | } | 364 | } |
361 | 365 | ||
362 | 366 | ||