aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/Makefile.am15
-rw-r--r--src/transport/plugin_transport_unix.c154
-rw-r--r--src/transport/test_transport_api_unix_abstract_peer1.conf31
-rw-r--r--src/transport/test_transport_api_unix_abstract_peer2.conf31
4 files changed, 177 insertions, 54 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 2f30a212a..3112f0f30 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -103,6 +103,9 @@ UNIX_PLUGIN_TIMEOUT_TEST = test_transport_api_timeout_unix
103UNIX_REL_TEST = test_transport_api_unreliability_unix 103UNIX_REL_TEST = test_transport_api_unreliability_unix
104UNIX_QUOTA_TEST = test_quota_compliance_unix \ 104UNIX_QUOTA_TEST = test_quota_compliance_unix \
105 test_quota_compliance_unix_asymmetric 105 test_quota_compliance_unix_asymmetric
106if LINUX
107 UNIX_API_ABSTRACT_TEST = test_transport_api_unix_abstract
108endif
106endif 109endif
107 110
108noinst_PROGRAMS = \ 111noinst_PROGRAMS = \
@@ -396,6 +399,7 @@ check_PROGRAMS = \
396 test_transport_api_timeout_udp \ 399 test_transport_api_timeout_udp \
397 $(UNIX_PLUGIN_TEST) \ 400 $(UNIX_PLUGIN_TEST) \
398 $(UNIX_PLUGIN_TIMEOUT_TEST) \ 401 $(UNIX_PLUGIN_TIMEOUT_TEST) \
402 $(UNIX_API_ABSTRACT_TEST) \
399 test_transport_api_udp_nat \ 403 test_transport_api_udp_nat \
400 $(HTTP_API_TEST) \ 404 $(HTTP_API_TEST) \
401 $(HTTP_REVERSE_API_TEST) \ 405 $(HTTP_REVERSE_API_TEST) \
@@ -464,6 +468,7 @@ TESTS = \
464 test_transport_api_timeout_udp \ 468 test_transport_api_timeout_udp \
465 $(UNIX_PLUGIN_TEST) \ 469 $(UNIX_PLUGIN_TEST) \
466 $(UNIX_PLUGIN_TIMEOUT_TEST) \ 470 $(UNIX_PLUGIN_TIMEOUT_TEST) \
471 $(UNIX_API_ABSTRACT_TEST) \
467 test_transport_api_udp_nat \ 472 test_transport_api_udp_nat \
468 $(HTTP_API_TEST) \ 473 $(HTTP_API_TEST) \
469 $(HTTP_API_TIMEOUT_TEST) \ 474 $(HTTP_API_TIMEOUT_TEST) \
@@ -886,6 +891,14 @@ test_transport_api_unix_LDADD = \
886 $(top_builddir)/src/util/libgnunetutil.la \ 891 $(top_builddir)/src/util/libgnunetutil.la \
887 $(top_builddir)/src/transport/libgnunettransporttesting.la 892 $(top_builddir)/src/transport/libgnunettransporttesting.la
888 893
894test_transport_api_unix_abstract_SOURCES = \
895 test_transport_api.c
896test_transport_api_unix_abstract_LDADD = \
897 $(top_builddir)/src/transport/libgnunettransport.la \
898 $(top_builddir)/src/hello/libgnunethello.la \
899 $(top_builddir)/src/util/libgnunetutil.la \
900 $(top_builddir)/src/transport/libgnunettransporttesting.la
901
889# HTTP tests 902# HTTP tests
890test_transport_api_http_SOURCES = \ 903test_transport_api_http_SOURCES = \
891 test_transport_api.c 904 test_transport_api.c
@@ -1197,6 +1210,8 @@ test_transport_api_timeout_udp_peer1.conf\
1197test_transport_api_timeout_udp_peer2.conf\ 1210test_transport_api_timeout_udp_peer2.conf\
1198test_transport_api_unix_peer1.conf\ 1211test_transport_api_unix_peer1.conf\
1199test_transport_api_unix_peer2.conf\ 1212test_transport_api_unix_peer2.conf\
1213test_transport_api_unix_abstract_peer1.conf \
1214test_transport_api_unix_abstract_peer2.conf \
1200test_transport_api_timeout_unix_peer1.conf\ 1215test_transport_api_timeout_unix_peer1.conf\
1201test_transport_api_timeout_unix_peer2.conf\ 1216test_transport_api_timeout_unix_peer2.conf\
1202test_transport_api_timeout_wlan_peer1.conf \ 1217test_transport_api_timeout_wlan_peer1.conf \
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c
index ec0956c0b..7bffa220d 100644
--- a/src/transport/plugin_transport_unix.c
+++ b/src/transport/plugin_transport_unix.c
@@ -45,6 +45,13 @@
45 45
46#define PLUGIN_NAME "unix" 46#define PLUGIN_NAME "unix"
47 47
48enum UNIX_ADDRESS_OPTIONS
49{
50 UNIX_OPTIONS_NONE = 0,
51 UNIX_OPTIONS_USE_ABSTRACT_SOCKETS = 1
52};
53
54
48/** 55/**
49 * How long until we give up on transmitting the welcome message? 56 * How long until we give up on transmitting the welcome message?
50 */ 57 */
@@ -81,12 +88,6 @@ struct UNIXMessage
81}; 88};
82 89
83GNUNET_NETWORK_STRUCT_END 90GNUNET_NETWORK_STRUCT_END
84
85/**
86 * Address options
87 */
88static uint32_t myoptions;
89
90/** 91/**
91 * Handle for a session. 92 * Handle for a session.
92 */ 93 */
@@ -298,6 +299,12 @@ struct Plugin
298 struct UNIX_Sock_Info unix_sock; 299 struct UNIX_Sock_Info unix_sock;
299 300
300 /** 301 /**
302 * Address options in HBO
303 */
304 uint32_t myoptions;
305
306
307 /**
301 * ATS network 308 * ATS network
302 */ 309 */
303 struct GNUNET_ATS_Information ats_network; 310 struct GNUNET_ATS_Information ats_network;
@@ -309,6 +316,7 @@ struct Plugin
309 */ 316 */
310 int with_ws; 317 int with_ws;
311 318
319 int abstract;
312}; 320};
313 321
314 322
@@ -332,6 +340,29 @@ reschedule_session_timeout (struct Session *s);
332static void 340static void
333unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 341unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
334 342
343static struct sockaddr_un *
344unix_address_to_sockaddr (const char *unixpath,
345 socklen_t *sock_len)
346{
347 struct sockaddr_un *un;
348 size_t slen;
349
350 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
351 un = GNUNET_new (struct sockaddr_un);
352 un->sun_family = AF_UNIX;
353 slen = strlen (unixpath);
354 if (slen >= sizeof (un->sun_path))
355 slen = sizeof (un->sun_path) - 1;
356 memcpy (un->sun_path, unixpath, slen);
357 un->sun_path[slen] = '\0';
358 slen = sizeof (struct sockaddr_un);
359#if HAVE_SOCKADDR_IN_SIN_LEN
360 un->sun_len = (u_char) slen;
361#endif
362 (*sock_len) = slen;
363 return un;
364}
365
335 366
336/** 367/**
337 * Function called for a quick conversion of the binary address to 368 * Function called for a quick conversion of the binary address to
@@ -351,6 +382,7 @@ unix_address_to_string (void *cls, const void *addr, size_t addrlen)
351 struct UnixAddress *ua = (struct UnixAddress *) addr; 382 struct UnixAddress *ua = (struct UnixAddress *) addr;
352 char *addrstr; 383 char *addrstr;
353 size_t addr_str_len; 384 size_t addr_str_len;
385 unsigned int off;
354 386
355 if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen)) 387 if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen))
356 { 388 {
@@ -377,46 +409,23 @@ unix_address_to_string (void *cls, const void *addr, size_t addrlen)
377 return NULL ; 409 return NULL ;
378 } 410 }
379 411
412 off = 0;
413 if ('\0' == addrstr[0])
414 off++;
415 memset (rbuf, 0, sizeof (rbuf));
416 GNUNET_snprintf (rbuf, sizeof (rbuf) - 1, "%s.%u.%s%.*s",
417 PLUGIN_NAME,
418 ntohl (ua->options),
419 (off == 1) ? "@" : "",
420 (int) (addr_str_len - off),
421 &addrstr[off]);
422/*
380 GNUNET_snprintf (rbuf, sizeof(rbuf), "%s.%u.%s", PLUGIN_NAME, 423 GNUNET_snprintf (rbuf, sizeof(rbuf), "%s.%u.%s", PLUGIN_NAME,
381 ntohl (ua->options), addrstr); 424 ntohl (ua->options), addrstr);*/
382 return rbuf; 425 return rbuf;
383} 426}
384 427
385 428
386static struct sockaddr_un *
387unix_address_to_sockaddr (const struct GNUNET_CONFIGURATION_Handle *cfg,
388 const char *unixpath,
389 socklen_t *sock_len)
390{
391 struct sockaddr_un *un;
392 size_t slen;
393
394 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
395 un = GNUNET_new (struct sockaddr_un);
396 un->sun_family = AF_UNIX;
397 slen = strlen (unixpath);
398 if (slen >= sizeof (un->sun_path))
399 slen = sizeof (un->sun_path) - 1;
400 memcpy (un->sun_path, unixpath, slen);
401 un->sun_path[slen] = '\0';
402#ifdef LINUX
403 {
404 int abstract;
405
406 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
407 "TESTING",
408 "USE_ABSTRACT_SOCKETS");
409 if (GNUNET_YES == abstract)
410 un->sun_path[0] = '\0';
411 }
412#endif
413 slen = sizeof (struct sockaddr_un);
414#if HAVE_SOCKADDR_IN_SIN_LEN
415 un->sun_len = (u_char) slen;
416#endif
417 (*sock_len) = slen;
418 return un;
419}
420 429
421 430
422/** 431/**
@@ -645,14 +654,18 @@ unix_real_send (void *cls,
645 654
646 /* Prepare address */ 655 /* Prepare address */
647 unixpath = (const char *) &addr[1]; 656 unixpath = (const char *) &addr[1];
648 if (NULL == (un = unix_address_to_sockaddr (plugin->env->cfg, 657 if (NULL == (un = unix_address_to_sockaddr (unixpath,
649 unixpath,
650 &un_len))) 658 &un_len)))
651 { 659 {
652 GNUNET_break (0); 660 GNUNET_break (0);
653 return -1; 661 return -1;
654 } 662 }
655 663
664 if ((GNUNET_YES == plugin->abstract) &&
665 (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl(addr->options) )) )
666 {
667 un->sun_path[0] = '\0';
668 }
656resend: 669resend:
657 /* Send the data */ 670 /* Send the data */
658 sent = GNUNET_NETWORK_socket_sendto (send_handle, msgbuf, msgbuf_size, 671 sent = GNUNET_NETWORK_socket_sendto (send_handle, msgbuf, msgbuf_size,
@@ -811,6 +824,7 @@ unix_plugin_get_session (void *cls,
811 struct UnixAddress *ua; 824 struct UnixAddress *ua;
812 char * addrstr; 825 char * addrstr;
813 uint32_t addr_str_len; 826 uint32_t addr_str_len;
827 uint32_t addr_option;
814 828
815 GNUNET_assert (NULL != plugin); 829 GNUNET_assert (NULL != plugin);
816 GNUNET_assert (NULL != address); 830 GNUNET_assert (NULL != address);
@@ -822,14 +836,21 @@ unix_plugin_get_session (void *cls,
822 GNUNET_break (0); 836 GNUNET_break (0);
823 return NULL; 837 return NULL;
824 } 838 }
825 addrstr = (char *) &ua[1]; 839 addrstr = (char *) &ua[1];
826 addr_str_len = ntohl (ua->addrlen); 840 addr_str_len = ntohl (ua->addrlen);
827 if (addr_str_len != address->address_length - sizeof (struct UnixAddress)) 841 addr_option = ntohl (ua->options);
842
843 if ( (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) &&
844 (GNUNET_NO == plugin->abstract))
828 { 845 {
829 /* This can be a legacy address */
830 return NULL; 846 return NULL;
831 } 847 }
832 848
849 if (addr_str_len != address->address_length - sizeof (struct UnixAddress))
850 {
851 return NULL; /* This can be a legacy address */
852 }
853
833 if ('\0' != addrstr[addr_str_len - 1]) 854 if ('\0' != addrstr[addr_str_len - 1])
834 { 855 {
835 GNUNET_break (0); 856 GNUNET_break (0);
@@ -1045,6 +1066,7 @@ unix_plugin_select_read (struct Plugin *plugin)
1045 ssize_t ret; 1066 ssize_t ret;
1046 int offset; 1067 int offset;
1047 int tsize; 1068 int tsize;
1069 int is_abstract;
1048 char *msgbuf; 1070 char *msgbuf;
1049 const struct GNUNET_MessageHeader *currhdr; 1071 const struct GNUNET_MessageHeader *currhdr;
1050 uint16_t csize; 1072 uint16_t csize;
@@ -1074,11 +1096,21 @@ unix_plugin_select_read (struct Plugin *plugin)
1074 } 1096 }
1075 1097
1076 GNUNET_assert (AF_UNIX == (un.sun_family)); 1098 GNUNET_assert (AF_UNIX == (un.sun_family));
1099 is_abstract = GNUNET_NO;
1100 if ('\0' == un.sun_path[0])
1101 {
1102 un.sun_path[0] = '@';
1103 is_abstract = GNUNET_YES;
1104 }
1105
1077 ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1; 1106 ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1;
1078 ua = GNUNET_malloc (ua_len); 1107 ua = GNUNET_malloc (ua_len);
1079 ua->addrlen = htonl (strlen (&un.sun_path[0]) +1); 1108 ua->addrlen = htonl (strlen (&un.sun_path[0]) +1);
1080 ua->options = htonl (0);
1081 memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1); 1109 memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1);
1110 if (is_abstract)
1111 ua->options = htonl(UNIX_OPTIONS_USE_ABSTRACT_SOCKETS);
1112 else
1113 ua->options = htonl(UNIX_OPTIONS_NONE);
1082 1114
1083 msg = (struct UNIXMessage *) buf; 1115 msg = (struct UNIXMessage *) buf;
1084 csize = ntohs (msg->header.size); 1116 csize = ntohs (msg->header.size);
@@ -1266,9 +1298,13 @@ unix_transport_server_start (void *cls)
1266 struct sockaddr_un *un; 1298 struct sockaddr_un *un;
1267 socklen_t un_len; 1299 socklen_t un_len;
1268 1300
1269 un = unix_address_to_sockaddr (plugin->env->cfg, 1301 un = unix_address_to_sockaddr (plugin->unix_socket_path,
1270 plugin->unix_socket_path,
1271 &un_len); 1302 &un_len);
1303 if (GNUNET_YES == plugin->abstract)
1304 {
1305 plugin->unix_socket_path[0] = '@';
1306 un->sun_path[0] = '\0';
1307 }
1272 plugin->ats_network = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) un, un_len); 1308 plugin->ats_network = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) un, un_len);
1273 plugin->unix_sock.desc = 1309 plugin->unix_sock.desc =
1274 GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); 1310 GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
@@ -1487,12 +1523,14 @@ address_notification (void *cls,
1487 struct GNUNET_HELLO_Address *address; 1523 struct GNUNET_HELLO_Address *address;
1488 size_t len; 1524 size_t len;
1489 struct UnixAddress *ua; 1525 struct UnixAddress *ua;
1526 char *unix_path;
1490 1527
1491 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; 1528 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
1492 ua = GNUNET_malloc (len); 1529 ua = GNUNET_malloc (len);
1493 ua->options = htonl (myoptions); 1530 ua->options = htonl (plugin->myoptions);
1494 ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1); 1531 ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1);
1495 memcpy (&ua[1], plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1); 1532 unix_path = (char *) &ua[1];
1533 memcpy (unix_path, plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1);
1496 1534
1497 plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK; 1535 plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK;
1498 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 1536 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
@@ -1608,7 +1646,15 @@ libgnunet_plugin_transport_unix_init (void *cls)
1608 plugin->env = env; 1646 plugin->env = env;
1609 1647
1610 /* Initialize my flags */ 1648 /* Initialize my flags */
1611 myoptions = 0; 1649#ifdef LINUX
1650 plugin->abstract = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
1651 "testing", "USE_ABSTRACT_SOCKETS");
1652#endif
1653 plugin->myoptions = UNIX_OPTIONS_NONE;
1654 if (GNUNET_YES == plugin->abstract)
1655 {
1656 plugin->myoptions = UNIX_OPTIONS_USE_ABSTRACT_SOCKETS;
1657 }
1612 1658
1613 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 1659 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
1614 api->cls = plugin; 1660 api->cls = plugin;
@@ -1658,7 +1704,7 @@ libgnunet_plugin_transport_unix_done (void *cls)
1658 1704
1659 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; 1705 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1;
1660 ua = GNUNET_malloc (len); 1706 ua = GNUNET_malloc (len);
1661 ua->options = htonl (myoptions); 1707 ua->options = htonl (plugin->myoptions);
1662 ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1); 1708 ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1);
1663 memcpy (&ua[1], plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1); 1709 memcpy (&ua[1], plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1);
1664 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 1710 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
diff --git a/src/transport/test_transport_api_unix_abstract_peer1.conf b/src/transport/test_transport_api_unix_abstract_peer1.conf
new file mode 100644
index 000000000..aea61113d
--- /dev/null
+++ b/src/transport/test_transport_api_unix_abstract_peer1.conf
@@ -0,0 +1,31 @@
1@INLINE@ template_cfg_peer1.conf
2[PATHS]
3GNUNET_TEST_HOME = /tmp/test-transport/api-unix-p1/
4
5[arm]
6PORT = 12125
7UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-arm.sock
8
9[statistics]
10PORT = 12124
11UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-statistics.sock
12
13[resolver]
14PORT = 12123
15UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-resolver.sock
16
17[peerinfo]
18PORT = 12122
19UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-peerinfo.sock
20
21[transport]
22PORT = 12121
23PLUGINS = unix
24UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-transport.sock
25
26[transport-unix]
27PORT = 12120
28
29[testing]
30USE_ABSTRACT_SOCKETS = YES
31
diff --git a/src/transport/test_transport_api_unix_abstract_peer2.conf b/src/transport/test_transport_api_unix_abstract_peer2.conf
new file mode 100644
index 000000000..3adbd7fd0
--- /dev/null
+++ b/src/transport/test_transport_api_unix_abstract_peer2.conf
@@ -0,0 +1,31 @@
1@INLINE@ template_cfg_peer2.conf
2[PATHS]
3GNUNET_TEST_HOME = /tmp/test-transport/api-unix-p2/
4
5[arm]
6PORT = 12135
7UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-arm.sock
8
9[statistics]
10PORT = 12134
11UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-statistics.sock
12
13[resolver]
14PORT = 12133
15UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-resolver.sock
16
17[peerinfo]
18PORT = 12132
19UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-peerinfo.sock
20
21[transport]
22PORT = 12131
23PLUGINS = unix
24UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-transport.sock
25
26[transport-unix]
27PORT = 12136
28
29[testing]
30USE_ABSTRACT_SOCKETS = YES
31