diff options
Diffstat (limited to 'src/transport/transport_api2_application.c')
-rw-r--r-- | src/transport/transport_api2_application.c | 184 |
1 files changed, 93 insertions, 91 deletions
diff --git a/src/transport/transport_api2_application.c b/src/transport/transport_api2_application.c index 8ddf48a86..4862863dd 100644 --- a/src/transport/transport_api2_application.c +++ b/src/transport/transport_api2_application.c | |||
@@ -30,13 +30,14 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | #define LOG(kind, ...) \ | 32 | #define LOG(kind, ...) \ |
33 | GNUNET_log_from(kind, "transport-application-api", __VA_ARGS__) | 33 | GNUNET_log_from (kind, "transport-application-api", __VA_ARGS__) |
34 | 34 | ||
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Handle for TRANSPORT address suggestion requests. | 37 | * Handle for TRANSPORT address suggestion requests. |
38 | */ | 38 | */ |
39 | struct GNUNET_TRANSPORT_ApplicationSuggestHandle { | 39 | struct GNUNET_TRANSPORT_ApplicationSuggestHandle |
40 | { | ||
40 | /** | 41 | /** |
41 | * ID of the peer for which address suggestion was requested. | 42 | * ID of the peer for which address suggestion was requested. |
42 | */ | 43 | */ |
@@ -62,7 +63,8 @@ struct GNUNET_TRANSPORT_ApplicationSuggestHandle { | |||
62 | /** | 63 | /** |
63 | * Handle to the TRANSPORT subsystem for application management. | 64 | * Handle to the TRANSPORT subsystem for application management. |
64 | */ | 65 | */ |
65 | struct GNUNET_TRANSPORT_ApplicationHandle { | 66 | struct GNUNET_TRANSPORT_ApplicationHandle |
67 | { | ||
66 | /** | 68 | /** |
67 | * Our configuration. | 69 | * Our configuration. |
68 | */ | 70 | */ |
@@ -98,7 +100,7 @@ struct GNUNET_TRANSPORT_ApplicationHandle { | |||
98 | * @param ch handle to use to re-connect. | 100 | * @param ch handle to use to re-connect. |
99 | */ | 101 | */ |
100 | static void | 102 | static void |
101 | reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch); | 103 | reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch); |
102 | 104 | ||
103 | 105 | ||
104 | /** | 106 | /** |
@@ -107,12 +109,12 @@ reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch); | |||
107 | * @param cls handle to use to re-connect. | 109 | * @param cls handle to use to re-connect. |
108 | */ | 110 | */ |
109 | static void | 111 | static void |
110 | reconnect_task(void *cls) | 112 | reconnect_task (void *cls) |
111 | { | 113 | { |
112 | struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; | 114 | struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; |
113 | 115 | ||
114 | ch->task = NULL; | 116 | ch->task = NULL; |
115 | reconnect(ch); | 117 | reconnect (ch); |
116 | } | 118 | } |
117 | 119 | ||
118 | 120 | ||
@@ -122,15 +124,15 @@ reconnect_task(void *cls) | |||
122 | * @param ch our handle | 124 | * @param ch our handle |
123 | */ | 125 | */ |
124 | static void | 126 | static void |
125 | force_reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch) | 127 | force_reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch) |
126 | { | 128 | { |
127 | if (NULL != ch->mq) | 129 | if (NULL != ch->mq) |
128 | { | 130 | { |
129 | GNUNET_MQ_destroy(ch->mq); | 131 | GNUNET_MQ_destroy (ch->mq); |
130 | ch->mq = NULL; | 132 | ch->mq = NULL; |
131 | } | 133 | } |
132 | ch->backoff = GNUNET_TIME_STD_BACKOFF(ch->backoff); | 134 | ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff); |
133 | ch->task = GNUNET_SCHEDULER_add_delayed(ch->backoff, &reconnect_task, ch); | 135 | ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff, &reconnect_task, ch); |
134 | } | 136 | } |
135 | 137 | ||
136 | 138 | ||
@@ -142,14 +144,14 @@ force_reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch) | |||
142 | * @param error details about the error | 144 | * @param error details about the error |
143 | */ | 145 | */ |
144 | static void | 146 | static void |
145 | error_handler(void *cls, enum GNUNET_MQ_Error error) | 147 | error_handler (void *cls, enum GNUNET_MQ_Error error) |
146 | { | 148 | { |
147 | struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; | 149 | struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; |
148 | 150 | ||
149 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 151 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
150 | "TRANSPORT connection died (code %d), reconnecting\n", | 152 | "TRANSPORT connection died (code %d), reconnecting\n", |
151 | (int)error); | 153 | (int) error); |
152 | force_reconnect(ch); | 154 | force_reconnect (ch); |
153 | } | 155 | } |
154 | 156 | ||
155 | 157 | ||
@@ -163,9 +165,9 @@ error_handler(void *cls, enum GNUNET_MQ_Error error) | |||
163 | * failure (message queue no longer exists) | 165 | * failure (message queue no longer exists) |
164 | */ | 166 | */ |
165 | static int | 167 | static int |
166 | transmit_suggestion(void *cls, | 168 | transmit_suggestion (void *cls, |
167 | const struct GNUNET_PeerIdentity *peer, | 169 | const struct GNUNET_PeerIdentity *peer, |
168 | void *value) | 170 | void *value) |
169 | { | 171 | { |
170 | struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; | 172 | struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; |
171 | struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh = value; | 173 | struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh = value; |
@@ -174,11 +176,11 @@ transmit_suggestion(void *cls, | |||
174 | 176 | ||
175 | if (NULL == ch->mq) | 177 | if (NULL == ch->mq) |
176 | return GNUNET_SYSERR; | 178 | return GNUNET_SYSERR; |
177 | ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST); | 179 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST); |
178 | m->pk = htonl((uint32_t)sh->pk); | 180 | m->pk = htonl ((uint32_t) sh->pk); |
179 | m->bw = sh->bw; | 181 | m->bw = sh->bw; |
180 | m->peer = *peer; | 182 | m->peer = *peer; |
181 | GNUNET_MQ_send(ch->mq, ev); | 183 | GNUNET_MQ_send (ch->mq, ev); |
182 | return GNUNET_OK; | 184 | return GNUNET_OK; |
183 | } | 185 | } |
184 | 186 | ||
@@ -189,21 +191,21 @@ transmit_suggestion(void *cls, | |||
189 | * @param ch handle to use to re-connect. | 191 | * @param ch handle to use to re-connect. |
190 | */ | 192 | */ |
191 | static void | 193 | static void |
192 | reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch) | 194 | reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch) |
193 | { | 195 | { |
194 | static const struct GNUNET_MQ_MessageHandler handlers[] = { { NULL, 0, 0 } }; | 196 | static const struct GNUNET_MQ_MessageHandler handlers[] = { { NULL, 0, 0 } }; |
195 | 197 | ||
196 | GNUNET_assert(NULL == ch->mq); | 198 | GNUNET_assert (NULL == ch->mq); |
197 | ch->mq = | 199 | ch->mq = |
198 | GNUNET_CLIENT_connect(ch->cfg, "transport", handlers, &error_handler, ch); | 200 | GNUNET_CLIENT_connect (ch->cfg, "transport", handlers, &error_handler, ch); |
199 | if (NULL == ch->mq) | 201 | if (NULL == ch->mq) |
200 | { | 202 | { |
201 | force_reconnect(ch); | 203 | force_reconnect (ch); |
202 | return; | 204 | return; |
203 | } | 205 | } |
204 | GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, | 206 | GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests, |
205 | &transmit_suggestion, | 207 | &transmit_suggestion, |
206 | ch); | 208 | ch); |
207 | } | 209 | } |
208 | 210 | ||
209 | 211 | ||
@@ -214,15 +216,15 @@ reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch) | |||
214 | * @return transport application handle, NULL on error | 216 | * @return transport application handle, NULL on error |
215 | */ | 217 | */ |
216 | struct GNUNET_TRANSPORT_ApplicationHandle * | 218 | struct GNUNET_TRANSPORT_ApplicationHandle * |
217 | GNUNET_TRANSPORT_application_init( | 219 | GNUNET_TRANSPORT_application_init ( |
218 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 220 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
219 | { | 221 | { |
220 | struct GNUNET_TRANSPORT_ApplicationHandle *ch; | 222 | struct GNUNET_TRANSPORT_ApplicationHandle *ch; |
221 | 223 | ||
222 | ch = GNUNET_new(struct GNUNET_TRANSPORT_ApplicationHandle); | 224 | ch = GNUNET_new (struct GNUNET_TRANSPORT_ApplicationHandle); |
223 | ch->cfg = cfg; | 225 | ch->cfg = cfg; |
224 | ch->sug_requests = GNUNET_CONTAINER_multipeermap_create(32, GNUNET_YES); | 226 | ch->sug_requests = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); |
225 | reconnect(ch); | 227 | reconnect (ch); |
226 | return ch; | 228 | return ch; |
227 | } | 229 | } |
228 | 230 | ||
@@ -237,11 +239,11 @@ GNUNET_TRANSPORT_application_init( | |||
237 | * @return #GNUNET_OK (continue to iterate) | 239 | * @return #GNUNET_OK (continue to iterate) |
238 | */ | 240 | */ |
239 | static int | 241 | static int |
240 | free_sug_handle(void *cls, const struct GNUNET_PeerIdentity *key, void *value) | 242 | free_sug_handle (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
241 | { | 243 | { |
242 | struct GNUNET_TRANSPORT_ApplicationSuggestHandle *cur = value; | 244 | struct GNUNET_TRANSPORT_ApplicationSuggestHandle *cur = value; |
243 | 245 | ||
244 | GNUNET_free(cur); | 246 | GNUNET_free (cur); |
245 | return GNUNET_OK; | 247 | return GNUNET_OK; |
246 | } | 248 | } |
247 | 249 | ||
@@ -252,24 +254,24 @@ free_sug_handle(void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
252 | * @param ch handle to release | 254 | * @param ch handle to release |
253 | */ | 255 | */ |
254 | void | 256 | void |
255 | GNUNET_TRANSPORT_application_done( | 257 | GNUNET_TRANSPORT_application_done ( |
256 | struct GNUNET_TRANSPORT_ApplicationHandle *ch) | 258 | struct GNUNET_TRANSPORT_ApplicationHandle *ch) |
257 | { | 259 | { |
258 | if (NULL != ch->mq) | 260 | if (NULL != ch->mq) |
259 | { | 261 | { |
260 | GNUNET_MQ_destroy(ch->mq); | 262 | GNUNET_MQ_destroy (ch->mq); |
261 | ch->mq = NULL; | 263 | ch->mq = NULL; |
262 | } | 264 | } |
263 | if (NULL != ch->task) | 265 | if (NULL != ch->task) |
264 | { | 266 | { |
265 | GNUNET_SCHEDULER_cancel(ch->task); | 267 | GNUNET_SCHEDULER_cancel (ch->task); |
266 | ch->task = NULL; | 268 | ch->task = NULL; |
267 | } | 269 | } |
268 | GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, | 270 | GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests, |
269 | &free_sug_handle, | 271 | &free_sug_handle, |
270 | NULL); | 272 | NULL); |
271 | GNUNET_CONTAINER_multipeermap_destroy(ch->sug_requests); | 273 | GNUNET_CONTAINER_multipeermap_destroy (ch->sug_requests); |
272 | GNUNET_free(ch); | 274 | GNUNET_free (ch); |
273 | } | 275 | } |
274 | 276 | ||
275 | 277 | ||
@@ -284,7 +286,7 @@ GNUNET_TRANSPORT_application_done( | |||
284 | * @return suggest handle, NULL if a request is already pending | 286 | * @return suggest handle, NULL if a request is already pending |
285 | */ | 287 | */ |
286 | struct GNUNET_TRANSPORT_ApplicationSuggestHandle * | 288 | struct GNUNET_TRANSPORT_ApplicationSuggestHandle * |
287 | GNUNET_TRANSPORT_application_suggest( | 289 | GNUNET_TRANSPORT_application_suggest ( |
288 | struct GNUNET_TRANSPORT_ApplicationHandle *ch, | 290 | struct GNUNET_TRANSPORT_ApplicationHandle *ch, |
289 | const struct GNUNET_PeerIdentity *peer, | 291 | const struct GNUNET_PeerIdentity *peer, |
290 | enum GNUNET_MQ_PriorityPreferences pk, | 292 | enum GNUNET_MQ_PriorityPreferences pk, |
@@ -292,22 +294,22 @@ GNUNET_TRANSPORT_application_suggest( | |||
292 | { | 294 | { |
293 | struct GNUNET_TRANSPORT_ApplicationSuggestHandle *s; | 295 | struct GNUNET_TRANSPORT_ApplicationSuggestHandle *s; |
294 | 296 | ||
295 | s = GNUNET_new(struct GNUNET_TRANSPORT_ApplicationSuggestHandle); | 297 | s = GNUNET_new (struct GNUNET_TRANSPORT_ApplicationSuggestHandle); |
296 | s->ch = ch; | 298 | s->ch = ch; |
297 | s->id = *peer; | 299 | s->id = *peer; |
298 | s->pk = pk; | 300 | s->pk = pk; |
299 | s->bw = bw; | 301 | s->bw = bw; |
300 | (void)GNUNET_CONTAINER_multipeermap_put( | 302 | (void) GNUNET_CONTAINER_multipeermap_put ( |
301 | ch->sug_requests, | 303 | ch->sug_requests, |
302 | &s->id, | 304 | &s->id, |
303 | s, | 305 | s, |
304 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 306 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
305 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 307 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
306 | "Requesting TRANSPORT to suggest address for `%s'\n", | 308 | "Requesting TRANSPORT to suggest address for `%s'\n", |
307 | GNUNET_i2s(peer)); | 309 | GNUNET_i2s (peer)); |
308 | if (NULL == ch->mq) | 310 | if (NULL == ch->mq) |
309 | return s; | 311 | return s; |
310 | GNUNET_assert(GNUNET_OK == transmit_suggestion(ch, &s->id, s)); | 312 | GNUNET_assert (GNUNET_OK == transmit_suggestion (ch, &s->id, s)); |
311 | return s; | 313 | return s; |
312 | } | 314 | } |
313 | 315 | ||
@@ -318,30 +320,30 @@ GNUNET_TRANSPORT_application_suggest( | |||
318 | * @param sh handle to stop | 320 | * @param sh handle to stop |
319 | */ | 321 | */ |
320 | void | 322 | void |
321 | GNUNET_TRANSPORT_application_suggest_cancel( | 323 | GNUNET_TRANSPORT_application_suggest_cancel ( |
322 | struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh) | 324 | struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh) |
323 | { | 325 | { |
324 | struct GNUNET_TRANSPORT_ApplicationHandle *ch = sh->ch; | 326 | struct GNUNET_TRANSPORT_ApplicationHandle *ch = sh->ch; |
325 | struct GNUNET_MQ_Envelope *ev; | 327 | struct GNUNET_MQ_Envelope *ev; |
326 | struct ExpressPreferenceMessage *m; | 328 | struct ExpressPreferenceMessage *m; |
327 | 329 | ||
328 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 330 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
329 | "Telling TRANSPORT we no longer care for an address for `%s'\n", | 331 | "Telling TRANSPORT we no longer care for an address for `%s'\n", |
330 | GNUNET_i2s(&sh->id)); | 332 | GNUNET_i2s (&sh->id)); |
331 | GNUNET_assert( | 333 | GNUNET_assert ( |
332 | GNUNET_OK == | 334 | GNUNET_OK == |
333 | GNUNET_CONTAINER_multipeermap_remove(ch->sug_requests, &sh->id, sh)); | 335 | GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests, &sh->id, sh)); |
334 | if (NULL == ch->mq) | 336 | if (NULL == ch->mq) |
335 | { | 337 | { |
336 | GNUNET_free(sh); | 338 | GNUNET_free (sh); |
337 | return; | 339 | return; |
338 | } | 340 | } |
339 | ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL); | 341 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL); |
340 | m->pk = htonl((uint32_t)sh->pk); | 342 | m->pk = htonl ((uint32_t) sh->pk); |
341 | m->bw = sh->bw; | 343 | m->bw = sh->bw; |
342 | m->peer = sh->id; | 344 | m->peer = sh->id; |
343 | GNUNET_MQ_send(ch->mq, ev); | 345 | GNUNET_MQ_send (ch->mq, ev); |
344 | GNUNET_free(sh); | 346 | GNUNET_free (sh); |
345 | } | 347 | } |
346 | 348 | ||
347 | 349 | ||
@@ -361,7 +363,7 @@ GNUNET_TRANSPORT_application_suggest_cancel( | |||
361 | * @param addr address to validate | 363 | * @param addr address to validate |
362 | */ | 364 | */ |
363 | void | 365 | void |
364 | GNUNET_TRANSPORT_application_validate( | 366 | GNUNET_TRANSPORT_application_validate ( |
365 | struct GNUNET_TRANSPORT_ApplicationHandle *ch, | 367 | struct GNUNET_TRANSPORT_ApplicationHandle *ch, |
366 | const struct GNUNET_PeerIdentity *peer, | 368 | const struct GNUNET_PeerIdentity *peer, |
367 | enum GNUNET_NetworkType nt, | 369 | enum GNUNET_NetworkType nt, |
@@ -372,23 +374,23 @@ GNUNET_TRANSPORT_application_validate( | |||
372 | size_t alen; | 374 | size_t alen; |
373 | 375 | ||
374 | if (NULL == ch->mq) | 376 | if (NULL == ch->mq) |
375 | { | 377 | { |
376 | GNUNET_log( | 378 | GNUNET_log ( |
377 | GNUNET_ERROR_TYPE_WARNING, | 379 | GNUNET_ERROR_TYPE_WARNING, |
378 | "Address validation for %s:%s skipped as transport is not connected\n", | 380 | "Address validation for %s:%s skipped as transport is not connected\n", |
379 | GNUNET_i2s(peer), | 381 | GNUNET_i2s (peer), |
380 | addr); | 382 | addr); |
381 | return; | 383 | return; |
382 | } | 384 | } |
383 | alen = strlen(addr) + 1; | 385 | alen = strlen (addr) + 1; |
384 | ev = | 386 | ev = |
385 | GNUNET_MQ_msg_extra(m, | 387 | GNUNET_MQ_msg_extra (m, |
386 | alen, | 388 | alen, |
387 | GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION); | 389 | GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION); |
388 | m->peer = *peer; | 390 | m->peer = *peer; |
389 | m->nt = htonl((uint32_t)nt); | 391 | m->nt = htonl ((uint32_t) nt); |
390 | memcpy(&m[1], addr, alen); | 392 | memcpy (&m[1], addr, alen); |
391 | GNUNET_MQ_send(ch->mq, ev); | 393 | GNUNET_MQ_send (ch->mq, ev); |
392 | } | 394 | } |
393 | 395 | ||
394 | 396 | ||