aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_unix.c')
-rw-r--r--src/transport/plugin_transport_unix.c1566
1 files changed, 787 insertions, 779 deletions
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c
index 5f7b38479..42d16f131 100644
--- a/src/transport/plugin_transport_unix.c
+++ b/src/transport/plugin_transport_unix.c
@@ -51,7 +51,8 @@
51/** 51/**
52 * Options for UNIX Domain addresses. 52 * Options for UNIX Domain addresses.
53 */ 53 */
54enum UNIX_ADDRESS_OPTIONS { 54enum UNIX_ADDRESS_OPTIONS
55{
55 /** 56 /**
56 * No special options. 57 * No special options.
57 */ 58 */
@@ -68,9 +69,9 @@ enum UNIX_ADDRESS_OPTIONS {
68 * How long until we give up on transmitting the welcome message? 69 * How long until we give up on transmitting the welcome message?
69 */ 70 */
70#define HOSTNAME_RESOLVE_TIMEOUT \ 71#define HOSTNAME_RESOLVE_TIMEOUT \
71 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) 72 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
72 73
73#define LOG(kind, ...) GNUNET_log_from(kind, "transport-unix", __VA_ARGS__) 74#define LOG(kind, ...) GNUNET_log_from (kind, "transport-unix", __VA_ARGS__)
74 75
75 76
76GNUNET_NETWORK_STRUCT_BEGIN 77GNUNET_NETWORK_STRUCT_BEGIN
@@ -78,7 +79,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
78/** 79/**
79 * Binary format for an UNIX Domain Socket address in GNUnet. 80 * Binary format for an UNIX Domain Socket address in GNUnet.
80 */ 81 */
81struct UnixAddress { 82struct UnixAddress
83{
82 /** 84 /**
83 * Options to use for the address, in NBO 85 * Options to use for the address, in NBO
84 */ 86 */
@@ -96,7 +98,8 @@ struct UnixAddress {
96/** 98/**
97 * UNIX Message-Packet header. 99 * UNIX Message-Packet header.
98 */ 100 */
99struct UNIXMessage { 101struct UNIXMessage
102{
100 /** 103 /**
101 * Message header. 104 * Message header.
102 */ 105 */
@@ -114,7 +117,8 @@ GNUNET_NETWORK_STRUCT_END
114/** 117/**
115 * Information we track for a message awaiting transmission. 118 * Information we track for a message awaiting transmission.
116 */ 119 */
117struct UNIXMessageWrapper { 120struct UNIXMessageWrapper
121{
118 /** 122 /**
119 * We keep messages in a doubly linked list. 123 * We keep messages in a doubly linked list.
120 */ 124 */
@@ -170,7 +174,8 @@ struct UNIXMessageWrapper {
170/** 174/**
171 * Handle for a session. 175 * Handle for a session.
172 */ 176 */
173struct GNUNET_ATS_Session { 177struct GNUNET_ATS_Session
178{
174 /** 179 /**
175 * Sessions with pending messages (!) are kept in a DLL. 180 * Sessions with pending messages (!) are kept in a DLL.
176 */ 181 */
@@ -230,7 +235,8 @@ struct Plugin;
230/** 235/**
231 * Information we keep for each of our listen sockets. 236 * Information we keep for each of our listen sockets.
232 */ 237 */
233struct UNIX_Sock_Info { 238struct UNIX_Sock_Info
239{
234 /** 240 /**
235 * The network handle 241 * The network handle
236 */ 242 */
@@ -241,7 +247,8 @@ struct UNIX_Sock_Info {
241/** 247/**
242 * Encapsulation of all of the state of the plugin. 248 * Encapsulation of all of the state of the plugin.
243 */ 249 */
244struct Plugin { 250struct Plugin
251{
245 /** 252 /**
246 * ID of task used to update our addresses when one expires. 253 * ID of task used to update our addresses when one expires.
247 */ 254 */
@@ -323,15 +330,15 @@ struct Plugin {
323 * @param state new state of the session 330 * @param state new state of the session
324 */ 331 */
325static void 332static void
326notify_session_monitor(struct Plugin *plugin, 333notify_session_monitor (struct Plugin *plugin,
327 struct GNUNET_ATS_Session *session, 334 struct GNUNET_ATS_Session *session,
328 enum GNUNET_TRANSPORT_SessionState state) 335 enum GNUNET_TRANSPORT_SessionState state)
329{ 336{
330 struct GNUNET_TRANSPORT_SessionInfo info; 337 struct GNUNET_TRANSPORT_SessionInfo info;
331 338
332 if (NULL == plugin->sic) 339 if (NULL == plugin->sic)
333 return; 340 return;
334 memset(&info, 0, sizeof(info)); 341 memset (&info, 0, sizeof(info));
335 info.state = state; 342 info.state = state;
336 info.is_inbound = GNUNET_SYSERR; /* hard to say */ 343 info.is_inbound = GNUNET_SYSERR; /* hard to say */
337 info.num_msg_pending = session->msgs_in_queue; 344 info.num_msg_pending = session->msgs_in_queue;
@@ -341,7 +348,7 @@ notify_session_monitor(struct Plugin *plugin,
341 to receive from others) */ 348 to receive from others) */
342 info.session_timeout = session->timeout; 349 info.session_timeout = session->timeout;
343 info.address = session->address; 350 info.address = session->address;
344 plugin->sic(plugin->sic_cls, session, &info); 351 plugin->sic (plugin->sic_cls, session, &info);
345} 352}
346 353
347 354
@@ -357,50 +364,50 @@ notify_session_monitor(struct Plugin *plugin,
357 * @return string representing the same address 364 * @return string representing the same address
358 */ 365 */
359static const char * 366static const char *
360unix_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) 367unix_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
361{ 368{
362 static char rbuf[1024]; 369 static char rbuf[1024];
363 struct UnixAddress *ua = (struct UnixAddress *)addr; 370 struct UnixAddress *ua = (struct UnixAddress *) addr;
364 char *addrstr; 371 char *addrstr;
365 size_t addr_str_len; 372 size_t addr_str_len;
366 unsigned int off; 373 unsigned int off;
367 374
368 if ((NULL == addr) || (sizeof(struct UnixAddress) > addrlen)) 375 if ((NULL == addr) || (sizeof(struct UnixAddress) > addrlen))
369 { 376 {
370 GNUNET_break(0); 377 GNUNET_break (0);
371 return NULL; 378 return NULL;
372 } 379 }
373 addrstr = (char *)&ua[1]; 380 addrstr = (char *) &ua[1];
374 addr_str_len = ntohl(ua->addrlen); 381 addr_str_len = ntohl (ua->addrlen);
375 382
376 if (addr_str_len != addrlen - sizeof(struct UnixAddress)) 383 if (addr_str_len != addrlen - sizeof(struct UnixAddress))
377 { 384 {
378 GNUNET_break(0); 385 GNUNET_break (0);
379 return NULL; 386 return NULL;
380 } 387 }
381 if ('\0' != addrstr[addr_str_len - 1]) 388 if ('\0' != addrstr[addr_str_len - 1])
382 { 389 {
383 GNUNET_break(0); 390 GNUNET_break (0);
384 return NULL; 391 return NULL;
385 } 392 }
386 if (strlen(addrstr) + 1 != addr_str_len) 393 if (strlen (addrstr) + 1 != addr_str_len)
387 { 394 {
388 GNUNET_break(0); 395 GNUNET_break (0);
389 return NULL; 396 return NULL;
390 } 397 }
391 398
392 off = 0; 399 off = 0;
393 if ('\0' == addrstr[0]) 400 if ('\0' == addrstr[0])
394 off++; 401 off++;
395 memset(rbuf, 0, sizeof(rbuf)); 402 memset (rbuf, 0, sizeof(rbuf));
396 GNUNET_snprintf(rbuf, 403 GNUNET_snprintf (rbuf,
397 sizeof(rbuf) - 1, 404 sizeof(rbuf) - 1,
398 "%s.%u.%s%.*s", 405 "%s.%u.%s%.*s",
399 PLUGIN_NAME, 406 PLUGIN_NAME,
400 ntohl(ua->options), 407 ntohl (ua->options),
401 (off == 1) ? "@" : "", 408 (off == 1) ? "@" : "",
402 (int)(addr_str_len - off), 409 (int) (addr_str_len - off),
403 &addrstr[off]); 410 &addrstr[off]);
404 return rbuf; 411 return rbuf;
405} 412}
406 413
@@ -415,61 +422,61 @@ unix_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
415 * @return #GNUNET_OK on success 422 * @return #GNUNET_OK on success
416 */ 423 */
417static int 424static int
418unix_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *session) 425unix_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *session)
419{ 426{
420 struct Plugin *plugin = cls; 427 struct Plugin *plugin = cls;
421 struct UNIXMessageWrapper *msgw; 428 struct UNIXMessageWrapper *msgw;
422 struct UNIXMessageWrapper *next; 429 struct UNIXMessageWrapper *next;
423 430
424 LOG(GNUNET_ERROR_TYPE_DEBUG, 431 LOG (GNUNET_ERROR_TYPE_DEBUG,
425 "Disconnecting session for peer `%s' `%s'\n", 432 "Disconnecting session for peer `%s' `%s'\n",
426 GNUNET_i2s(&session->target), 433 GNUNET_i2s (&session->target),
427 unix_plugin_address_to_string(NULL, 434 unix_plugin_address_to_string (NULL,
428 session->address->address, 435 session->address->address,
429 session->address->address_length)); 436 session->address->address_length));
430 plugin->env->session_end(plugin->env->cls, session->address, session); 437 plugin->env->session_end (plugin->env->cls, session->address, session);
431 next = plugin->msg_head; 438 next = plugin->msg_head;
432 while (NULL != next) 439 while (NULL != next)
433 { 440 {
434 msgw = next; 441 msgw = next;
435 next = msgw->next; 442 next = msgw->next;
436 if (msgw->session != session) 443 if (msgw->session != session)
437 continue; 444 continue;
438 GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); 445 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
439 session->msgs_in_queue--; 446 session->msgs_in_queue--;
440 GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); 447 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
441 session->bytes_in_queue -= msgw->msgsize; 448 session->bytes_in_queue -= msgw->msgsize;
442 GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); 449 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
443 plugin->bytes_in_queue -= msgw->msgsize; 450 plugin->bytes_in_queue -= msgw->msgsize;
444 if (NULL != msgw->cont) 451 if (NULL != msgw->cont)
445 msgw->cont(msgw->cont_cls, 452 msgw->cont (msgw->cont_cls,
446 &msgw->session->target, 453 &msgw->session->target,
447 GNUNET_SYSERR, 454 GNUNET_SYSERR,
448 msgw->payload, 455 msgw->payload,
449 0); 456 0);
450 GNUNET_free(msgw->msg); 457 GNUNET_free (msgw->msg);
451 GNUNET_free(msgw); 458 GNUNET_free (msgw);
452 } 459 }
453 GNUNET_assert(GNUNET_YES == 460 GNUNET_assert (GNUNET_YES ==
454 GNUNET_CONTAINER_multipeermap_remove(plugin->session_map, 461 GNUNET_CONTAINER_multipeermap_remove (plugin->session_map,
455 &session->target, 462 &session->target,
456 session)); 463 session));
457 GNUNET_STATISTICS_set(plugin->env->stats, 464 GNUNET_STATISTICS_set (plugin->env->stats,
458 "# UNIX sessions active", 465 "# UNIX sessions active",
459 GNUNET_CONTAINER_multipeermap_size( 466 GNUNET_CONTAINER_multipeermap_size (
460 plugin->session_map), 467 plugin->session_map),
461 GNUNET_NO); 468 GNUNET_NO);
462 if (NULL != session->timeout_task) 469 if (NULL != session->timeout_task)
463 { 470 {
464 GNUNET_SCHEDULER_cancel(session->timeout_task); 471 GNUNET_SCHEDULER_cancel (session->timeout_task);
465 session->timeout_task = NULL; 472 session->timeout_task = NULL;
466 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; 473 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
467 } 474 }
468 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_DONE); 475 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_DONE);
469 GNUNET_HELLO_address_free(session->address); 476 GNUNET_HELLO_address_free (session->address);
470 GNUNET_break(0 == session->bytes_in_queue); 477 GNUNET_break (0 == session->bytes_in_queue);
471 GNUNET_break(0 == session->msgs_in_queue); 478 GNUNET_break (0 == session->msgs_in_queue);
472 GNUNET_free(session); 479 GNUNET_free (session);
473 return GNUNET_OK; 480 return GNUNET_OK;
474} 481}
475 482
@@ -480,31 +487,31 @@ unix_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *session)
480 * @param cls the `struct GNUNET_ATS_Session *` to disconnect 487 * @param cls the `struct GNUNET_ATS_Session *` to disconnect
481 */ 488 */
482static void 489static void
483session_timeout(void *cls) 490session_timeout (void *cls)
484{ 491{
485 struct GNUNET_ATS_Session *session = cls; 492 struct GNUNET_ATS_Session *session = cls;
486 struct GNUNET_TIME_Relative left; 493 struct GNUNET_TIME_Relative left;
487 494
488 session->timeout_task = NULL; 495 session->timeout_task = NULL;
489 left = GNUNET_TIME_absolute_get_remaining(session->timeout); 496 left = GNUNET_TIME_absolute_get_remaining (session->timeout);
490 if (0 != left.rel_value_us) 497 if (0 != left.rel_value_us)
491 { 498 {
492 /* not actually our turn yet, but let's at least update 499 /* not actually our turn yet, but let's at least update
493 the monitor, it may think we're about to die ... */ 500 the monitor, it may think we're about to die ... */
494 notify_session_monitor(session->plugin, 501 notify_session_monitor (session->plugin,
495 session, 502 session,
496 GNUNET_TRANSPORT_SS_UPDATE); 503 GNUNET_TRANSPORT_SS_UPDATE);
497 session->timeout_task = 504 session->timeout_task =
498 GNUNET_SCHEDULER_add_delayed(left, &session_timeout, session); 505 GNUNET_SCHEDULER_add_delayed (left, &session_timeout, session);
499 return; 506 return;
500 } 507 }
501 LOG(GNUNET_ERROR_TYPE_DEBUG, 508 LOG (GNUNET_ERROR_TYPE_DEBUG,
502 "Session %p was idle for %s, disconnecting\n", 509 "Session %p was idle for %s, disconnecting\n",
503 session, 510 session,
504 GNUNET_STRINGS_relative_time_to_string( 511 GNUNET_STRINGS_relative_time_to_string (
505 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 512 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
506 GNUNET_YES)); 513 GNUNET_YES));
507 unix_plugin_session_disconnect(session->plugin, session); 514 unix_plugin_session_disconnect (session->plugin, session);
508} 515}
509 516
510 517
@@ -516,11 +523,11 @@ session_timeout(void *cls)
516 * @param session session for which the timeout should be rescheduled 523 * @param session session for which the timeout should be rescheduled
517 */ 524 */
518static void 525static void
519reschedule_session_timeout(struct GNUNET_ATS_Session *session) 526reschedule_session_timeout (struct GNUNET_ATS_Session *session)
520{ 527{
521 GNUNET_assert(NULL != session->timeout_task); 528 GNUNET_assert (NULL != session->timeout_task);
522 session->timeout = 529 session->timeout =
523 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 530 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
524} 531}
525 532
526 533
@@ -532,22 +539,22 @@ reschedule_session_timeout(struct GNUNET_ATS_Session *session)
532 * @return converted unix path 539 * @return converted unix path
533 */ 540 */
534static struct sockaddr_un * 541static struct sockaddr_un *
535unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len) 542unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len)
536{ 543{
537 struct sockaddr_un *un; 544 struct sockaddr_un *un;
538 size_t slen; 545 size_t slen;
539 546
540 GNUNET_assert(0 < strlen(unixpath)); /* sanity check */ 547 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
541 un = GNUNET_new(struct sockaddr_un); 548 un = GNUNET_new (struct sockaddr_un);
542 un->sun_family = AF_UNIX; 549 un->sun_family = AF_UNIX;
543 slen = strlen(unixpath); 550 slen = strlen (unixpath);
544 if (slen >= sizeof(un->sun_path)) 551 if (slen >= sizeof(un->sun_path))
545 slen = sizeof(un->sun_path) - 1; 552 slen = sizeof(un->sun_path) - 1;
546 GNUNET_memcpy(un->sun_path, unixpath, slen); 553 GNUNET_memcpy (un->sun_path, unixpath, slen);
547 un->sun_path[slen] = '\0'; 554 un->sun_path[slen] = '\0';
548 slen = sizeof(struct sockaddr_un); 555 slen = sizeof(struct sockaddr_un);
549#if HAVE_SOCKADDR_UN_SUN_LEN 556#if HAVE_SOCKADDR_UN_SUN_LEN
550 un->sun_len = (u_char)slen; 557 un->sun_len = (u_char) slen;
551#endif 558#endif
552 (*sock_len) = slen; 559 (*sock_len) = slen;
553 return un; 560 return un;
@@ -557,7 +564,8 @@ unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len)
557/** 564/**
558 * Closure to #lookup_session_it(). 565 * Closure to #lookup_session_it().
559 */ 566 */
560struct LookupCtx { 567struct LookupCtx
568{
561 /** 569 /**
562 * Location to store the session, if found. 570 * Location to store the session, if found.
563 */ 571 */
@@ -579,18 +587,18 @@ struct LookupCtx {
579 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success 587 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success
580 */ 588 */
581static int 589static int
582lookup_session_it(void *cls, 590lookup_session_it (void *cls,
583 const struct GNUNET_PeerIdentity *key, 591 const struct GNUNET_PeerIdentity *key,
584 void *value) 592 void *value)
585{ 593{
586 struct LookupCtx *lctx = cls; 594 struct LookupCtx *lctx = cls;
587 struct GNUNET_ATS_Session *session = value; 595 struct GNUNET_ATS_Session *session = value;
588 596
589 if (0 == GNUNET_HELLO_address_cmp(lctx->address, session->address)) 597 if (0 == GNUNET_HELLO_address_cmp (lctx->address, session->address))
590 { 598 {
591 lctx->res = session; 599 lctx->res = session;
592 return GNUNET_NO; 600 return GNUNET_NO;
593 } 601 }
594 return GNUNET_YES; 602 return GNUNET_YES;
595} 603}
596 604
@@ -603,17 +611,17 @@ lookup_session_it(void *cls,
603 * @return NULL if session was not found 611 * @return NULL if session was not found
604 */ 612 */
605static struct GNUNET_ATS_Session * 613static struct GNUNET_ATS_Session *
606lookup_session(struct Plugin *plugin, 614lookup_session (struct Plugin *plugin,
607 const struct GNUNET_HELLO_Address *address) 615 const struct GNUNET_HELLO_Address *address)
608{ 616{
609 struct LookupCtx lctx; 617 struct LookupCtx lctx;
610 618
611 lctx.address = address; 619 lctx.address = address;
612 lctx.res = NULL; 620 lctx.res = NULL;
613 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->session_map, 621 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
614 &address->peer, 622 &address->peer,
615 &lookup_session_it, 623 &lookup_session_it,
616 &lctx); 624 &lctx);
617 return lctx.res; 625 return lctx.res;
618} 626}
619 627
@@ -627,7 +635,7 @@ lookup_session(struct Plugin *plugin,
627 * @return keepalive factor 635 * @return keepalive factor
628 */ 636 */
629static unsigned int 637static unsigned int
630unix_plugin_query_keepalive_factor(void *cls) 638unix_plugin_query_keepalive_factor (void *cls)
631{ 639{
632 return 3; 640 return 3;
633} 641}
@@ -655,18 +663,18 @@ unix_plugin_query_keepalive_factor(void *cls)
655 * @return on success the number of bytes written, RETRY for retry, -1 on errors 663 * @return on success the number of bytes written, RETRY for retry, -1 on errors
656 */ 664 */
657static ssize_t 665static ssize_t
658unix_real_send(void *cls, 666unix_real_send (void *cls,
659 struct GNUNET_NETWORK_Handle *send_handle, 667 struct GNUNET_NETWORK_Handle *send_handle,
660 const struct GNUNET_PeerIdentity *target, 668 const struct GNUNET_PeerIdentity *target,
661 const char *msgbuf, 669 const char *msgbuf,
662 size_t msgbuf_size, 670 size_t msgbuf_size,
663 unsigned int priority, 671 unsigned int priority,
664 struct GNUNET_TIME_Absolute timeout, 672 struct GNUNET_TIME_Absolute timeout,
665 const struct UnixAddress *addr, 673 const struct UnixAddress *addr,
666 size_t addrlen, 674 size_t addrlen,
667 size_t payload, 675 size_t payload,
668 GNUNET_TRANSPORT_TransmitContinuation cont, 676 GNUNET_TRANSPORT_TransmitContinuation cont,
669 void *cont_cls) 677 void *cont_cls)
670{ 678{
671 struct Plugin *plugin = cls; 679 struct Plugin *plugin = cls;
672 ssize_t sent; 680 ssize_t sent;
@@ -675,96 +683,96 @@ unix_real_send(void *cls,
675 const char *unixpath; 683 const char *unixpath;
676 684
677 if (NULL == send_handle) 685 if (NULL == send_handle)
678 { 686 {
679 GNUNET_break(0); /* We do not have a send handle */ 687 GNUNET_break (0); /* We do not have a send handle */
680 return GNUNET_SYSERR; 688 return GNUNET_SYSERR;
681 } 689 }
682 if ((NULL == addr) || (0 == addrlen)) 690 if ((NULL == addr) || (0 == addrlen))
683 { 691 {
684 GNUNET_break(0); /* Can never send if we don't have an address */ 692 GNUNET_break (0); /* Can never send if we don't have an address */
685 return GNUNET_SYSERR; 693 return GNUNET_SYSERR;
686 } 694 }
687 695
688 /* Prepare address */ 696 /* Prepare address */
689 unixpath = (const char *)&addr[1]; 697 unixpath = (const char *) &addr[1];
690 if (NULL == (un = unix_address_to_sockaddr(unixpath, &un_len))) 698 if (NULL == (un = unix_address_to_sockaddr (unixpath, &un_len)))
691 { 699 {
692 GNUNET_break(0); 700 GNUNET_break (0);
693 return -1; 701 return -1;
694 } 702 }
695 703
696 if ((GNUNET_YES == plugin->is_abstract) && 704 if ((GNUNET_YES == plugin->is_abstract) &&
697 (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl(addr->options)))) 705 (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl (addr->options))))
698 { 706 {
699 un->sun_path[0] = '\0'; 707 un->sun_path[0] = '\0';
700 } 708 }
701resend: 709resend:
702 /* Send the data */ 710 /* Send the data */
703 sent = GNUNET_NETWORK_socket_sendto(send_handle, 711 sent = GNUNET_NETWORK_socket_sendto (send_handle,
704 msgbuf, 712 msgbuf,
705 msgbuf_size, 713 msgbuf_size,
706 (const struct sockaddr *)un, 714 (const struct sockaddr *) un,
707 un_len); 715 un_len);
708 if (GNUNET_SYSERR == sent) 716 if (GNUNET_SYSERR == sent)
717 {
718 if ((EAGAIN == errno) || (ENOBUFS == errno))
709 { 719 {
710 if ((EAGAIN == errno) || (ENOBUFS == errno)) 720 GNUNET_free (un);
711 { 721 return RETRY; /* We have to retry later */
712 GNUNET_free(un); 722 }
713 return RETRY; /* We have to retry later */ 723 if (EMSGSIZE == errno)
714 } 724 {
715 if (EMSGSIZE == errno) 725 socklen_t size = 0;
726 socklen_t len = sizeof(size);
727
728 GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *)
729 send_handle,
730 SOL_SOCKET,
731 SO_SNDBUF,
732 &size,
733 &len);
734 if (size < msgbuf_size)
735 {
736 LOG (GNUNET_ERROR_TYPE_DEBUG,
737 "Trying to increase socket buffer size from %u to %u for message size %u\n",
738 (unsigned int) size,
739 (unsigned int) ((msgbuf_size / 1000) + 2) * 1000,
740 (unsigned int) msgbuf_size);
741 size = ((msgbuf_size / 1000) + 2) * 1000;
742 if (GNUNET_OK ==
743 GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *)
744 send_handle,
745 SOL_SOCKET,
746 SO_SNDBUF,
747 &size,
748 sizeof(size)))
749 goto resend; /* Increased buffer size, retry sending */
750 else
716 { 751 {
717 socklen_t size = 0; 752 /* Could not increase buffer size: error, no retry */
718 socklen_t len = sizeof(size); 753 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
719 754 GNUNET_free (un);
720 GNUNET_NETWORK_socket_getsockopt((struct GNUNET_NETWORK_Handle *) 755 return GNUNET_SYSERR;
721 send_handle,
722 SOL_SOCKET,
723 SO_SNDBUF,
724 &size,
725 &len);
726 if (size < msgbuf_size)
727 {
728 LOG(GNUNET_ERROR_TYPE_DEBUG,
729 "Trying to increase socket buffer size from %u to %u for message size %u\n",
730 (unsigned int)size,
731 (unsigned int)((msgbuf_size / 1000) + 2) * 1000,
732 (unsigned int)msgbuf_size);
733 size = ((msgbuf_size / 1000) + 2) * 1000;
734 if (GNUNET_OK ==
735 GNUNET_NETWORK_socket_setsockopt((struct GNUNET_NETWORK_Handle *)
736 send_handle,
737 SOL_SOCKET,
738 SO_SNDBUF,
739 &size,
740 sizeof(size)))
741 goto resend; /* Increased buffer size, retry sending */
742 else
743 {
744 /* Could not increase buffer size: error, no retry */
745 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "setsockopt");
746 GNUNET_free(un);
747 return GNUNET_SYSERR;
748 }
749 }
750 else
751 {
752 /* Buffer is bigger than message: error, no retry
753 * This should never happen!*/
754 GNUNET_break(0);
755 GNUNET_free(un);
756 return GNUNET_SYSERR;
757 }
758 } 756 }
757 }
758 else
759 {
760 /* Buffer is bigger than message: error, no retry
761 * This should never happen!*/
762 GNUNET_break (0);
763 GNUNET_free (un);
764 return GNUNET_SYSERR;
765 }
759 } 766 }
760 767 }
761 LOG(GNUNET_ERROR_TYPE_DEBUG, 768
762 "UNIX transmitted %u-byte message to %s (%d: %s)\n", 769 LOG (GNUNET_ERROR_TYPE_DEBUG,
763 (unsigned int)msgbuf_size, 770 "UNIX transmitted %u-byte message to %s (%d: %s)\n",
764 GNUNET_a2s((const struct sockaddr *)un, un_len), 771 (unsigned int) msgbuf_size,
765 (int)sent, 772 GNUNET_a2s ((const struct sockaddr *) un, un_len),
766 (sent < 0) ? strerror(errno) : "ok"); 773 (int) sent,
767 GNUNET_free(un); 774 (sent < 0) ? strerror (errno) : "ok");
775 GNUNET_free (un);
768 return sent; 776 return sent;
769} 777}
770 778
@@ -777,9 +785,9 @@ resend:
777 * @return the network type in HBO or #GNUNET_SYSERR 785 * @return the network type in HBO or #GNUNET_SYSERR
778 */ 786 */
779static enum GNUNET_NetworkType 787static enum GNUNET_NetworkType
780unix_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session) 788unix_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
781{ 789{
782 GNUNET_assert(NULL != session); 790 GNUNET_assert (NULL != session);
783 return GNUNET_NT_LOOPBACK; 791 return GNUNET_NT_LOOPBACK;
784} 792}
785 793
@@ -792,8 +800,8 @@ unix_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session)
792 * @return the network type 800 * @return the network type
793 */ 801 */
794static enum GNUNET_NetworkType 802static enum GNUNET_NetworkType
795unix_plugin_get_network_for_address(void *cls, 803unix_plugin_get_network_for_address (void *cls,
796 const struct GNUNET_HELLO_Address *address) 804 const struct GNUNET_HELLO_Address *address)
797{ 805{
798 return GNUNET_NT_LOOPBACK; 806 return GNUNET_NT_LOOPBACK;
799} 807}
@@ -808,7 +816,7 @@ unix_plugin_get_network_for_address(void *cls,
808 * @return the session or NULL of max connections exceeded 816 * @return the session or NULL of max connections exceeded
809 */ 817 */
810static struct GNUNET_ATS_Session * 818static struct GNUNET_ATS_Session *
811unix_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) 819unix_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
812{ 820{
813 struct Plugin *plugin = cls; 821 struct Plugin *plugin = cls;
814 struct GNUNET_ATS_Session *session; 822 struct GNUNET_ATS_Session *session;
@@ -817,80 +825,80 @@ unix_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
817 uint32_t addr_str_len; 825 uint32_t addr_str_len;
818 uint32_t addr_option; 826 uint32_t addr_option;
819 827
820 ua = (struct UnixAddress *)address->address; 828 ua = (struct UnixAddress *) address->address;
821 if ((NULL == address->address) || (0 == address->address_length) || 829 if ((NULL == address->address) || (0 == address->address_length) ||
822 (sizeof(struct UnixAddress) > address->address_length)) 830 (sizeof(struct UnixAddress) > address->address_length))
823 { 831 {
824 GNUNET_break(0); 832 GNUNET_break (0);
825 return NULL; 833 return NULL;
826 } 834 }
827 addrstr = (char *)&ua[1]; 835 addrstr = (char *) &ua[1];
828 addr_str_len = ntohl(ua->addrlen); 836 addr_str_len = ntohl (ua->addrlen);
829 addr_option = ntohl(ua->options); 837 addr_option = ntohl (ua->options);
830 838
831 if ((0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) && 839 if ((0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) &&
832 (GNUNET_NO == plugin->is_abstract)) 840 (GNUNET_NO == plugin->is_abstract))
833 { 841 {
834 return NULL; 842 return NULL;
835 } 843 }
836 844
837 if (addr_str_len != address->address_length - sizeof(struct UnixAddress)) 845 if (addr_str_len != address->address_length - sizeof(struct UnixAddress))
838 { 846 {
839 return NULL; /* This can be a legacy address */ 847 return NULL; /* This can be a legacy address */
840 } 848 }
841 849
842 if ('\0' != addrstr[addr_str_len - 1]) 850 if ('\0' != addrstr[addr_str_len - 1])
843 { 851 {
844 GNUNET_break(0); 852 GNUNET_break (0);
845 return NULL; 853 return NULL;
846 } 854 }
847 if (strlen(addrstr) + 1 != addr_str_len) 855 if (strlen (addrstr) + 1 != addr_str_len)
848 { 856 {
849 GNUNET_break(0); 857 GNUNET_break (0);
850 return NULL; 858 return NULL;
851 } 859 }
852 860
853 /* Check if a session for this address already exists */ 861 /* Check if a session for this address already exists */
854 if (NULL != (session = lookup_session(plugin, address))) 862 if (NULL != (session = lookup_session (plugin, address)))
855 { 863 {
856 LOG(GNUNET_ERROR_TYPE_DEBUG, 864 LOG (GNUNET_ERROR_TYPE_DEBUG,
857 "Found existing session %p for address `%s'\n", 865 "Found existing session %p for address `%s'\n",
858 session, 866 session,
859 unix_plugin_address_to_string(NULL, 867 unix_plugin_address_to_string (NULL,
860 address->address, 868 address->address,
861 address->address_length)); 869 address->address_length));
862 return session; 870 return session;
863 } 871 }
864 872
865 /* create a new session */ 873 /* create a new session */
866 session = GNUNET_new(struct GNUNET_ATS_Session); 874 session = GNUNET_new (struct GNUNET_ATS_Session);
867 session->target = address->peer; 875 session->target = address->peer;
868 session->address = GNUNET_HELLO_address_copy(address); 876 session->address = GNUNET_HELLO_address_copy (address);
869 session->plugin = plugin; 877 session->plugin = plugin;
870 session->timeout = 878 session->timeout =
871 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 879 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
872 session->timeout_task = 880 session->timeout_task =
873 GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 881 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
874 &session_timeout, 882 &session_timeout,
875 session); 883 session);
876 LOG(GNUNET_ERROR_TYPE_DEBUG, 884 LOG (GNUNET_ERROR_TYPE_DEBUG,
877 "Creating a new session %p for address `%s'\n", 885 "Creating a new session %p for address `%s'\n",
878 session, 886 session,
879 unix_plugin_address_to_string(NULL, 887 unix_plugin_address_to_string (NULL,
880 address->address, 888 address->address,
881 address->address_length)); 889 address->address_length));
882 (void)GNUNET_CONTAINER_multipeermap_put( 890 (void) GNUNET_CONTAINER_multipeermap_put (
883 plugin->session_map, 891 plugin->session_map,
884 &address->peer, 892 &address->peer,
885 session, 893 session,
886 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 894 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
887 GNUNET_STATISTICS_set(plugin->env->stats, 895 GNUNET_STATISTICS_set (plugin->env->stats,
888 "# UNIX sessions active", 896 "# UNIX sessions active",
889 GNUNET_CONTAINER_multipeermap_size( 897 GNUNET_CONTAINER_multipeermap_size (
890 plugin->session_map), 898 plugin->session_map),
891 GNUNET_NO); 899 GNUNET_NO);
892 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT); 900 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT);
893 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP); 901 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP);
894 return session; 902 return session;
895} 903}
896 904
@@ -905,21 +913,21 @@ unix_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
905 * @param session which session is being updated 913 * @param session which session is being updated
906 */ 914 */
907static void 915static void
908unix_plugin_update_session_timeout(void *cls, 916unix_plugin_update_session_timeout (void *cls,
909 const struct GNUNET_PeerIdentity *peer, 917 const struct GNUNET_PeerIdentity *peer,
910 struct GNUNET_ATS_Session *session) 918 struct GNUNET_ATS_Session *session)
911{ 919{
912 struct Plugin *plugin = cls; 920 struct Plugin *plugin = cls;
913 921
914 if (GNUNET_OK != 922 if (GNUNET_OK !=
915 GNUNET_CONTAINER_multipeermap_contains_value(plugin->session_map, 923 GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map,
916 &session->target, 924 &session->target,
917 session)) 925 session))
918 { 926 {
919 GNUNET_break(0); 927 GNUNET_break (0);
920 return; 928 return;
921 } 929 }
922 reschedule_session_timeout(session); 930 reschedule_session_timeout (session);
923} 931}
924 932
925 933
@@ -933,47 +941,47 @@ unix_plugin_update_session_timeout(void *cls,
933 * @param ua_len length of the address @a ua 941 * @param ua_len length of the address @a ua
934 */ 942 */
935static void 943static void
936unix_demultiplexer(struct Plugin *plugin, 944unix_demultiplexer (struct Plugin *plugin,
937 struct GNUNET_PeerIdentity *sender, 945 struct GNUNET_PeerIdentity *sender,
938 const struct GNUNET_MessageHeader *currhdr, 946 const struct GNUNET_MessageHeader *currhdr,
939 const struct UnixAddress *ua, 947 const struct UnixAddress *ua,
940 size_t ua_len) 948 size_t ua_len)
941{ 949{
942 struct GNUNET_ATS_Session *session; 950 struct GNUNET_ATS_Session *session;
943 struct GNUNET_HELLO_Address *address; 951 struct GNUNET_HELLO_Address *address;
944 952
945 GNUNET_assert(ua_len >= sizeof(struct UnixAddress)); 953 GNUNET_assert (ua_len >= sizeof(struct UnixAddress));
946 LOG(GNUNET_ERROR_TYPE_DEBUG, 954 LOG (GNUNET_ERROR_TYPE_DEBUG,
947 "Received message from %s\n", 955 "Received message from %s\n",
948 unix_plugin_address_to_string(NULL, ua, ua_len)); 956 unix_plugin_address_to_string (NULL, ua, ua_len));
949 GNUNET_STATISTICS_update(plugin->env->stats, 957 GNUNET_STATISTICS_update (plugin->env->stats,
950 "# bytes received via UNIX", 958 "# bytes received via UNIX",
951 ntohs(currhdr->size), 959 ntohs (currhdr->size),
952 GNUNET_NO); 960 GNUNET_NO);
953 961
954 /* Look for existing session */ 962 /* Look for existing session */
955 address = GNUNET_HELLO_address_allocate( 963 address = GNUNET_HELLO_address_allocate (
956 sender, 964 sender,
957 PLUGIN_NAME, 965 PLUGIN_NAME,
958 ua, 966 ua,
959 ua_len, 967 ua_len,
960 GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */ 968 GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */
961 session = lookup_session(plugin, address); 969 session = lookup_session (plugin, address);
962 if (NULL == session) 970 if (NULL == session)
963 { 971 {
964 session = unix_plugin_get_session(plugin, address); 972 session = unix_plugin_get_session (plugin, address);
965 /* Notify transport and ATS about new inbound session */ 973 /* Notify transport and ATS about new inbound session */
966 plugin->env->session_start(NULL, 974 plugin->env->session_start (NULL,
967 session->address, 975 session->address,
968 session, 976 session,
969 GNUNET_NT_LOOPBACK); 977 GNUNET_NT_LOOPBACK);
970 } 978 }
971 else 979 else
972 { 980 {
973 reschedule_session_timeout(session); 981 reschedule_session_timeout (session);
974 } 982 }
975 GNUNET_HELLO_address_free(address); 983 GNUNET_HELLO_address_free (address);
976 plugin->env->receive(plugin->env->cls, session->address, session, currhdr); 984 plugin->env->receive (plugin->env->cls, session->address, session, currhdr);
977} 985}
978 986
979 987
@@ -983,7 +991,7 @@ unix_demultiplexer(struct Plugin *plugin,
983 * @param plugin the plugin 991 * @param plugin the plugin
984 */ 992 */
985static void 993static void
986unix_plugin_do_read(struct Plugin *plugin) 994unix_plugin_do_read (struct Plugin *plugin)
987{ 995{
988 char buf[65536] GNUNET_ALIGN; 996 char buf[65536] GNUNET_ALIGN;
989 struct UnixAddress *ua; 997 struct UnixAddress *ua;
@@ -1001,70 +1009,70 @@ unix_plugin_do_read(struct Plugin *plugin)
1001 size_t ua_len; 1009 size_t ua_len;
1002 1010
1003 addrlen = sizeof(un); 1011 addrlen = sizeof(un);
1004 memset(&un, 0, sizeof(un)); 1012 memset (&un, 0, sizeof(un));
1005 ret = GNUNET_NETWORK_socket_recvfrom(plugin->unix_sock.desc, 1013 ret = GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc,
1006 buf, 1014 buf,
1007 sizeof(buf), 1015 sizeof(buf),
1008 (struct sockaddr *)&un, 1016 (struct sockaddr *) &un,
1009 &addrlen); 1017 &addrlen);
1010 if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS))) 1018 if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS)))
1011 return; 1019 return;
1012 if (GNUNET_SYSERR == ret) 1020 if (GNUNET_SYSERR == ret)
1013 { 1021 {
1014 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "recvfrom"); 1022 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom");
1015 return; 1023 return;
1016 } 1024 }
1017 else 1025 else
1018 { 1026 {
1019 LOG(GNUNET_ERROR_TYPE_DEBUG, 1027 LOG (GNUNET_ERROR_TYPE_DEBUG,
1020 "Read %d bytes from socket %s\n", 1028 "Read %d bytes from socket %s\n",
1021 (int)ret, 1029 (int) ret,
1022 un.sun_path); 1030 un.sun_path);
1023 } 1031 }
1024 1032
1025 GNUNET_assert(AF_UNIX == (un.sun_family)); 1033 GNUNET_assert (AF_UNIX == (un.sun_family));
1026 is_abstract = GNUNET_NO; 1034 is_abstract = GNUNET_NO;
1027 if ('\0' == un.sun_path[0]) 1035 if ('\0' == un.sun_path[0])
1028 { 1036 {
1029 un.sun_path[0] = '@'; 1037 un.sun_path[0] = '@';
1030 is_abstract = GNUNET_YES; 1038 is_abstract = GNUNET_YES;
1031 } 1039 }
1032 1040
1033 ua_len = sizeof(struct UnixAddress) + strlen(un.sun_path) + 1; 1041 ua_len = sizeof(struct UnixAddress) + strlen (un.sun_path) + 1;
1034 ua = GNUNET_malloc(ua_len); 1042 ua = GNUNET_malloc (ua_len);
1035 ua->addrlen = htonl(strlen(&un.sun_path[0]) + 1); 1043 ua->addrlen = htonl (strlen (&un.sun_path[0]) + 1);
1036 GNUNET_memcpy(&ua[1], &un.sun_path[0], strlen(un.sun_path) + 1); 1044 GNUNET_memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1);
1037 if (is_abstract) 1045 if (is_abstract)
1038 ua->options = htonl(UNIX_OPTIONS_USE_ABSTRACT_SOCKETS); 1046 ua->options = htonl (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS);
1039 else 1047 else
1040 ua->options = htonl(UNIX_OPTIONS_NONE); 1048 ua->options = htonl (UNIX_OPTIONS_NONE);
1041 1049
1042 msg = (struct UNIXMessage *)buf; 1050 msg = (struct UNIXMessage *) buf;
1043 csize = ntohs(msg->header.size); 1051 csize = ntohs (msg->header.size);
1044 if ((csize < sizeof(struct UNIXMessage)) || (csize > ret)) 1052 if ((csize < sizeof(struct UNIXMessage)) || (csize > ret))
1045 { 1053 {
1046 GNUNET_break_op(0); 1054 GNUNET_break_op (0);
1047 GNUNET_free(ua); 1055 GNUNET_free (ua);
1048 return; 1056 return;
1049 } 1057 }
1050 msgbuf = (char *)&msg[1]; 1058 msgbuf = (char *) &msg[1];
1051 GNUNET_memcpy(&sender, &msg->sender, sizeof(struct GNUNET_PeerIdentity)); 1059 GNUNET_memcpy (&sender, &msg->sender, sizeof(struct GNUNET_PeerIdentity));
1052 offset = 0; 1060 offset = 0;
1053 tsize = csize - sizeof(struct UNIXMessage); 1061 tsize = csize - sizeof(struct UNIXMessage);
1054 while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize) 1062 while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize)
1063 {
1064 currhdr = (struct GNUNET_MessageHeader *) &msgbuf[offset];
1065 csize = ntohs (currhdr->size);
1066 if ((csize < sizeof(struct GNUNET_MessageHeader)) ||
1067 (csize > tsize - offset))
1055 { 1068 {
1056 currhdr = (struct GNUNET_MessageHeader *)&msgbuf[offset]; 1069 GNUNET_break_op (0);
1057 csize = ntohs(currhdr->size); 1070 break;
1058 if ((csize < sizeof(struct GNUNET_MessageHeader)) ||
1059 (csize > tsize - offset))
1060 {
1061 GNUNET_break_op(0);
1062 break;
1063 }
1064 unix_demultiplexer(plugin, &sender, currhdr, ua, ua_len);
1065 offset += csize;
1066 } 1071 }
1067 GNUNET_free(ua); 1072 unix_demultiplexer (plugin, &sender, currhdr, ua, ua_len);
1073 offset += csize;
1074 }
1075 GNUNET_free (ua);
1068} 1076}
1069 1077
1070 1078
@@ -1074,7 +1082,7 @@ unix_plugin_do_read(struct Plugin *plugin)
1074 * @param plugin handle to the plugin 1082 * @param plugin handle to the plugin
1075 */ 1083 */
1076static void 1084static void
1077unix_plugin_do_write(struct Plugin *plugin) 1085unix_plugin_do_write (struct Plugin *plugin)
1078{ 1086{
1079 ssize_t sent = 0; 1087 ssize_t sent = 0;
1080 struct UNIXMessageWrapper *msgw; 1088 struct UNIXMessageWrapper *msgw;
@@ -1084,108 +1092,108 @@ unix_plugin_do_write(struct Plugin *plugin)
1084 session = NULL; 1092 session = NULL;
1085 did_delete = GNUNET_NO; 1093 did_delete = GNUNET_NO;
1086 while (NULL != (msgw = plugin->msg_head)) 1094 while (NULL != (msgw = plugin->msg_head))
1087 { 1095 {
1088 if (GNUNET_TIME_absolute_get_remaining(msgw->timeout).rel_value_us > 0) 1096 if (GNUNET_TIME_absolute_get_remaining (msgw->timeout).rel_value_us > 0)
1089 break; /* Message is ready for sending */ 1097 break; /* Message is ready for sending */
1090 /* Message has a timeout */ 1098 /* Message has a timeout */
1091 did_delete = GNUNET_YES; 1099 did_delete = GNUNET_YES;
1092 LOG(GNUNET_ERROR_TYPE_DEBUG, 1100 LOG (GNUNET_ERROR_TYPE_DEBUG,
1093 "Timeout for message with %u bytes \n", 1101 "Timeout for message with %u bytes \n",
1094 (unsigned int)msgw->msgsize); 1102 (unsigned int) msgw->msgsize);
1095 GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); 1103 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
1096 session = msgw->session; 1104 session = msgw->session;
1097 session->msgs_in_queue--; 1105 session->msgs_in_queue--;
1098 GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); 1106 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1099 session->bytes_in_queue -= msgw->msgsize; 1107 session->bytes_in_queue -= msgw->msgsize;
1100 GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); 1108 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1101 plugin->bytes_in_queue -= msgw->msgsize; 1109 plugin->bytes_in_queue -= msgw->msgsize;
1102 GNUNET_STATISTICS_set(plugin->env->stats, 1110 GNUNET_STATISTICS_set (plugin->env->stats,
1103 "# bytes currently in UNIX buffers", 1111 "# bytes currently in UNIX buffers",
1104 plugin->bytes_in_queue, 1112 plugin->bytes_in_queue,
1105 GNUNET_NO); 1113 GNUNET_NO);
1106 GNUNET_STATISTICS_update(plugin->env->stats, 1114 GNUNET_STATISTICS_update (plugin->env->stats,
1107 "# UNIX bytes discarded", 1115 "# UNIX bytes discarded",
1108 msgw->msgsize, 1116 msgw->msgsize,
1109 GNUNET_NO); 1117 GNUNET_NO);
1110 if (NULL != msgw->cont) 1118 if (NULL != msgw->cont)
1111 msgw->cont(msgw->cont_cls, 1119 msgw->cont (msgw->cont_cls,
1112 &msgw->session->target, 1120 &msgw->session->target,
1113 GNUNET_SYSERR, 1121 GNUNET_SYSERR,
1114 msgw->payload, 1122 msgw->payload,
1115 0); 1123 0);
1116 GNUNET_free(msgw->msg); 1124 GNUNET_free (msgw->msg);
1117 GNUNET_free(msgw); 1125 GNUNET_free (msgw);
1118 } 1126 }
1119 if (NULL == msgw) 1127 if (NULL == msgw)
1120 { 1128 {
1121 if (GNUNET_YES == did_delete) 1129 if (GNUNET_YES == did_delete)
1122 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); 1130 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1123 return; /* Nothing to send at the moment */ 1131 return; /* Nothing to send at the moment */
1124 } 1132 }
1125 session = msgw->session; 1133 session = msgw->session;
1126 sent = unix_real_send(plugin, 1134 sent = unix_real_send (plugin,
1127 plugin->unix_sock.desc, 1135 plugin->unix_sock.desc,
1128 &session->target, 1136 &session->target,
1129 (const char *)msgw->msg, 1137 (const char *) msgw->msg,
1130 msgw->msgsize, 1138 msgw->msgsize,
1131 msgw->priority, 1139 msgw->priority,
1132 msgw->timeout, 1140 msgw->timeout,
1133 msgw->session->address->address, 1141 msgw->session->address->address,
1134 msgw->session->address->address_length, 1142 msgw->session->address->address_length,
1135 msgw->payload, 1143 msgw->payload,
1136 msgw->cont, 1144 msgw->cont,
1137 msgw->cont_cls); 1145 msgw->cont_cls);
1138 if (RETRY == sent) 1146 if (RETRY == sent)
1139 { 1147 {
1140 GNUNET_STATISTICS_update(plugin->env->stats, 1148 GNUNET_STATISTICS_update (plugin->env->stats,
1141 "# UNIX retry attempts", 1149 "# UNIX retry attempts",
1142 1, 1150 1,
1143 GNUNET_NO); 1151 GNUNET_NO);
1144 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); 1152 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1145 return; 1153 return;
1146 } 1154 }
1147 GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); 1155 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
1148 session->msgs_in_queue--; 1156 session->msgs_in_queue--;
1149 GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); 1157 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1150 session->bytes_in_queue -= msgw->msgsize; 1158 session->bytes_in_queue -= msgw->msgsize;
1151 GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); 1159 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1152 plugin->bytes_in_queue -= msgw->msgsize; 1160 plugin->bytes_in_queue -= msgw->msgsize;
1153 GNUNET_STATISTICS_set(plugin->env->stats, 1161 GNUNET_STATISTICS_set (plugin->env->stats,
1154 "# bytes currently in UNIX buffers", 1162 "# bytes currently in UNIX buffers",
1155 plugin->bytes_in_queue, 1163 plugin->bytes_in_queue,
1156 GNUNET_NO); 1164 GNUNET_NO);
1157 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); 1165 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1158 if (GNUNET_SYSERR == sent) 1166 if (GNUNET_SYSERR == sent)
1159 { 1167 {
1160 /* failed and no retry */ 1168 /* failed and no retry */
1161 if (NULL != msgw->cont) 1169 if (NULL != msgw->cont)
1162 msgw->cont(msgw->cont_cls, 1170 msgw->cont (msgw->cont_cls,
1163 &msgw->session->target, 1171 &msgw->session->target,
1164 GNUNET_SYSERR, 1172 GNUNET_SYSERR,
1165 msgw->payload, 1173 msgw->payload,
1166 0); 1174 0);
1167 GNUNET_STATISTICS_update(plugin->env->stats, 1175 GNUNET_STATISTICS_update (plugin->env->stats,
1168 "# UNIX bytes discarded", 1176 "# UNIX bytes discarded",
1169 msgw->msgsize, 1177 msgw->msgsize,
1170 GNUNET_NO); 1178 GNUNET_NO);
1171 GNUNET_free(msgw->msg); 1179 GNUNET_free (msgw->msg);
1172 GNUNET_free(msgw); 1180 GNUNET_free (msgw);
1173 return; 1181 return;
1174 } 1182 }
1175 /* successfully sent bytes */ 1183 /* successfully sent bytes */
1176 GNUNET_break(sent > 0); 1184 GNUNET_break (sent > 0);
1177 GNUNET_STATISTICS_update(plugin->env->stats, 1185 GNUNET_STATISTICS_update (plugin->env->stats,
1178 "# bytes transmitted via UNIX", 1186 "# bytes transmitted via UNIX",
1179 msgw->msgsize, 1187 msgw->msgsize,
1180 GNUNET_NO); 1188 GNUNET_NO);
1181 if (NULL != msgw->cont) 1189 if (NULL != msgw->cont)
1182 msgw->cont(msgw->cont_cls, 1190 msgw->cont (msgw->cont_cls,
1183 &msgw->session->target, 1191 &msgw->session->target,
1184 GNUNET_OK, 1192 GNUNET_OK,
1185 msgw->payload, 1193 msgw->payload,
1186 msgw->msgsize); 1194 msgw->msgsize);
1187 GNUNET_free(msgw->msg); 1195 GNUNET_free (msgw->msg);
1188 GNUNET_free(msgw); 1196 GNUNET_free (msgw);
1189} 1197}
1190 1198
1191 1199
@@ -1196,20 +1204,20 @@ unix_plugin_do_write(struct Plugin *plugin)
1196 * @param cls the plugin handle 1204 * @param cls the plugin handle
1197 */ 1205 */
1198static void 1206static void
1199unix_plugin_select_read(void *cls) 1207unix_plugin_select_read (void *cls)
1200{ 1208{
1201 struct Plugin *plugin = cls; 1209 struct Plugin *plugin = cls;
1202 const struct GNUNET_SCHEDULER_TaskContext *tc; 1210 const struct GNUNET_SCHEDULER_TaskContext *tc;
1203 1211
1204 plugin->read_task = NULL; 1212 plugin->read_task = NULL;
1205 tc = GNUNET_SCHEDULER_get_task_context(); 1213 tc = GNUNET_SCHEDULER_get_task_context ();
1206 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) 1214 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
1207 unix_plugin_do_read(plugin); 1215 unix_plugin_do_read (plugin);
1208 plugin->read_task = 1216 plugin->read_task =
1209 GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 1217 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1210 plugin->unix_sock.desc, 1218 plugin->unix_sock.desc,
1211 &unix_plugin_select_read, 1219 &unix_plugin_select_read,
1212 plugin); 1220 plugin);
1213} 1221}
1214 1222
1215 1223
@@ -1220,22 +1228,22 @@ unix_plugin_select_read(void *cls)
1220 * @param cls the plugin handle 1228 * @param cls the plugin handle
1221 */ 1229 */
1222static void 1230static void
1223unix_plugin_select_write(void *cls) 1231unix_plugin_select_write (void *cls)
1224{ 1232{
1225 struct Plugin *plugin = cls; 1233 struct Plugin *plugin = cls;
1226 const struct GNUNET_SCHEDULER_TaskContext *tc; 1234 const struct GNUNET_SCHEDULER_TaskContext *tc;
1227 1235
1228 plugin->write_task = NULL; 1236 plugin->write_task = NULL;
1229 tc = GNUNET_SCHEDULER_get_task_context(); 1237 tc = GNUNET_SCHEDULER_get_task_context ();
1230 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) 1238 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
1231 unix_plugin_do_write(plugin); 1239 unix_plugin_do_write (plugin);
1232 if (NULL == plugin->msg_head) 1240 if (NULL == plugin->msg_head)
1233 return; /* write queue empty */ 1241 return; /* write queue empty */
1234 plugin->write_task = 1242 plugin->write_task =
1235 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, 1243 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1236 plugin->unix_sock.desc, 1244 plugin->unix_sock.desc,
1237 &unix_plugin_select_write, 1245 &unix_plugin_select_write,
1238 plugin); 1246 plugin);
1239} 1247}
1240 1248
1241 1249
@@ -1267,14 +1275,14 @@ unix_plugin_select_write(void *cls)
1267 * and does NOT mean that the message was not transmitted (DV) 1275 * and does NOT mean that the message was not transmitted (DV)
1268 */ 1276 */
1269static ssize_t 1277static ssize_t
1270unix_plugin_send(void *cls, 1278unix_plugin_send (void *cls,
1271 struct GNUNET_ATS_Session *session, 1279 struct GNUNET_ATS_Session *session,
1272 const char *msgbuf, 1280 const char *msgbuf,
1273 size_t msgbuf_size, 1281 size_t msgbuf_size,
1274 unsigned int priority, 1282 unsigned int priority,
1275 struct GNUNET_TIME_Relative to, 1283 struct GNUNET_TIME_Relative to,
1276 GNUNET_TRANSPORT_TransmitContinuation cont, 1284 GNUNET_TRANSPORT_TransmitContinuation cont,
1277 void *cont_cls) 1285 void *cont_cls)
1278{ 1286{
1279 struct Plugin *plugin = cls; 1287 struct Plugin *plugin = cls;
1280 struct UNIXMessageWrapper *wrapper; 1288 struct UNIXMessageWrapper *wrapper;
@@ -1282,60 +1290,60 @@ unix_plugin_send(void *cls,
1282 int ssize; 1290 int ssize;
1283 1291
1284 if (GNUNET_OK != 1292 if (GNUNET_OK !=
1285 GNUNET_CONTAINER_multipeermap_contains_value(plugin->session_map, 1293 GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map,
1286 &session->target, 1294 &session->target,
1287 session)) 1295 session))
1288 { 1296 {
1289 LOG(GNUNET_ERROR_TYPE_ERROR, 1297 LOG (GNUNET_ERROR_TYPE_ERROR,
1290 "Invalid session for peer `%s' `%s'\n", 1298 "Invalid session for peer `%s' `%s'\n",
1291 GNUNET_i2s(&session->target), 1299 GNUNET_i2s (&session->target),
1292 unix_plugin_address_to_string(NULL, 1300 unix_plugin_address_to_string (NULL,
1293 session->address->address, 1301 session->address->address,
1294 session->address->address_length)); 1302 session->address->address_length));
1295 GNUNET_break(0); 1303 GNUNET_break (0);
1296 return GNUNET_SYSERR; 1304 return GNUNET_SYSERR;
1297 } 1305 }
1298 LOG(GNUNET_ERROR_TYPE_DEBUG, 1306 LOG (GNUNET_ERROR_TYPE_DEBUG,
1299 "Sending %u bytes with session for peer `%s' `%s'\n", 1307 "Sending %u bytes with session for peer `%s' `%s'\n",
1300 msgbuf_size, 1308 msgbuf_size,
1301 GNUNET_i2s(&session->target), 1309 GNUNET_i2s (&session->target),
1302 unix_plugin_address_to_string(NULL, 1310 unix_plugin_address_to_string (NULL,
1303 session->address->address, 1311 session->address->address,
1304 session->address->address_length)); 1312 session->address->address_length));
1305 ssize = sizeof(struct UNIXMessage) + msgbuf_size; 1313 ssize = sizeof(struct UNIXMessage) + msgbuf_size;
1306 message = GNUNET_malloc(sizeof(struct UNIXMessage) + msgbuf_size); 1314 message = GNUNET_malloc (sizeof(struct UNIXMessage) + msgbuf_size);
1307 message->header.size = htons(ssize); 1315 message->header.size = htons (ssize);
1308 message->header.type = htons(0); 1316 message->header.type = htons (0);
1309 GNUNET_memcpy(&message->sender, 1317 GNUNET_memcpy (&message->sender,
1310 plugin->env->my_identity, 1318 plugin->env->my_identity,
1311 sizeof(struct GNUNET_PeerIdentity)); 1319 sizeof(struct GNUNET_PeerIdentity));
1312 GNUNET_memcpy(&message[1], msgbuf, msgbuf_size); 1320 GNUNET_memcpy (&message[1], msgbuf, msgbuf_size);
1313 wrapper = GNUNET_new(struct UNIXMessageWrapper); 1321 wrapper = GNUNET_new (struct UNIXMessageWrapper);
1314 wrapper->msg = message; 1322 wrapper->msg = message;
1315 wrapper->msgsize = ssize; 1323 wrapper->msgsize = ssize;
1316 wrapper->payload = msgbuf_size; 1324 wrapper->payload = msgbuf_size;
1317 wrapper->priority = priority; 1325 wrapper->priority = priority;
1318 wrapper->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to); 1326 wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), to);
1319 wrapper->cont = cont; 1327 wrapper->cont = cont;
1320 wrapper->cont_cls = cont_cls; 1328 wrapper->cont_cls = cont_cls;
1321 wrapper->session = session; 1329 wrapper->session = session;
1322 GNUNET_CONTAINER_DLL_insert_tail(plugin->msg_head, 1330 GNUNET_CONTAINER_DLL_insert_tail (plugin->msg_head,
1323 plugin->msg_tail, 1331 plugin->msg_tail,
1324 wrapper); 1332 wrapper);
1325 plugin->bytes_in_queue += ssize; 1333 plugin->bytes_in_queue += ssize;
1326 session->bytes_in_queue += ssize; 1334 session->bytes_in_queue += ssize;
1327 session->msgs_in_queue++; 1335 session->msgs_in_queue++;
1328 GNUNET_STATISTICS_set(plugin->env->stats, 1336 GNUNET_STATISTICS_set (plugin->env->stats,
1329 "# bytes currently in UNIX buffers", 1337 "# bytes currently in UNIX buffers",
1330 plugin->bytes_in_queue, 1338 plugin->bytes_in_queue,
1331 GNUNET_NO); 1339 GNUNET_NO);
1332 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE); 1340 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1333 if (NULL == plugin->write_task) 1341 if (NULL == plugin->write_task)
1334 plugin->write_task = 1342 plugin->write_task =
1335 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL, 1343 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1336 plugin->unix_sock.desc, 1344 plugin->unix_sock.desc,
1337 &unix_plugin_select_write, 1345 &unix_plugin_select_write,
1338 plugin); 1346 plugin);
1339 return ssize; 1347 return ssize;
1340} 1348}
1341 1349
@@ -1347,57 +1355,57 @@ unix_plugin_send(void *cls,
1347 * @return number of sockets created or #GNUNET_SYSERR on error 1355 * @return number of sockets created or #GNUNET_SYSERR on error
1348 */ 1356 */
1349static int 1357static int
1350unix_transport_server_start(void *cls) 1358unix_transport_server_start (void *cls)
1351{ 1359{
1352 struct Plugin *plugin = cls; 1360 struct Plugin *plugin = cls;
1353 struct sockaddr_un *un; 1361 struct sockaddr_un *un;
1354 socklen_t un_len; 1362 socklen_t un_len;
1355 1363
1356 un = unix_address_to_sockaddr(plugin->unix_socket_path, &un_len); 1364 un = unix_address_to_sockaddr (plugin->unix_socket_path, &un_len);
1357 if (GNUNET_YES == plugin->is_abstract) 1365 if (GNUNET_YES == plugin->is_abstract)
1358 { 1366 {
1359 plugin->unix_socket_path[0] = '@'; 1367 plugin->unix_socket_path[0] = '@';
1360 un->sun_path[0] = '\0'; 1368 un->sun_path[0] = '\0';
1361 } 1369 }
1362 plugin->unix_sock.desc = 1370 plugin->unix_sock.desc =
1363 GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_DGRAM, 0); 1371 GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
1364 if (NULL == plugin->unix_sock.desc) 1372 if (NULL == plugin->unix_sock.desc)
1365 { 1373 {
1366 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); 1374 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
1367 GNUNET_free(un); 1375 GNUNET_free (un);
1368 return GNUNET_SYSERR; 1376 return GNUNET_SYSERR;
1369 } 1377 }
1370 if ('\0' != un->sun_path[0]) 1378 if ('\0' != un->sun_path[0])
1379 {
1380 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path))
1371 { 1381 {
1372 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(un->sun_path)) 1382 LOG (GNUNET_ERROR_TYPE_ERROR,
1373 { 1383 _ ("Cannot create path to `%s'\n"),
1374 LOG(GNUNET_ERROR_TYPE_ERROR, 1384 un->sun_path);
1375 _("Cannot create path to `%s'\n"), 1385 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
1376 un->sun_path);
1377 GNUNET_NETWORK_socket_close(plugin->unix_sock.desc);
1378 plugin->unix_sock.desc = NULL;
1379 GNUNET_free(un);
1380 return GNUNET_SYSERR;
1381 }
1382 }
1383 if (GNUNET_OK != GNUNET_NETWORK_socket_bind(plugin->unix_sock.desc,
1384 (const struct sockaddr *)un,
1385 un_len))
1386 {
1387 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "bind");
1388 LOG(GNUNET_ERROR_TYPE_ERROR, _("Cannot bind to `%s'\n"), un->sun_path);
1389 GNUNET_NETWORK_socket_close(plugin->unix_sock.desc);
1390 plugin->unix_sock.desc = NULL; 1386 plugin->unix_sock.desc = NULL;
1391 GNUNET_free(un); 1387 GNUNET_free (un);
1392 return GNUNET_SYSERR; 1388 return GNUNET_SYSERR;
1393 } 1389 }
1394 LOG(GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", plugin->unix_socket_path); 1390 }
1391 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc,
1392 (const struct sockaddr *) un,
1393 un_len))
1394 {
1395 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
1396 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Cannot bind to `%s'\n"), un->sun_path);
1397 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
1398 plugin->unix_sock.desc = NULL;
1399 GNUNET_free (un);
1400 return GNUNET_SYSERR;
1401 }
1402 LOG (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", plugin->unix_socket_path);
1395 plugin->read_task = 1403 plugin->read_task =
1396 GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, 1404 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
1397 plugin->unix_sock.desc, 1405 plugin->unix_sock.desc,
1398 &unix_plugin_select_read, 1406 &unix_plugin_select_read,
1399 plugin); 1407 plugin);
1400 GNUNET_free(un); 1408 GNUNET_free (un);
1401 return 1; 1409 return 1;
1402} 1410}
1403 1411
@@ -1419,7 +1427,7 @@ unix_transport_server_start(void *cls)
1419 * 1427 *
1420 */ 1428 */
1421static int 1429static int
1422unix_plugin_check_address(void *cls, const void *addr, size_t addrlen) 1430unix_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1423{ 1431{
1424 struct Plugin *plugin = cls; 1432 struct Plugin *plugin = cls;
1425 const struct UnixAddress *ua = addr; 1433 const struct UnixAddress *ua = addr;
@@ -1428,24 +1436,24 @@ unix_plugin_check_address(void *cls, const void *addr, size_t addrlen)
1428 1436
1429 if ((NULL == addr) || (0 == addrlen) || 1437 if ((NULL == addr) || (0 == addrlen) ||
1430 (sizeof(struct UnixAddress) > addrlen)) 1438 (sizeof(struct UnixAddress) > addrlen))
1431 { 1439 {
1432 GNUNET_break(0); 1440 GNUNET_break (0);
1433 return GNUNET_SYSERR; 1441 return GNUNET_SYSERR;
1434 } 1442 }
1435 addrstr = (char *)&ua[1]; 1443 addrstr = (char *) &ua[1];
1436 addr_str_len = ntohl(ua->addrlen); 1444 addr_str_len = ntohl (ua->addrlen);
1437 if ('\0' != addrstr[addr_str_len - 1]) 1445 if ('\0' != addrstr[addr_str_len - 1])
1438 { 1446 {
1439 GNUNET_break(0); 1447 GNUNET_break (0);
1440 return GNUNET_SYSERR; 1448 return GNUNET_SYSERR;
1441 } 1449 }
1442 if (strlen(addrstr) + 1 != addr_str_len) 1450 if (strlen (addrstr) + 1 != addr_str_len)
1443 { 1451 {
1444 GNUNET_break(0); 1452 GNUNET_break (0);
1445 return GNUNET_SYSERR; 1453 return GNUNET_SYSERR;
1446 } 1454 }
1447 1455
1448 if (0 == strcmp(plugin->unix_socket_path, addrstr)) 1456 if (0 == strcmp (plugin->unix_socket_path, addrstr))
1449 return GNUNET_OK; 1457 return GNUNET_OK;
1450 return GNUNET_SYSERR; 1458 return GNUNET_SYSERR;
1451} 1459}
@@ -1466,23 +1474,23 @@ unix_plugin_check_address(void *cls, const void *addr, size_t addrlen)
1466 * @param asc_cls closure for @a asc 1474 * @param asc_cls closure for @a asc
1467 */ 1475 */
1468static void 1476static void
1469unix_plugin_address_pretty_printer(void *cls, 1477unix_plugin_address_pretty_printer (void *cls,
1470 const char *type, 1478 const char *type,
1471 const void *addr, 1479 const void *addr,
1472 size_t addrlen, 1480 size_t addrlen,
1473 int numeric, 1481 int numeric,
1474 struct GNUNET_TIME_Relative timeout, 1482 struct GNUNET_TIME_Relative timeout,
1475 GNUNET_TRANSPORT_AddressStringCallback asc, 1483 GNUNET_TRANSPORT_AddressStringCallback asc,
1476 void *asc_cls) 1484 void *asc_cls)
1477{ 1485{
1478 const char *ret; 1486 const char *ret;
1479 1487
1480 if ((NULL != addr) && (addrlen > 0)) 1488 if ((NULL != addr) && (addrlen > 0))
1481 ret = unix_plugin_address_to_string(NULL, addr, addrlen); 1489 ret = unix_plugin_address_to_string (NULL, addr, addrlen);
1482 else 1490 else
1483 ret = NULL; 1491 ret = NULL;
1484 asc(asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); 1492 asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
1485 asc(asc_cls, NULL, GNUNET_OK); 1493 asc (asc_cls, NULL, GNUNET_OK);
1486} 1494}
1487 1495
1488 1496
@@ -1499,11 +1507,11 @@ unix_plugin_address_pretty_printer(void *cls,
1499 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 1507 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1500 */ 1508 */
1501static int 1509static int
1502unix_plugin_string_to_address(void *cls, 1510unix_plugin_string_to_address (void *cls,
1503 const char *addr, 1511 const char *addr,
1504 uint16_t addrlen, 1512 uint16_t addrlen,
1505 void **buf, 1513 void **buf,
1506 size_t *added) 1514 size_t *added)
1507{ 1515{
1508 struct UnixAddress *ua; 1516 struct UnixAddress *ua;
1509 char *address; 1517 char *address;
@@ -1518,53 +1526,53 @@ unix_plugin_string_to_address(void *cls,
1518 optionstr = NULL; 1526 optionstr = NULL;
1519 1527
1520 if ((NULL == addr) || (addrlen == 0)) 1528 if ((NULL == addr) || (addrlen == 0))
1521 { 1529 {
1522 GNUNET_break(0); 1530 GNUNET_break (0);
1523 return GNUNET_SYSERR; 1531 return GNUNET_SYSERR;
1524 } 1532 }
1525 if ('\0' != addr[addrlen - 1]) 1533 if ('\0' != addr[addrlen - 1])
1526 { 1534 {
1527 GNUNET_break(0); 1535 GNUNET_break (0);
1528 return GNUNET_SYSERR; 1536 return GNUNET_SYSERR;
1529 } 1537 }
1530 if (strlen(addr) != addrlen - 1) 1538 if (strlen (addr) != addrlen - 1)
1531 { 1539 {
1532 GNUNET_break(0); 1540 GNUNET_break (0);
1533 return GNUNET_SYSERR; 1541 return GNUNET_SYSERR;
1534 } 1542 }
1535 plugin = GNUNET_strdup(addr); 1543 plugin = GNUNET_strdup (addr);
1536 optionstr = strchr(plugin, '.'); 1544 optionstr = strchr (plugin, '.');
1537 if (NULL == optionstr) 1545 if (NULL == optionstr)
1538 { 1546 {
1539 GNUNET_break(0); 1547 GNUNET_break (0);
1540 GNUNET_free(plugin); 1548 GNUNET_free (plugin);
1541 return GNUNET_SYSERR; 1549 return GNUNET_SYSERR;
1542 } 1550 }
1543 optionstr[0] = '\0'; 1551 optionstr[0] = '\0';
1544 optionstr++; 1552 optionstr++;
1545 options = atol(optionstr); 1553 options = atol (optionstr);
1546 address = strchr(optionstr, '.'); 1554 address = strchr (optionstr, '.');
1547 if (NULL == address) 1555 if (NULL == address)
1548 { 1556 {
1549 GNUNET_break(0); 1557 GNUNET_break (0);
1550 GNUNET_free(plugin); 1558 GNUNET_free (plugin);
1551 return GNUNET_SYSERR; 1559 return GNUNET_SYSERR;
1552 } 1560 }
1553 address[0] = '\0'; 1561 address[0] = '\0';
1554 address++; 1562 address++;
1555 if (0 != strcmp(plugin, PLUGIN_NAME)) 1563 if (0 != strcmp (plugin, PLUGIN_NAME))
1556 { 1564 {
1557 GNUNET_break(0); 1565 GNUNET_break (0);
1558 GNUNET_free(plugin); 1566 GNUNET_free (plugin);
1559 return GNUNET_SYSERR; 1567 return GNUNET_SYSERR;
1560 } 1568 }
1561 1569
1562 ua_size = sizeof(struct UnixAddress) + strlen(address) + 1; 1570 ua_size = sizeof(struct UnixAddress) + strlen (address) + 1;
1563 ua = GNUNET_malloc(ua_size); 1571 ua = GNUNET_malloc (ua_size);
1564 ua->options = htonl(options); 1572 ua->options = htonl (options);
1565 ua->addrlen = htonl(strlen(address) + 1); 1573 ua->addrlen = htonl (strlen (address) + 1);
1566 GNUNET_memcpy(&ua[1], address, strlen(address) + 1); 1574 GNUNET_memcpy (&ua[1], address, strlen (address) + 1);
1567 GNUNET_free(plugin); 1575 GNUNET_free (plugin);
1568 1576
1569 (*buf) = ua; 1577 (*buf) = ua;
1570 (*added) = ua_size; 1578 (*added) = ua_size;
@@ -1578,7 +1586,7 @@ unix_plugin_string_to_address(void *cls,
1578 * @param cls the plugin 1586 * @param cls the plugin
1579 */ 1587 */
1580static void 1588static void
1581address_notification(void *cls) 1589address_notification (void *cls)
1582{ 1590{
1583 struct Plugin *plugin = cls; 1591 struct Plugin *plugin = cls;
1584 struct GNUNET_HELLO_Address *address; 1592 struct GNUNET_HELLO_Address *address;
@@ -1586,24 +1594,24 @@ address_notification(void *cls)
1586 struct UnixAddress *ua; 1594 struct UnixAddress *ua;
1587 char *unix_path; 1595 char *unix_path;
1588 1596
1589 len = sizeof(struct UnixAddress) + strlen(plugin->unix_socket_path) + 1; 1597 len = sizeof(struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
1590 ua = GNUNET_malloc(len); 1598 ua = GNUNET_malloc (len);
1591 ua->options = htonl(plugin->myoptions); 1599 ua->options = htonl (plugin->myoptions);
1592 ua->addrlen = htonl(strlen(plugin->unix_socket_path) + 1); 1600 ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1);
1593 unix_path = (char *)&ua[1]; 1601 unix_path = (char *) &ua[1];
1594 GNUNET_memcpy(unix_path, 1602 GNUNET_memcpy (unix_path,
1595 plugin->unix_socket_path, 1603 plugin->unix_socket_path,
1596 strlen(plugin->unix_socket_path) + 1); 1604 strlen (plugin->unix_socket_path) + 1);
1597 1605
1598 plugin->address_update_task = NULL; 1606 plugin->address_update_task = NULL;
1599 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, 1607 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1600 PLUGIN_NAME, 1608 PLUGIN_NAME,
1601 ua, 1609 ua,
1602 len, 1610 len,
1603 GNUNET_HELLO_ADDRESS_INFO_NONE); 1611 GNUNET_HELLO_ADDRESS_INFO_NONE);
1604 plugin->env->notify_address(plugin->env->cls, GNUNET_YES, address); 1612 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address);
1605 GNUNET_free(ua); 1613 GNUNET_free (ua);
1606 GNUNET_free(address); 1614 GNUNET_free (address);
1607} 1615}
1608 1616
1609 1617
@@ -1616,14 +1624,14 @@ address_notification(void *cls)
1616 * @return #GNUNET_YES (always, continue to iterate) 1624 * @return #GNUNET_YES (always, continue to iterate)
1617 */ 1625 */
1618static int 1626static int
1619get_session_delete_it(void *cls, 1627get_session_delete_it (void *cls,
1620 const struct GNUNET_PeerIdentity *key, 1628 const struct GNUNET_PeerIdentity *key,
1621 void *value) 1629 void *value)
1622{ 1630{
1623 struct Plugin *plugin = cls; 1631 struct Plugin *plugin = cls;
1624 struct GNUNET_ATS_Session *session = value; 1632 struct GNUNET_ATS_Session *session = value;
1625 1633
1626 unix_plugin_session_disconnect(plugin, session); 1634 unix_plugin_session_disconnect (plugin, session);
1627 return GNUNET_YES; 1635 return GNUNET_YES;
1628} 1636}
1629 1637
@@ -1636,15 +1644,15 @@ get_session_delete_it(void *cls,
1636 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed 1644 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed
1637 */ 1645 */
1638static void 1646static void
1639unix_plugin_peer_disconnect(void *cls, 1647unix_plugin_peer_disconnect (void *cls,
1640 const struct GNUNET_PeerIdentity *target) 1648 const struct GNUNET_PeerIdentity *target)
1641{ 1649{
1642 struct Plugin *plugin = cls; 1650 struct Plugin *plugin = cls;
1643 1651
1644 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->session_map, 1652 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
1645 target, 1653 target,
1646 &get_session_delete_it, 1654 &get_session_delete_it,
1647 plugin); 1655 plugin);
1648} 1656}
1649 1657
1650 1658
@@ -1658,15 +1666,15 @@ unix_plugin_peer_disconnect(void *cls,
1658 * @return #GNUNET_OK (continue to iterate) 1666 * @return #GNUNET_OK (continue to iterate)
1659 */ 1667 */
1660static int 1668static int
1661send_session_info_iter(void *cls, 1669send_session_info_iter (void *cls,
1662 const struct GNUNET_PeerIdentity *peer, 1670 const struct GNUNET_PeerIdentity *peer,
1663 void *value) 1671 void *value)
1664{ 1672{
1665 struct Plugin *plugin = cls; 1673 struct Plugin *plugin = cls;
1666 struct GNUNET_ATS_Session *session = value; 1674 struct GNUNET_ATS_Session *session = value;
1667 1675
1668 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT); 1676 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT);
1669 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP); 1677 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP);
1670 return GNUNET_OK; 1678 return GNUNET_OK;
1671} 1679}
1672 1680
@@ -1684,22 +1692,22 @@ send_session_info_iter(void *cls,
1684 * @param sic_cls closure for @a sic 1692 * @param sic_cls closure for @a sic
1685 */ 1693 */
1686static void 1694static void
1687unix_plugin_setup_monitor(void *cls, 1695unix_plugin_setup_monitor (void *cls,
1688 GNUNET_TRANSPORT_SessionInfoCallback sic, 1696 GNUNET_TRANSPORT_SessionInfoCallback sic,
1689 void *sic_cls) 1697 void *sic_cls)
1690{ 1698{
1691 struct Plugin *plugin = cls; 1699 struct Plugin *plugin = cls;
1692 1700
1693 plugin->sic = sic; 1701 plugin->sic = sic;
1694 plugin->sic_cls = sic_cls; 1702 plugin->sic_cls = sic_cls;
1695 if (NULL != sic) 1703 if (NULL != sic)
1696 { 1704 {
1697 GNUNET_CONTAINER_multipeermap_iterate(plugin->session_map, 1705 GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map,
1698 &send_session_info_iter, 1706 &send_session_info_iter,
1699 plugin); 1707 plugin);
1700 /* signal end of first iteration */ 1708 /* signal end of first iteration */
1701 sic(sic_cls, NULL, NULL); 1709 sic (sic_cls, NULL, NULL);
1702 } 1710 }
1703} 1711}
1704 1712
1705 1713
@@ -1711,7 +1719,7 @@ unix_plugin_setup_monitor(void *cls,
1711 * @return NULL on error, plugin functions otherwise 1719 * @return NULL on error, plugin functions otherwise
1712 */ 1720 */
1713void * 1721void *
1714libgnunet_plugin_transport_unix_init(void *cls) 1722libgnunet_plugin_transport_unix_init (void *cls)
1715{ 1723{
1716 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 1724 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1717 struct GNUNET_TRANSPORT_PluginFunctions *api; 1725 struct GNUNET_TRANSPORT_PluginFunctions *api;
@@ -1719,45 +1727,45 @@ libgnunet_plugin_transport_unix_init(void *cls)
1719 int sockets_created; 1727 int sockets_created;
1720 1728
1721 if (NULL == env->receive) 1729 if (NULL == env->receive)
1722 { 1730 {
1723 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 1731 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
1724 initialze the plugin or the API */ 1732 initialze the plugin or the API */
1725 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 1733 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
1726 api->cls = NULL; 1734 api->cls = NULL;
1727 api->address_pretty_printer = &unix_plugin_address_pretty_printer; 1735 api->address_pretty_printer = &unix_plugin_address_pretty_printer;
1728 api->address_to_string = &unix_plugin_address_to_string; 1736 api->address_to_string = &unix_plugin_address_to_string;
1729 api->string_to_address = &unix_plugin_string_to_address; 1737 api->string_to_address = &unix_plugin_string_to_address;
1730 return api; 1738 return api;
1731 } 1739 }
1732 1740
1733 plugin = GNUNET_new(struct Plugin); 1741 plugin = GNUNET_new (struct Plugin);
1734 if (GNUNET_OK != 1742 if (GNUNET_OK !=
1735 GNUNET_CONFIGURATION_get_value_filename(env->cfg, 1743 GNUNET_CONFIGURATION_get_value_filename (env->cfg,
1736 "transport-unix", 1744 "transport-unix",
1737 "UNIXPATH", 1745 "UNIXPATH",
1738 &plugin->unix_socket_path)) 1746 &plugin->unix_socket_path))
1739 { 1747 {
1740 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 1748 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1741 "transport-unix", 1749 "transport-unix",
1742 "UNIXPATH"); 1750 "UNIXPATH");
1743 GNUNET_free(plugin); 1751 GNUNET_free (plugin);
1744 return NULL; 1752 return NULL;
1745 } 1753 }
1746 1754
1747 plugin->env = env; 1755 plugin->env = env;
1748 1756
1749 /* Initialize my flags */ 1757 /* Initialize my flags */
1750#ifdef LINUX 1758#ifdef LINUX
1751 plugin->is_abstract = 1759 plugin->is_abstract =
1752 GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, 1760 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
1753 "testing", 1761 "testing",
1754 "USE_ABSTRACT_SOCKETS"); 1762 "USE_ABSTRACT_SOCKETS");
1755#endif 1763#endif
1756 plugin->myoptions = UNIX_OPTIONS_NONE; 1764 plugin->myoptions = UNIX_OPTIONS_NONE;
1757 if (GNUNET_YES == plugin->is_abstract) 1765 if (GNUNET_YES == plugin->is_abstract)
1758 plugin->myoptions = UNIX_OPTIONS_USE_ABSTRACT_SOCKETS; 1766 plugin->myoptions = UNIX_OPTIONS_USE_ABSTRACT_SOCKETS;
1759 1767
1760 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 1768 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
1761 api->cls = plugin; 1769 api->cls = plugin;
1762 api->get_session = &unix_plugin_get_session; 1770 api->get_session = &unix_plugin_get_session;
1763 api->send = &unix_plugin_send; 1771 api->send = &unix_plugin_send;
@@ -1772,18 +1780,18 @@ libgnunet_plugin_transport_unix_init(void *cls)
1772 api->get_network_for_address = &unix_plugin_get_network_for_address; 1780 api->get_network_for_address = &unix_plugin_get_network_for_address;
1773 api->update_session_timeout = &unix_plugin_update_session_timeout; 1781 api->update_session_timeout = &unix_plugin_update_session_timeout;
1774 api->setup_monitor = &unix_plugin_setup_monitor; 1782 api->setup_monitor = &unix_plugin_setup_monitor;
1775 sockets_created = unix_transport_server_start(plugin); 1783 sockets_created = unix_transport_server_start (plugin);
1776 if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created)) 1784 if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created))
1777 { 1785 {
1778 LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to open UNIX listen socket\n")); 1786 LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UNIX listen socket\n"));
1779 GNUNET_free(api); 1787 GNUNET_free (api);
1780 GNUNET_free(plugin->unix_socket_path); 1788 GNUNET_free (plugin->unix_socket_path);
1781 GNUNET_free(plugin); 1789 GNUNET_free (plugin);
1782 return NULL; 1790 return NULL;
1783 } 1791 }
1784 plugin->session_map = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); 1792 plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1785 plugin->address_update_task = 1793 plugin->address_update_task =
1786 GNUNET_SCHEDULER_add_now(&address_notification, plugin); 1794 GNUNET_SCHEDULER_add_now (&address_notification, plugin);
1787 return api; 1795 return api;
1788} 1796}
1789 1797
@@ -1795,7 +1803,7 @@ libgnunet_plugin_transport_unix_init(void *cls)
1795 * @return NULL (always) 1803 * @return NULL (always)
1796 */ 1804 */
1797void * 1805void *
1798libgnunet_plugin_transport_unix_done(void *cls) 1806libgnunet_plugin_transport_unix_done (void *cls)
1799{ 1807{
1800 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 1808 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1801 struct Plugin *plugin = api->cls; 1809 struct Plugin *plugin = api->cls;
@@ -1806,75 +1814,75 @@ libgnunet_plugin_transport_unix_done(void *cls)
1806 struct GNUNET_ATS_Session *session; 1814 struct GNUNET_ATS_Session *session;
1807 1815
1808 if (NULL == plugin) 1816 if (NULL == plugin)
1809 { 1817 {
1810 GNUNET_free(api); 1818 GNUNET_free (api);
1811 return NULL; 1819 return NULL;
1812 } 1820 }
1813 len = sizeof(struct UnixAddress) + strlen(plugin->unix_socket_path) + 1; 1821 len = sizeof(struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
1814 ua = GNUNET_malloc(len); 1822 ua = GNUNET_malloc (len);
1815 ua->options = htonl(plugin->myoptions); 1823 ua->options = htonl (plugin->myoptions);
1816 ua->addrlen = htonl(strlen(plugin->unix_socket_path) + 1); 1824 ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1);
1817 GNUNET_memcpy(&ua[1], 1825 GNUNET_memcpy (&ua[1],
1818 plugin->unix_socket_path, 1826 plugin->unix_socket_path,
1819 strlen(plugin->unix_socket_path) + 1); 1827 strlen (plugin->unix_socket_path) + 1);
1820 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, 1828 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1821 PLUGIN_NAME, 1829 PLUGIN_NAME,
1822 ua, 1830 ua,
1823 len, 1831 len,
1824 GNUNET_HELLO_ADDRESS_INFO_NONE); 1832 GNUNET_HELLO_ADDRESS_INFO_NONE);
1825 plugin->env->notify_address(plugin->env->cls, GNUNET_NO, address); 1833 plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address);
1826 1834
1827 GNUNET_free(address); 1835 GNUNET_free (address);
1828 GNUNET_free(ua); 1836 GNUNET_free (ua);
1829 1837
1830 while (NULL != (msgw = plugin->msg_head)) 1838 while (NULL != (msgw = plugin->msg_head))
1831 { 1839 {
1832 GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw); 1840 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);
1833 session = msgw->session; 1841 session = msgw->session;
1834 session->msgs_in_queue--; 1842 session->msgs_in_queue--;
1835 GNUNET_assert(session->bytes_in_queue >= msgw->msgsize); 1843 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize);
1836 session->bytes_in_queue -= msgw->msgsize; 1844 session->bytes_in_queue -= msgw->msgsize;
1837 GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize); 1845 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize);
1838 plugin->bytes_in_queue -= msgw->msgsize; 1846 plugin->bytes_in_queue -= msgw->msgsize;
1839 if (NULL != msgw->cont) 1847 if (NULL != msgw->cont)
1840 msgw->cont(msgw->cont_cls, 1848 msgw->cont (msgw->cont_cls,
1841 &msgw->session->target, 1849 &msgw->session->target,
1842 GNUNET_SYSERR, 1850 GNUNET_SYSERR,
1843 msgw->payload, 1851 msgw->payload,
1844 0); 1852 0);
1845 GNUNET_free(msgw->msg); 1853 GNUNET_free (msgw->msg);
1846 GNUNET_free(msgw); 1854 GNUNET_free (msgw);
1847 } 1855 }
1848 1856
1849 if (NULL != plugin->read_task) 1857 if (NULL != plugin->read_task)
1850 { 1858 {
1851 GNUNET_SCHEDULER_cancel(plugin->read_task); 1859 GNUNET_SCHEDULER_cancel (plugin->read_task);
1852 plugin->read_task = NULL; 1860 plugin->read_task = NULL;
1853 } 1861 }
1854 if (NULL != plugin->write_task) 1862 if (NULL != plugin->write_task)
1855 { 1863 {
1856 GNUNET_SCHEDULER_cancel(plugin->write_task); 1864 GNUNET_SCHEDULER_cancel (plugin->write_task);
1857 plugin->write_task = NULL; 1865 plugin->write_task = NULL;
1858 } 1866 }
1859 if (NULL != plugin->address_update_task) 1867 if (NULL != plugin->address_update_task)
1860 { 1868 {
1861 GNUNET_SCHEDULER_cancel(plugin->address_update_task); 1869 GNUNET_SCHEDULER_cancel (plugin->address_update_task);
1862 plugin->address_update_task = NULL; 1870 plugin->address_update_task = NULL;
1863 } 1871 }
1864 if (NULL != plugin->unix_sock.desc) 1872 if (NULL != plugin->unix_sock.desc)
1865 { 1873 {
1866 GNUNET_break(GNUNET_OK == 1874 GNUNET_break (GNUNET_OK ==
1867 GNUNET_NETWORK_socket_close(plugin->unix_sock.desc)); 1875 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc));
1868 plugin->unix_sock.desc = NULL; 1876 plugin->unix_sock.desc = NULL;
1869 } 1877 }
1870 GNUNET_CONTAINER_multipeermap_iterate(plugin->session_map, 1878 GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map,
1871 &get_session_delete_it, 1879 &get_session_delete_it,
1872 plugin); 1880 plugin);
1873 GNUNET_CONTAINER_multipeermap_destroy(plugin->session_map); 1881 GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map);
1874 GNUNET_break(0 == plugin->bytes_in_queue); 1882 GNUNET_break (0 == plugin->bytes_in_queue);
1875 GNUNET_free(plugin->unix_socket_path); 1883 GNUNET_free (plugin->unix_socket_path);
1876 GNUNET_free(plugin); 1884 GNUNET_free (plugin);
1877 GNUNET_free(api); 1885 GNUNET_free (api);
1878 return NULL; 1886 return NULL;
1879} 1887}
1880 1888