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.c135
1 files changed, 53 insertions, 82 deletions
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c
index 3a2fa6516..384787ae9 100644
--- a/src/transport/plugin_transport_unix.c
+++ b/src/transport/plugin_transport_unix.c
@@ -103,11 +103,7 @@ struct Session
103 103
104 struct Plugin * plugin; 104 struct Plugin * plugin;
105 105
106 struct UnixAddress *addr; 106 struct GNUNET_HELLO_Address *address;
107
108 size_t addrlen;
109
110 int inbound;
111 107
112 /** 108 /**
113 * Session timeout task 109 * Session timeout task
@@ -468,17 +464,9 @@ struct LookupCtx
468 /** 464 /**
469 * Location to store the session, if found. 465 * Location to store the session, if found.
470 */ 466 */
471 struct Session *s; 467 struct Session *res;
472
473 /**
474 * Address we are looking for.
475 */
476 const struct UnixAddress *ua;
477 468
478 /** 469 struct GNUNET_HELLO_Address *address;
479 * Number of bytes in @e ua
480 */
481 size_t ua_len;
482}; 470};
483 471
484 472
@@ -496,20 +484,13 @@ lookup_session_it (void *cls,
496 void *value) 484 void *value)
497{ 485{
498 struct LookupCtx *lctx = cls; 486 struct LookupCtx *lctx = cls;
499 struct Session *t = value; 487 struct Session *s = value;
500
501 if (t->addrlen != lctx->ua_len)
502 {
503 GNUNET_break (0);
504 return GNUNET_YES;
505 }
506 488
507 if (0 == memcmp (t->addr, lctx->ua, lctx->ua_len)) 489 if (0 == GNUNET_HELLO_address_cmp (lctx->address, s->address))
508 { 490 {
509 lctx->s = t; 491 lctx->res = s;
510 return GNUNET_NO; 492 return GNUNET_NO;
511 } 493 }
512 GNUNET_break (0);
513 return GNUNET_YES; 494 return GNUNET_YES;
514} 495}
515 496
@@ -525,18 +506,16 @@ lookup_session_it (void *cls,
525 */ 506 */
526static struct Session * 507static struct Session *
527lookup_session (struct Plugin *plugin, 508lookup_session (struct Plugin *plugin,
528 const struct GNUNET_PeerIdentity *sender, 509 struct GNUNET_HELLO_Address *address)
529 const struct UnixAddress *ua, size_t ua_len)
530{ 510{
531 struct LookupCtx lctx; 511 struct LookupCtx lctx;
532 512
533 lctx.s = NULL; 513 lctx.address = address;
534 lctx.ua = ua; 514 lctx.res = NULL;
535 lctx.ua_len = ua_len;
536 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, 515 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
537 sender, 516 &address->peer,
538 &lookup_session_it, &lctx); 517 &lookup_session_it, &lctx);
539 return lctx.s; 518 return lctx.res;
540} 519}
541 520
542 521
@@ -561,7 +540,7 @@ unix_session_disconnect (void *cls,
561 LOG (GNUNET_ERROR_TYPE_DEBUG, 540 LOG (GNUNET_ERROR_TYPE_DEBUG,
562 "Disconnecting session for peer `%s' `%s'\n", 541 "Disconnecting session for peer `%s' `%s'\n",
563 GNUNET_i2s (&s->target), 542 GNUNET_i2s (&s->target),
564 s->addr); 543 unix_address_to_string (NULL, s->address->address, s->address->address_length) );
565 plugin->env->session_end (plugin->env->cls, &s->target, s); 544 plugin->env->session_end (plugin->env->cls, &s->target, s);
566 removed = GNUNET_NO; 545 removed = GNUNET_NO;
567 next = plugin->msg_head; 546 next = plugin->msg_head;
@@ -594,6 +573,7 @@ unix_session_disconnect (void *cls,
594 GNUNET_SCHEDULER_cancel (s->timeout_task); 573 GNUNET_SCHEDULER_cancel (s->timeout_task);
595 s->timeout_task = GNUNET_SCHEDULER_NO_TASK; 574 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
596 } 575 }
576 GNUNET_HELLO_address_free (s->address);
597 GNUNET_free (s); 577 GNUNET_free (s);
598 return GNUNET_OK; 578 return GNUNET_OK;
599} 579}
@@ -746,12 +726,7 @@ struct GetSessionIteratorContext
746 /** 726 /**
747 * Address information. 727 * Address information.
748 */ 728 */
749 const char *address; 729 const struct GNUNET_HELLO_Address *address;
750
751 /**
752 * Number of bytes in @e address
753 */
754 size_t addrlen;
755}; 730};
756 731
757 732
@@ -771,8 +746,7 @@ get_session_it (void *cls,
771 struct GetSessionIteratorContext *gsi = cls; 746 struct GetSessionIteratorContext *gsi = cls;
772 struct Session *s = value; 747 struct Session *s = value;
773 748
774 if ((GNUNET_NO == s->inbound) && (gsi->addrlen == s->addrlen) && 749 if (0 == GNUNET_HELLO_address_cmp(s->address, gsi->address))
775 (0 == memcmp (gsi->address, s->addr, s->addrlen)) )
776 { 750 {
777 gsi->res = s; 751 gsi->res = s;
778 return GNUNET_NO; 752 return GNUNET_NO;
@@ -868,27 +842,23 @@ unix_plugin_get_session (void *cls,
868 } 842 }
869 843
870 /* Check if already existing */ 844 /* Check if already existing */
871 gsi.address = (const char *) address->address; 845 gsi.address = address;
872 gsi.addrlen = address->address_length;
873 gsi.res = NULL; 846 gsi.res = NULL;
874 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, 847 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map,
875 &address->peer, 848 &address->peer,
876 &get_session_it, &gsi); 849 &get_session_it, &gsi);
877 if (NULL != gsi.res) 850 if (NULL != gsi.res)
878 { 851 {
879 LOG (GNUNET_ERROR_TYPE_DEBUG, 852 LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p for address `%s'\n",
880 "Found existing session\n"); 853 gsi.res,
854 unix_address_to_string (NULL, address->address, address->address_length));
881 return gsi.res; 855 return gsi.res;
882 } 856 }
883 857
884 /* create a new session */ 858 /* create a new session */
885 s = GNUNET_malloc (sizeof (struct Session) + address->address_length); 859 s = GNUNET_new (struct Session);
886 s->addr = (struct UnixAddress *) &s[1]; 860 s->target = address->peer;
887 s->addrlen = address->address_length; 861 s->address = GNUNET_HELLO_address_copy (address);
888 s->plugin = plugin;
889 s->inbound = GNUNET_NO;
890 memcpy (s->addr, address->address, address->address_length);
891 memcpy (&s->target, &address->peer, sizeof (struct GNUNET_PeerIdentity));
892 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); 862 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task);
893 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 863 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
894 &session_timeout, 864 &session_timeout,
@@ -918,7 +888,6 @@ unix_plugin_update_session_timeout (void *cls,
918 &session->target, 888 &session->target,
919 session)) 889 session))
920 return; 890 return;
921
922 reschedule_session_timeout (session); 891 reschedule_session_timeout (session);
923} 892}
924 893
@@ -970,7 +939,8 @@ unix_plugin_send (void *cls,
970 LOG (GNUNET_ERROR_TYPE_ERROR, 939 LOG (GNUNET_ERROR_TYPE_ERROR,
971 "Invalid session for peer `%s' `%s'\n", 940 "Invalid session for peer `%s' `%s'\n",
972 GNUNET_i2s (&session->target), 941 GNUNET_i2s (&session->target),
973 (const char *) session->addr); 942 unix_address_to_string(NULL, session->address->address,
943 session->address->address_length));
974 GNUNET_break (0); 944 GNUNET_break (0);
975 return GNUNET_SYSERR; 945 return GNUNET_SYSERR;
976 } 946 }
@@ -978,7 +948,8 @@ unix_plugin_send (void *cls,
978 "Sending %u bytes with session for peer `%s' `%s'\n", 948 "Sending %u bytes with session for peer `%s' `%s'\n",
979 msgbuf_size, 949 msgbuf_size,
980 GNUNET_i2s (&session->target), 950 GNUNET_i2s (&session->target),
981 (const char *) session->addr); 951 unix_address_to_string(NULL, session->address->address,
952 session->address->address_length));
982 ssize = sizeof (struct UNIXMessage) + msgbuf_size; 953 ssize = sizeof (struct UNIXMessage) + msgbuf_size;
983 message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); 954 message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size);
984 message->header.size = htons (ssize); 955 message->header.size = htons (ssize);
@@ -1025,7 +996,7 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
1025 const struct UnixAddress *ua, size_t ua_len) 996 const struct UnixAddress *ua, size_t ua_len)
1026{ 997{
1027 struct Session *s = NULL; 998 struct Session *s = NULL;
1028 struct GNUNET_HELLO_Address * addr; 999 struct GNUNET_HELLO_Address *address;
1029 1000
1030 GNUNET_break (ntohl(plugin->ats_network.value) != GNUNET_ATS_NET_UNSPECIFIED); 1001 GNUNET_break (ntohl(plugin->ats_network.value) != GNUNET_ATS_NET_UNSPECIFIED);
1031 GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); 1002 GNUNET_assert (ua_len >= sizeof (struct UnixAddress));
@@ -1037,31 +1008,23 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
1037 ntohs (currhdr->size), 1008 ntohs (currhdr->size),
1038 GNUNET_NO); 1009 GNUNET_NO);
1039 1010
1040 addr = GNUNET_HELLO_address_allocate (sender, 1011 /* Look for existing session */
1041 "unix", 1012 address = GNUNET_HELLO_address_allocate (sender, PLUGIN_NAME, ua, ua_len,
1042 ua, 1013 GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */
1043 ua_len); 1014 s = lookup_session (plugin, address);
1044 s = lookup_session (plugin, sender, ua, ua_len); 1015
1045 if (NULL == s) 1016 if (NULL == s)
1046 { 1017 {
1047 s = unix_plugin_get_session (plugin, addr); 1018 s = unix_plugin_get_session (plugin, address);
1048 s->inbound = GNUNET_YES;
1049 /* Notify transport and ATS about new inbound session */ 1019 /* Notify transport and ATS about new inbound session */
1050 plugin->env->session_start (NULL, sender, 1020 plugin->env->session_start (NULL, s->address, s, &plugin->ats_network, 1);
1051 PLUGIN_NAME, ua, ua_len, s, &plugin->ats_network, 1);
1052 } 1021 }
1022 GNUNET_HELLO_address_free (address);
1053 reschedule_session_timeout (s); 1023 reschedule_session_timeout (s);
1054 1024
1055 plugin->env->receive (plugin->env->cls, sender, currhdr, s, 1025 plugin->env->receive (plugin->env->cls, s->address, s, currhdr);
1056 (GNUNET_YES == s->inbound) ? NULL : (const char *) ua, 1026 plugin->env->update_address_metrics (plugin->env->cls, s->address, s,
1057 (GNUNET_YES == s->inbound) ? 0 : ua_len); 1027 &plugin->ats_network, 1);
1058
1059 plugin->env->update_address_metrics (plugin->env->cls, sender,
1060 (GNUNET_YES == s->inbound) ? NULL : (const char *) ua,
1061 (GNUNET_YES == s->inbound) ? 0 : ua_len,
1062 s, &plugin->ats_network, 1);
1063
1064 GNUNET_free (addr);
1065} 1028}
1066 1029
1067 1030
@@ -1193,8 +1156,8 @@ unix_plugin_select_write (struct Plugin *plugin)
1193 msgw->msgsize, 1156 msgw->msgsize,
1194 msgw->priority, 1157 msgw->priority,
1195 msgw->timeout, 1158 msgw->timeout,
1196 msgw->session->addr, 1159 msgw->session->address->address,
1197 msgw->session->addrlen, 1160 msgw->session->address->address_length,
1198 msgw->payload, 1161 msgw->payload,
1199 msgw->cont, msgw->cont_cls); 1162 msgw->cont, msgw->cont_cls);
1200 1163
@@ -1517,6 +1480,7 @@ address_notification (void *cls,
1517 const struct GNUNET_SCHEDULER_TaskContext *tc) 1480 const struct GNUNET_SCHEDULER_TaskContext *tc)
1518{ 1481{
1519 struct Plugin *plugin = cls; 1482 struct Plugin *plugin = cls;
1483 struct GNUNET_HELLO_Address *address;
1520 size_t len; 1484 size_t len;
1521 struct UnixAddress *ua; 1485 struct UnixAddress *ua;
1522 1486
@@ -1527,16 +1491,19 @@ address_notification (void *cls,
1527 memcpy (&ua[1], plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1); 1491 memcpy (&ua[1], plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1);
1528 1492
1529 plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK; 1493 plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK;
1530 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, 1494 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1531 ua, len, "unix"); 1495 PLUGIN_NAME, ua, len, GNUNET_HELLO_ADDRESS_INFO_NONE);
1496
1497 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address);
1532 GNUNET_free (ua); 1498 GNUNET_free (ua);
1499 GNUNET_free (address);
1533} 1500}
1534 1501
1535 1502
1536/** 1503/**
1537 * Increment session timeout due to activity 1504 * Increment session timeout due to activity
1538 * 1505 *
1539 * @param s session for which the timeout should be moved 1506 * @param res session for which the timeout should be moved
1540 */ 1507 */
1541static void 1508static void
1542reschedule_session_timeout (struct Session *s) 1509reschedule_session_timeout (struct Session *s)
@@ -1672,6 +1639,7 @@ libgnunet_plugin_transport_unix_done (void *cls)
1672{ 1639{
1673 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 1640 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1674 struct Plugin *plugin = api->cls; 1641 struct Plugin *plugin = api->cls;
1642 struct GNUNET_HELLO_Address *address;
1675 struct UNIXMessageWrapper * msgw; 1643 struct UNIXMessageWrapper * msgw;
1676 struct UnixAddress *ua; 1644 struct UnixAddress *ua;
1677 size_t len; 1645 size_t len;
@@ -1687,10 +1655,13 @@ libgnunet_plugin_transport_unix_done (void *cls)
1687 ua->options = htonl (myoptions); 1655 ua->options = htonl (myoptions);
1688 ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1); 1656 ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1);
1689 memcpy (&ua[1], plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1); 1657 memcpy (&ua[1], plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1);
1658 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1659 PLUGIN_NAME, ua, len, GNUNET_HELLO_ADDRESS_INFO_NONE);
1660 plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address);
1690 1661
1691 plugin->env->notify_address (plugin->env->cls, GNUNET_NO, 1662 GNUNET_free (address);
1692 ua, len, "unix");
1693 GNUNET_free (ua); 1663 GNUNET_free (ua);
1664
1694 while (NULL != (msgw = plugin->msg_head)) 1665 while (NULL != (msgw = plugin->msg_head))
1695 { 1666 {
1696 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); 1667 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw);