aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api2_application.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport_api2_application.c')
-rw-r--r--src/transport/transport_api2_application.c113
1 files changed, 48 insertions, 65 deletions
diff --git a/src/transport/transport_api2_application.c b/src/transport/transport_api2_application.c
index 414a21fe4..49f0f36c7 100644
--- a/src/transport/transport_api2_application.c
+++ b/src/transport/transport_api2_application.c
@@ -29,7 +29,8 @@
29#include "transport.h" 29#include "transport.h"
30 30
31 31
32#define LOG(kind,...) GNUNET_log_from(kind, "transport-application-api", __VA_ARGS__) 32#define LOG(kind, ...) \
33 GNUNET_log_from (kind, "transport-application-api", __VA_ARGS__)
33 34
34 35
35/** 36/**
@@ -132,9 +133,7 @@ force_reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch)
132 ch->mq = NULL; 133 ch->mq = NULL;
133 } 134 }
134 ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff); 135 ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff);
135 ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff, 136 ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff, &reconnect_task, ch);
136 &reconnect_task,
137 ch);
138} 137}
139 138
140 139
@@ -146,8 +145,7 @@ force_reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch)
146 * @param error details about the error 145 * @param error details about the error
147 */ 146 */
148static void 147static void
149error_handler (void *cls, 148error_handler (void *cls, enum GNUNET_MQ_Error error)
150 enum GNUNET_MQ_Error error)
151{ 149{
152 struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; 150 struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls;
153 151
@@ -179,8 +177,7 @@ transmit_suggestion (void *cls,
179 177
180 if (NULL == ch->mq) 178 if (NULL == ch->mq)
181 return GNUNET_SYSERR; 179 return GNUNET_SYSERR;
182 ev = GNUNET_MQ_msg (m, 180 ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST);
183 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST);
184 m->pk = htonl ((uint32_t) sh->pk); 181 m->pk = htonl ((uint32_t) sh->pk);
185 m->bw = sh->bw; 182 m->bw = sh->bw;
186 m->peer = *peer; 183 m->peer = *peer;
@@ -197,16 +194,11 @@ transmit_suggestion (void *cls,
197static void 194static void
198reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch) 195reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch)
199{ 196{
200 static const struct GNUNET_MQ_MessageHandler handlers[] = { 197 static const struct GNUNET_MQ_MessageHandler handlers[] = {{NULL, 0, 0}};
201 { NULL, 0, 0 }
202 };
203 198
204 GNUNET_assert (NULL == ch->mq); 199 GNUNET_assert (NULL == ch->mq);
205 ch->mq = GNUNET_CLIENT_connect (ch->cfg, 200 ch->mq =
206 "transport", 201 GNUNET_CLIENT_connect (ch->cfg, "transport", handlers, &error_handler, ch);
207 handlers,
208 &error_handler,
209 ch);
210 if (NULL == ch->mq) 202 if (NULL == ch->mq)
211 { 203 {
212 force_reconnect (ch); 204 force_reconnect (ch);
@@ -225,14 +217,14 @@ reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch)
225 * @return transport application handle, NULL on error 217 * @return transport application handle, NULL on error
226 */ 218 */
227struct GNUNET_TRANSPORT_ApplicationHandle * 219struct GNUNET_TRANSPORT_ApplicationHandle *
228GNUNET_TRANSPORT_application_init (const struct GNUNET_CONFIGURATION_Handle *cfg) 220GNUNET_TRANSPORT_application_init (
221 const struct GNUNET_CONFIGURATION_Handle *cfg)
229{ 222{
230 struct GNUNET_TRANSPORT_ApplicationHandle *ch; 223 struct GNUNET_TRANSPORT_ApplicationHandle *ch;
231 224
232 ch = GNUNET_new (struct GNUNET_TRANSPORT_ApplicationHandle); 225 ch = GNUNET_new (struct GNUNET_TRANSPORT_ApplicationHandle);
233 ch->cfg = cfg; 226 ch->cfg = cfg;
234 ch->sug_requests = GNUNET_CONTAINER_multipeermap_create (32, 227 ch->sug_requests = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES);
235 GNUNET_YES);
236 reconnect (ch); 228 reconnect (ch);
237 return ch; 229 return ch;
238} 230}
@@ -248,9 +240,7 @@ GNUNET_TRANSPORT_application_init (const struct GNUNET_CONFIGURATION_Handle *cfg
248 * @return #GNUNET_OK (continue to iterate) 240 * @return #GNUNET_OK (continue to iterate)
249 */ 241 */
250static int 242static int
251free_sug_handle (void *cls, 243free_sug_handle (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
252 const struct GNUNET_PeerIdentity *key,
253 void *value)
254{ 244{
255 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *cur = value; 245 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *cur = value;
256 246
@@ -265,7 +255,8 @@ free_sug_handle (void *cls,
265 * @param ch handle to release 255 * @param ch handle to release
266 */ 256 */
267void 257void
268GNUNET_TRANSPORT_application_done (struct GNUNET_TRANSPORT_ApplicationHandle *ch) 258GNUNET_TRANSPORT_application_done (
259 struct GNUNET_TRANSPORT_ApplicationHandle *ch)
269{ 260{
270 if (NULL != ch->mq) 261 if (NULL != ch->mq)
271 { 262 {
@@ -299,10 +290,11 @@ GNUNET_TRANSPORT_application_done (struct GNUNET_TRANSPORT_ApplicationHandle *ch
299 * @return suggest handle, NULL if a request is already pending 290 * @return suggest handle, NULL if a request is already pending
300 */ 291 */
301struct GNUNET_TRANSPORT_ApplicationSuggestHandle * 292struct GNUNET_TRANSPORT_ApplicationSuggestHandle *
302GNUNET_TRANSPORT_application_suggest (struct GNUNET_TRANSPORT_ApplicationHandle *ch, 293GNUNET_TRANSPORT_application_suggest (
303 const struct GNUNET_PeerIdentity *peer, 294 struct GNUNET_TRANSPORT_ApplicationHandle *ch,
304 enum GNUNET_MQ_PreferenceKind pk, 295 const struct GNUNET_PeerIdentity *peer,
305 struct GNUNET_BANDWIDTH_Value32NBO bw) 296 enum GNUNET_MQ_PreferenceKind pk,
297 struct GNUNET_BANDWIDTH_Value32NBO bw)
306{ 298{
307 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *s; 299 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *s;
308 300
@@ -311,19 +303,17 @@ GNUNET_TRANSPORT_application_suggest (struct GNUNET_TRANSPORT_ApplicationHandle
311 s->id = *peer; 303 s->id = *peer;
312 s->pk = pk; 304 s->pk = pk;
313 s->bw = bw; 305 s->bw = bw;
314 (void) GNUNET_CONTAINER_multipeermap_put (ch->sug_requests, 306 (void) GNUNET_CONTAINER_multipeermap_put (
315 &s->id, 307 ch->sug_requests,
316 s, 308 &s->id,
317 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 309 s,
310 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
318 LOG (GNUNET_ERROR_TYPE_DEBUG, 311 LOG (GNUNET_ERROR_TYPE_DEBUG,
319 "Requesting TRANSPORT to suggest address for `%s'\n", 312 "Requesting TRANSPORT to suggest address for `%s'\n",
320 GNUNET_i2s (peer)); 313 GNUNET_i2s (peer));
321 if (NULL == ch->mq) 314 if (NULL == ch->mq)
322 return s; 315 return s;
323 GNUNET_assert (GNUNET_OK == 316 GNUNET_assert (GNUNET_OK == transmit_suggestion (ch, &s->id, s));
324 transmit_suggestion (ch,
325 &s->id,
326 s));
327 return s; 317 return s;
328} 318}
329 319
@@ -334,7 +324,8 @@ GNUNET_TRANSPORT_application_suggest (struct GNUNET_TRANSPORT_ApplicationHandle
334 * @param sh handle to stop 324 * @param sh handle to stop
335 */ 325 */
336void 326void
337GNUNET_TRANSPORT_application_suggest_cancel (struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh) 327GNUNET_TRANSPORT_application_suggest_cancel (
328 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh)
338{ 329{
339 struct GNUNET_TRANSPORT_ApplicationHandle *ch = sh->ch; 330 struct GNUNET_TRANSPORT_ApplicationHandle *ch = sh->ch;
340 struct GNUNET_MQ_Envelope *ev; 331 struct GNUNET_MQ_Envelope *ev;
@@ -343,27 +334,23 @@ GNUNET_TRANSPORT_application_suggest_cancel (struct GNUNET_TRANSPORT_Application
343 LOG (GNUNET_ERROR_TYPE_DEBUG, 334 LOG (GNUNET_ERROR_TYPE_DEBUG,
344 "Telling TRANSPORT we no longer care for an address for `%s'\n", 335 "Telling TRANSPORT we no longer care for an address for `%s'\n",
345 GNUNET_i2s (&sh->id)); 336 GNUNET_i2s (&sh->id));
346 GNUNET_assert (GNUNET_OK == 337 GNUNET_assert (
347 GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests, 338 GNUNET_OK ==
348 &sh->id, 339 GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests, &sh->id, sh));
349 sh));
350 if (NULL == ch->mq) 340 if (NULL == ch->mq)
351 { 341 {
352 GNUNET_free (sh); 342 GNUNET_free (sh);
353 return; 343 return;
354 } 344 }
355 ev = GNUNET_MQ_msg (m, 345 ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL);
356 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL);
357 m->pk = htonl ((uint32_t) sh->pk); 346 m->pk = htonl ((uint32_t) sh->pk);
358 m->bw = sh->bw; 347 m->bw = sh->bw;
359 m->peer = sh->id; 348 m->peer = sh->id;
360 GNUNET_MQ_send (ch->mq, 349 GNUNET_MQ_send (ch->mq, ev);
361 ev);
362 GNUNET_free (sh); 350 GNUNET_free (sh);
363} 351}
364 352
365 353
366
367/** 354/**
368 * An application (or a communicator) has received a HELLO (or other address 355 * An application (or a communicator) has received a HELLO (or other address
369 * data of another peer) and wants TRANSPORT to validate that the address is 356 * data of another peer) and wants TRANSPORT to validate that the address is
@@ -374,19 +361,17 @@ GNUNET_TRANSPORT_application_suggest_cancel (struct GNUNET_TRANSPORT_Application
374 * 361 *
375 * @param ch handle 362 * @param ch handle
376 * @param peer identity of the peer we have an address for 363 * @param peer identity of the peer we have an address for
377 * @param expiration when does @a addr expire; used by TRANSPORT to know when
378 * to definitively give up attempting to validate
379 * @param nt network type of @a addr (as claimed by the other peer); 364 * @param nt network type of @a addr (as claimed by the other peer);
380 * used by TRANSPORT to avoid trying @a addr's that really cannot work 365 * used by TRANSPORT to avoid trying @a addr's that really cannot work
381 * due to network type missmatches 366 * due to network type missmatches
382 * @param addr address to validate 367 * @param addr address to validate
383 */ 368 */
384void 369void
385GNUNET_TRANSPORT_application_validate (struct GNUNET_TRANSPORT_ApplicationHandle *ch, 370GNUNET_TRANSPORT_application_validate (
386 const struct GNUNET_PeerIdentity *peer, 371 struct GNUNET_TRANSPORT_ApplicationHandle *ch,
387 struct GNUNET_TIME_Absolute expiration, 372 const struct GNUNET_PeerIdentity *peer,
388 enum GNUNET_NetworkType nt, 373 enum GNUNET_NetworkType nt,
389 const char *addr) 374 const char *addr)
390{ 375{
391 struct GNUNET_MQ_Envelope *ev; 376 struct GNUNET_MQ_Envelope *ev;
392 struct RequestHelloValidationMessage *m; 377 struct RequestHelloValidationMessage *m;
@@ -394,24 +379,22 @@ GNUNET_TRANSPORT_application_validate (struct GNUNET_TRANSPORT_ApplicationHandle
394 379
395 if (NULL == ch->mq) 380 if (NULL == ch->mq)
396 { 381 {
397 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 382 GNUNET_log (
398 "Address validation for %s:%s skipped as transport is not connected\n", 383 GNUNET_ERROR_TYPE_WARNING,
399 GNUNET_i2s (peer), 384 "Address validation for %s:%s skipped as transport is not connected\n",
400 addr); 385 GNUNET_i2s (peer),
386 addr);
401 return; 387 return;
402 } 388 }
403 alen = strlen (addr) + 1; 389 alen = strlen (addr) + 1;
404 ev = GNUNET_MQ_msg_extra (m, 390 ev =
405 alen, 391 GNUNET_MQ_msg_extra (m,
406 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION); 392 alen,
393 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION);
407 m->peer = *peer; 394 m->peer = *peer;
408 m->expiration = GNUNET_TIME_absolute_hton (expiration);
409 m->nt = htonl ((uint32_t) nt); 395 m->nt = htonl ((uint32_t) nt);
410 memcpy (&m[1], 396 memcpy (&m[1], addr, alen);
411 addr, 397 GNUNET_MQ_send (ch->mq, ev);
412 alen);
413 GNUNET_MQ_send (ch->mq,
414 ev);
415} 398}
416 399
417 400