summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--TODO3
-rw-r--r--contrib/defaults.conf8
-rw-r--r--src/arm/gnunet-service-arm_interceptor.c10
-rw-r--r--src/core/test_core_api_peer1.conf5
-rw-r--r--src/core/test_core_api_peer2.conf6
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_peer1.conf6
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_peer2.conf8
-rw-r--r--src/include/gnunet_connection_lib.h23
-rw-r--r--src/include/platform.h1
-rw-r--r--src/testing/test_testing_connect_peer1.conf6
-rw-r--r--src/testing/test_testing_connect_peer2.conf6
-rw-r--r--src/testing/testing_group.c42
-rw-r--r--src/transport/test_transport_api_http_peer1.conf5
-rw-r--r--src/transport/test_transport_api_http_peer2.conf7
-rw-r--r--src/transport/test_transport_api_tcp_peer1.conf7
-rw-r--r--src/transport/test_transport_api_tcp_peer2.conf5
-rw-r--r--src/transport/test_transport_api_udp_nat_peer1.conf35
-rw-r--r--src/transport/test_transport_api_udp_nat_peer2.conf38
-rw-r--r--src/transport/test_transport_api_udp_peer1.conf15
-rw-r--r--src/transport/test_transport_api_udp_peer2.conf16
-rw-r--r--src/util/bandwidth.c2
-rw-r--r--src/util/client.c47
-rw-r--r--src/util/common_logging.c13
-rw-r--r--src/util/connection.c66
-rw-r--r--src/util/network.c11
-rw-r--r--src/util/service.c190
-rw-r--r--src/util/test_resolver_api.c2
28 files changed, 454 insertions, 133 deletions
diff --git a/ChangeLog b/ChangeLog
index 7cb118fbd..861d8bd25 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sat Jun 5 18:08:39 CEST 2010
+ Added support for UNIX domain sockets, code also defaults to
+ them when available.
+
Sun May 2 13:49:10 CEST 2010
Fixed problem with platform-dependence of format for IP addresses
in HELLOs for TCP and UDP transport.
diff --git a/TODO b/TODO
index 184c04a9f..e536258a4 100644
--- a/TODO
+++ b/TODO
@@ -21,7 +21,6 @@
* UTIL:
- only connect() sockets that are ready (select()) [Nils]
[On W32, we need to select after calling socket before doing connect etc.]
- - add support for UNIX domain sockets [CG]
* GNUNET-GTK:
- search events:
+ results
@@ -70,8 +69,8 @@
- better crash management (attach debugging support, capture and analyze
debug output, detect random vs. deterministic crashes)
- discover dependencies between services
- => need UNIX domain sockets first!
- handle gnunet-arm -k in combination with auto-start magic (what is the right thing here?)
+ - add listen socket forwarding to child processes on supported platforms
* FS: [CG]
- datastore reservation (publishing)
- location URIs (publish, search, download)
diff --git a/contrib/defaults.conf b/contrib/defaults.conf
index b4a3ddd72..c250ebe87 100644
--- a/contrib/defaults.conf
+++ b/contrib/defaults.conf
@@ -36,6 +36,7 @@ BINARY = gnunet-service-arm
ACCEPT_FROM = 127.0.0.1;
ACCEPT_FROM6 = ::1;
DEFAULTSERVICES = resolver transport core topology hostlist
+UNIXPATH = /tmp/gnunet-service-arm.sock
# GLOBAL_POSTFIX = -l $SERVICEHOME/{}-logs
# GLOBAL_PREFIX =
# USERNAME =
@@ -56,6 +57,7 @@ CONFIG = $DEFAULTCONFIG
BINARY = gnunet-service-statistics
ACCEPT_FROM = 127.0.0.1;
ACCEPT_FROM6 = ::1;
+UNIXPATH = /tmp/gnunet-service-statistics.sock
# USERNAME =
# MAXBUF =
# TIMEOUT =
@@ -74,6 +76,7 @@ CONFIG = $DEFAULTCONFIG
BINARY = gnunet-service-resolver
ACCEPT_FROM = 127.0.0.1;
ACCEPT_FROM6 = ::1;
+UNIXPATH = /tmp/gnunet-service-resolver.sock
# USERNAME =
# MAXBUF =
# TIMEOUT =
@@ -92,6 +95,7 @@ CONFIG = $DEFAULTCONFIG
BINARY = gnunet-service-peerinfo
ACCEPT_FROM = 127.0.0.1;
ACCEPT_FROM6 = ::1;
+UNIXPATH = /tmp/gnunet-service-peerinfo.sock
# USERNAME =
# MAXBUF =
# TIMEOUT =
@@ -115,6 +119,7 @@ NEIGHBOUR_LIMIT = 50
ACCEPT_FROM = 127.0.0.1;
ACCEPT_FROM6 = ::1;
PLUGINS = tcp
+UNIXPATH = /tmp/gnunet-service-transport.sock
# USERNAME =
# MAXBUF =
# TIMEOUT =
@@ -136,6 +141,7 @@ ACCEPT_FROM6 = ::1;
# quotas are in bytes per second now!
TOTAL_QUOTA_IN = 65536
TOTAL_QUOTA_OUT = 65536
+UNIXPATH = /tmp/gnunet-service-core.sock
# DEBUG = YES
# USERNAME =
# MAXBUF =
@@ -172,6 +178,7 @@ HTTP-PROXY =
[datastore]
AUTOSTART = YES
+UNIXPATH = /tmp/gnunet-service-datastore.sock
PORT = 2093
HOSTNAME = localhost
HOME = $SERVICEHOME
@@ -199,5 +206,6 @@ BINARY = gnunet-service-fs
ACCEPT_FROM = 127.0.0.1;
ACCEPT_FROM6 = ::1;
ACTIVEMIGRATION = YES
+UNIXPATH = /tmp/gnunet-service-fs.sock
# DEBUG = YES
diff --git a/src/arm/gnunet-service-arm_interceptor.c b/src/arm/gnunet-service-arm_interceptor.c
index 10847c2ba..afefe4e48 100644
--- a/src/arm/gnunet-service-arm_interceptor.c
+++ b/src/arm/gnunet-service-arm_interceptor.c
@@ -936,15 +936,21 @@ createListeningSocket (struct sockaddr *sa,
case AF_INET6:
sock = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
break;
+ case AF_UNIX:
+ sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0);
+ break;
default:
+ GNUNET_break (0);
sock = NULL;
+ errno = EAFNOSUPPORT;
break;
}
if (NULL == sock)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to create socket for service `%s'"),
- serviceName);
+ _("Unable to create socket for service `%s': %s\n"),
+ serviceName,
+ STRERROR (errno));
GNUNET_free (sa);
return;
}
diff --git a/src/core/test_core_api_peer1.conf b/src/core/test_core_api_peer1.conf
index 21bb7481b..a33893a39 100644
--- a/src/core/test_core_api_peer1.conf
+++ b/src/core/test_core_api_peer1.conf
@@ -4,10 +4,12 @@ DEFAULTCONFIG = test_core_api_peer1.conf
[resolver]
PORT = 12464
+UNIXPATH = /tmp/gnunet-p1-service-resolver.sock
#PREFIX = xterm -T resolver1 -e valgrind --tool=memcheck
[transport]
PORT = 12465
+UNIXPATH = /tmp/gnunet-p1-service-transport.sock
PLUGINS = tcp
#PREFIX = xterm -T transport1 -e
#PREFIX= xterm -e xterm -T transport1 -e gdb --args
@@ -17,6 +19,7 @@ PLUGINS = tcp
[arm]
PORT = 12466
+UNIXPATH = /tmp/gnunet-p1-service-arm.sock
DEFAULTSERVICES =
#GLOBAL_PREFIX = xterm -e valgrind --tool=memcheck
@@ -31,12 +34,14 @@ BINDTO = 127.0.0.1
[peerinfo]
PORT = 12469
+UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
#PREFIX = xterm -T peerinfo1 -e valgrind --tool=memcheck
#PREFIX = xterm -T peerinfo1 -e
#DEBUG = YES
[core]
PORT = 12470
+UNIXPATH = /tmp/gnunet-p1-service-core.sock
#PREFIX = valgrind --tool=memcheck
#OPTIONS = -l log-core-1
#PREFIX = xterm -e xterm -T core1 -e gdb --args
diff --git a/src/core/test_core_api_peer2.conf b/src/core/test_core_api_peer2.conf
index 71a167e73..7389d68f6 100644
--- a/src/core/test_core_api_peer2.conf
+++ b/src/core/test_core_api_peer2.conf
@@ -4,10 +4,12 @@ DEFAULTCONFIG = test_core_api_peer2.conf
[resolver]
PORT = 22464
+UNIXPATH = /tmp/gnunet-p2-service-resolver.sock
#PREFIX = xterm -T resolver2 -e valgrind --tool=memcheck
[transport]
PORT = 22465
+UNIXPATH = /tmp/gnunet-p2-service-transport.sock
PLUGINS = tcp
#PREFIX = xterm -T transport2 -e gdb --args
#PREFIX = xterm -e xterm -T transport2 -e gdb --args
@@ -17,11 +19,13 @@ PLUGINS = tcp
[arm]
PORT = 22466
+UNIXPATH = /tmp/gnunet-p2-service-arm.sock
DEFAULTSERVICES =
#GLOBAL_PREFIX = xterm -e valgrind --tool=memcheck
[statistics]
PORT = 22467
+UNIXPATH = /tmp/gnunet-p2-service-statistics.sock
#PREFIX = xterm -T statistics2 -e valgrind --tool=memcheck
[transport-tcp]
@@ -31,12 +35,14 @@ BINDTO = 127.0.0.1
[peerinfo]
PORT = 22469
+UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock
#PREFIX = xterm -T peerinfo2 -e valgrind --tool=memcheck
#PREFIX = xterm -T peerinfo2 -e
#DEBUG = YES
[core]
PORT = 22470
+UNIXPATH = /tmp/gnunet-p2-service-core.sock
#PREFIX = xterm -T core2 -e
#PREFIX = valgrind --tool=memcheck
#DEBUG = YES
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf b/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf
index 19874f022..be5db7582 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf
+++ b/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf
@@ -4,20 +4,24 @@ DEFAULTCONFIG = test_gnunet_daemon_hostlist_peer1.conf
[resolver]
PORT = 12964
+UNIXPATH = /tmp/gnunet-p1-service-resolver.sock
[transport]
PORT = 12965
+UNIXPATH = /tmp/gnunet-p1-service-transport.sock
PLUGINS = tcp
#DEBUG = YES
DEBUG = NO
[arm]
PORT = 12966
+UNIXPATH = /tmp/gnunet-p1-service-arm.sock
DEFAULTSERVICES = hostlist topology
#GLOBAL_PREFIX = xterm -e gdb -x cmd --args
[statistics]
PORT = 12967
+UNIXPATH = /tmp/gnunet-p1-service-statistics.sock
[transport-tcp]
PORT = 12968
@@ -25,9 +29,11 @@ DEBUG = NO
[peerinfo]
PORT = 12969
+UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
[core]
PORT = 12970
+UNIXPATH = /tmp/gnunet-p1-service-core.sock
#DEBUG = YES
#PREFIX = valgrind --tool=memcheck\
DEBUG = NO
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf b/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf
index c256c2829..dd47a27e6 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf
+++ b/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf
@@ -4,21 +4,25 @@ DEFAULTCONFIG = test_gnunet_daemon_hostlist_peer2.conf
[resolver]
PORT = 22964
+UNIXPATH = /tmp/gnunet-p2-service-resolver.sock
DEBUG = NO
[transport]
PORT = 22965
+UNIXPATH = /tmp/gnunet-p2-service-transport.sock
PLUGINS = tcp
DEBUG = NO
[arm]
PORT = 22966
+UNIXPATH = /tmp/gnunet-p2-service-arm.sock
DEFAULTSERVICES = hostlist topology
#GLOBAL_PREFIX = xterm -e gdb -x cmd --args
DEBUG = NO
[statistics]
PORT = 22967
+UNIXPATH = /tmp/gnunet-p2-service-statistics.sock
[transport-tcp]
PORT = 22968
@@ -26,9 +30,11 @@ DEBUG = NO
[peerinfo]
PORT = 22969
+UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock
[core]
PORT = 22970
+UNIXPATH = /tmp/gnunet-p2-service-core.sock
DEBUG = NO
#PREFIX = valgrind --tool=memcheck
@@ -52,4 +58,4 @@ DEBUG = NO
AUTOSTART = NO
[datastore]
-AUTOSTART = NO \ No newline at end of file
+AUTOSTART = NO
diff --git a/src/include/gnunet_connection_lib.h b/src/include/gnunet_connection_lib.h
index 9701eb149..1230c10c8 100644
--- a/src/include/gnunet_connection_lib.h
+++ b/src/include/gnunet_connection_lib.h
@@ -155,7 +155,28 @@ struct GNUNET_CONNECTION_Handle
const struct GNUNET_CONFIGURATION_Handle *cfg,
const char *hostname,
uint16_t port,
- size_t maxbuf);
+ size_t maxbuf);
+
+
+/**
+ * Create a socket handle by connecting to a UNIX domain service.
+ * This function returns immediately, even if the connection has not
+ * yet been established. This function only creates UNIX connections.
+ *
+ * @param sched scheduler to use
+ * @param cfg configuration to use
+ * @param unixpath path to connect to
+ * @param maxbuf maximum write buffer size for the socket (use
+ * 0 for sockets that need no write buffers, such as listen sockets)
+ * @return the socket handle, NULL on systems without UNIX support
+ */
+struct GNUNET_CONNECTION_Handle *
+GNUNET_CONNECTION_create_from_connect_to_unixpath (struct GNUNET_SCHEDULER_Handle *sched,
+ const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ const char *unixpath,
+ size_t maxbuf);
+
diff --git a/src/include/platform.h b/src/include/platform.h
index 0d39eaf10..fb9c992ec 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -82,6 +82,7 @@
#ifndef MINGW
#include <netdb.h>
#include <sys/socket.h>
+#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/ip.h> /* superset of previous */
#include <arpa/inet.h>
diff --git a/src/testing/test_testing_connect_peer1.conf b/src/testing/test_testing_connect_peer1.conf
index 76e5ee536..9b240c855 100644
--- a/src/testing/test_testing_connect_peer1.conf
+++ b/src/testing/test_testing_connect_peer1.conf
@@ -4,10 +4,12 @@ DEFAULTCONFIG = test_testing_connect_peer1.conf
[resolver]
PORT = 12564
+UNIXPATH = /tmp/gnunet-p1-service-resolver.sock
HOSTNAME = localhost
[transport]
PORT = 12565
+UNIXPATH = /tmp/gnunet-p1-service-transport.sock
HOSTNAME = localhost
PLUGINS = tcp
#PREFIX = xterm -e xterm -T transport -e gdb -x cmd --args
@@ -15,12 +17,14 @@ PLUGINS = tcp
[arm]
PORT = 12566
+UNIXPATH = /tmp/gnunet-p1-service-arm.sock
HOSTNAME = localhost
DEFAULTSERVICES =
#DEBUG = YES
[statistics]
PORT = 12567
+UNIXPATH = /tmp/gnunet-p1-service-statistics.sock
HOSTNAME = localhost
[transport-tcp]
@@ -28,10 +32,12 @@ PORT = 12568
[peerinfo]
PORT = 12569
+UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
HOSTNAME = localhost
[core]
PORT = 12570
+UNIXPATH = /tmp/gnunet-p1-service-core.sock
HOSTNAME = localhost
#DEBUG = YES
diff --git a/src/testing/test_testing_connect_peer2.conf b/src/testing/test_testing_connect_peer2.conf
index 5e8ae7a18..5d4237343 100644
--- a/src/testing/test_testing_connect_peer2.conf
+++ b/src/testing/test_testing_connect_peer2.conf
@@ -4,10 +4,12 @@ DEFAULTCONFIG = test_testing_connect_peer2.conf
[resolver]
PORT = 22564
+UNIXPATH = /tmp/gnunet-p2-service-resolver.sock
HOSTNAME = localhost
[transport]
PORT = 22565
+UNIXPATH = /tmp/gnunet-p2-service-transport.sock
HOSTNAME = localhost
PLUGINS = tcp
#PREFIX = xterm -e xterm -T transport -e gdb -x cmd --args
@@ -15,12 +17,14 @@ PLUGINS = tcp
[arm]
PORT = 22566
+UNIXPATH = /tmp/gnunet-p2-service-arm.sock
DEFAULTSERVICES =
HOSTNAME = localhost
#DEBUG = YES
[statistics]
PORT = 22567
+UNIXPATH = /tmp/gnunet-p2-service-statistics.sock
HOSTNAME = localhost
[transport-tcp]
@@ -28,10 +32,12 @@ PORT = 22568
[peerinfo]
PORT = 22569
+UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock
HOSTNAME = localhost
[core]
PORT = 22570
+UNIXPATH = /tmp/gnunet-p2-service-core.sock
HOSTNAME = localhost
#DEBUG = YES
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index bf90ea4b0..2920594c5 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -313,8 +313,9 @@ uid_from_hash (const GNUNET_HashCode *hash, uint32_t *uid)
struct UpdateContext
{
struct GNUNET_CONFIGURATION_Handle *ret;
- unsigned int nport;
const char *hostname;
+ unsigned int nport;
+ unsigned int upnum;
};
@@ -351,11 +352,25 @@ update_config (void *cls,
struct UpdateContext *ctx = cls;
unsigned int ival;
char cval[12];
+ char uval[128];
if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival)))
{
- GNUNET_snprintf (cval, sizeof (cval), "%u", ctx->nport++);
- value = cval;
+ if (ival != 0)
+ {
+ GNUNET_snprintf (cval, sizeof (cval), "%u", ctx->nport++);
+ value = cval;
+ }
+ }
+
+ if (0 == strcmp (option, "UNIXPATH"))
+ {
+ GNUNET_snprintf (uval,
+ sizeof (uval),
+ "/tmp/test-service-%s-%u",
+ section,
+ ctx->upnum++);
+ value = uval;
}
if ((0 == strcmp (option, "HOSTNAME")) && (ctx->hostname != NULL))
@@ -376,12 +391,16 @@ update_config (void *cls,
* @param cfg template configuration
* @param port port numbers to use, update to reflect
* port numbers that were used
+ * @param upnum number to make unix domain socket names unique
* @param hostname hostname of the controlling host, to allow control connections from
*
* @return new configuration, NULL on error
*/
static struct GNUNET_CONFIGURATION_Handle *
-make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t * port, const char *hostname)
+make_config (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ uint16_t * port,
+ uint32_t * upnum,
+ const char *hostname)
{
struct UpdateContext uc;
uint16_t orig;
@@ -390,6 +409,7 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t * port, con
orig = *port;
uc.nport = *port;
+ uc.upnum = *upnum;
uc.ret = GNUNET_CONFIGURATION_create ();
uc.hostname = hostname;
@@ -420,6 +440,7 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t * port, con
}
*port = (uint16_t) uc.nport;
+ *upnum = uc.upnum;
return uc.ret;
}
@@ -2499,13 +2520,14 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
unsigned int off;
unsigned int hostcnt;
uint16_t minport;
+ uint32_t upnum;
if (0 == total)
{
GNUNET_break (0);
return NULL;
}
-
+ upnum = 0;
pg = GNUNET_malloc (sizeof (struct GNUNET_TESTING_PeerGroup));
pg->sched = sched;
pg->cfg = cfg;
@@ -2571,12 +2593,18 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
if (hostcnt > 0)
{
hostname = pg->hosts[off % hostcnt].hostname;
- pcfg = make_config (cfg, &pg->hosts[off % hostcnt].minport, hostname);
+ pcfg = make_config (cfg,
+ &pg->hosts[off % hostcnt].minport,
+ &upnum,
+ hostname);
}
else
{
hostname = NULL;
- pcfg = make_config (cfg, &minport, hostname);
+ pcfg = make_config (cfg,
+ &minport,
+ &upnum,
+ hostname);
}
if (NULL == pcfg)
diff --git a/src/transport/test_transport_api_http_peer1.conf b/src/transport/test_transport_api_http_peer1.conf
index 539e9ab6c..793e12cc0 100644
--- a/src/transport/test_transport_api_http_peer1.conf
+++ b/src/transport/test_transport_api_http_peer1.conf
@@ -40,6 +40,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12365
+UNIXPATH = /tmp/gnunet-p1-service-transport.sock
[peerinfo]
TRUST = $SERVICEHOME/data/credit/
@@ -51,6 +52,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12369
+UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
[resolver]
ACCEPT_FROM6 = ::1;
@@ -60,6 +62,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12364
+UNIXPATH = /tmp/gnunet-p1-service-resolver.sock
[statistics]
ACCEPT_FROM6 = ::1;
@@ -69,6 +72,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12367
+UNIXPATH = /tmp/gnunet-p1-service-statistics.sock
[arm]
DEFAULTSERVICES =
@@ -79,6 +83,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12366
+UNIXPATH = /tmp/gnunet-p1-service-arm.sock
[transport-http]
PORT = 12389
diff --git a/src/transport/test_transport_api_http_peer2.conf b/src/transport/test_transport_api_http_peer2.conf
index 1cbe8cae0..00b90358f 100644
--- a/src/transport/test_transport_api_http_peer2.conf
+++ b/src/transport/test_transport_api_http_peer2.conf
@@ -43,6 +43,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22365
+UNIXPATH = /tmp/gnunet-p2-service-transport.sock
#PREFIX = xterm -T transport1 -e gdb --command=cmd --args
#PREFIX = valgrind --leak-check=full
@@ -56,6 +57,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22369
+UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock
[resolver]
ACCEPT_FROM6 = ::1;
@@ -65,6 +67,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22364
+UNIXPATH = /tmp/gnunet-p2-service-resolver.sock
[statistics]
ACCEPT_FROM6 = ::1;
@@ -74,6 +77,8 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22367
+UNIXPATH = /tmp/gnunet-p2-service-statistics.sock
+
[arm]
DEFAULTSERVICES =
@@ -84,6 +89,8 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22366
+UNIXPATH = /tmp/gnunet-p2-service-arm.sock
+
[transport-http]
PORT = 22389
diff --git a/src/transport/test_transport_api_tcp_peer1.conf b/src/transport/test_transport_api_tcp_peer1.conf
index 97e2111c8..f5bdc2063 100644
--- a/src/transport/test_transport_api_tcp_peer1.conf
+++ b/src/transport/test_transport_api_tcp_peer1.conf
@@ -43,6 +43,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12365
+UNIXPATH = /tmp/gnunet-p1-service-transport.sock
[peerinfo]
TRUST = $SERVICEHOME/data/credit/
@@ -54,6 +55,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12369
+UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
[resolver]
ACCEPT_FROM6 = ::1;
@@ -62,7 +64,8 @@ BINARY = gnunet-service-resolver
CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
-PORT = 12364
+PORT = 1236
+UNIXPATH = /tmp/gnunet-p1-service-resolver.sock
[statistics]
ACCEPT_FROM6 = ::1;
@@ -72,6 +75,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12367
+UNIXPATH = /tmp/gnunet-p1-service-statistics.sock
[arm]
DEFAULTSERVICES = transport statistics
@@ -82,6 +86,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12366
+UNIXPATH = /tmp/gnunet-p1-service-arm.sock
[transport-tcp]
TIMEOUT = 300000
diff --git a/src/transport/test_transport_api_tcp_peer2.conf b/src/transport/test_transport_api_tcp_peer2.conf
index f6ab6c231..f2c22e336 100644
--- a/src/transport/test_transport_api_tcp_peer2.conf
+++ b/src/transport/test_transport_api_tcp_peer2.conf
@@ -42,6 +42,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22365
+UNIXPATH = /tmp/gnunet-p2-service-transport.sock
#PREFIX = xterm -T transport1 -e gdb --command=cmd --args
#PREFIX = valgrind --leak-check=full
@@ -55,6 +56,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22369
+UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock
[resolver]
ACCEPT_FROM6 = ::1;
@@ -64,6 +66,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22364
+UNIXPATH = /tmp/gnunet-p2-service-resolver.sock
[statistics]
ACCEPT_FROM6 = ::1;
@@ -73,6 +76,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22367
+UNIXPATH = /tmp/gnunet-p2-service-statistics.sock
[arm]
DEFAULTSERVICES = transport statistics
@@ -83,6 +87,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22366
+UNIXPATH = /tmp/gnunet-p2-service-arm.sock
[transport-tcp]
TIMEOUT = 300000
diff --git a/src/transport/test_transport_api_udp_nat_peer1.conf b/src/transport/test_transport_api_udp_nat_peer1.conf
index d2ab3ecee..0956c83eb 100644
--- a/src/transport/test_transport_api_udp_nat_peer1.conf
+++ b/src/transport/test_transport_api_udp_nat_peer1.conf
@@ -5,29 +5,13 @@ INTERNAL_ADDRESS = 127.0.0.1
EXTERNAL_ADDRESS = 127.0.0.1
[fs]
-ACCEPT_FROM6 = ::1;
-ACCEPT_FROM = 127.0.0.1;
-BINARY = gnunet-service-fs
-CONFIG = $DEFAULTCONFIG
-HOME = $SERVICEHOME
-HOSTNAME = localhost
-PORT = 2094
-INDEXDB = $SERVICEHOME/idxinfo.lst
+AUTOSTART = NO
[datastore-sqlite]
FILENAME = $SERVICEHOME/datastore/sqlite.db
[datastore]
-DATABASE = sqlite
-BLOOMFILTER = $SERVICEHOME/fs/bloomfilter
-QUOTA = 100000000
-ACCEPT_FROM6 = ::1;
-ACCEPT_FROM = 127.0.0.1;
-BINARY = gnunet-service-datastore
-CONFIG = $DEFAULTCONFIG
-HOME = $SERVICEHOME
-HOSTNAME = localhost
-PORT = 2093
+AUTOSTART = NO
[hostlist]
HTTP-PROXY =
@@ -49,15 +33,7 @@ FRIENDS-ONLY = NO
MINIMUM-FRIENDS = 0
[core]
-TOTAL_QUOTA_OUT = 3932160
-TOTAL_QUOTA_IN = 3932160
-ACCEPT_FROM6 = ::1;
-ACCEPT_FROM = 127.0.0.1;
-BINARY = gnunet-service-core
-CONFIG = $DEFAULTCONFIG
-HOME = $SERVICEHOME
-HOSTNAME = localhost
-PORT = 2092
+AUTOSTART = NO
[transport]
PLUGINS = udp_nat
@@ -70,6 +46,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12365
+UNIXPATH = /tmp/gnunet-p1-service-transport.sock
#PREFIX = valgrind --track-origins=yes --leak-check=full --log-file=valgrind_udp_peer1.log
#PREFIX = xterm -e xterm -T transport -e gdb --args
@@ -83,6 +60,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12369
+UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
[resolver]
ACCEPT_FROM6 = ::1;
@@ -92,6 +70,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12364
+UNIXPATH = /tmp/gnunet-p1-service-resolver.sock
[statistics]
ACCEPT_FROM6 = ::1;
@@ -101,6 +80,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12367
+UNIXPATH = /tmp/gnunet-p1-service-statistics.sock
[arm]
DEFAULTSERVICES =
@@ -111,6 +91,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12366
+UNIXPATH = /tmp/gnunet-p1-service-arm.sock
[transport-tcp]
TIMEOUT = 300000
diff --git a/src/transport/test_transport_api_udp_nat_peer2.conf b/src/transport/test_transport_api_udp_nat_peer2.conf
index 32d8cab23..3dc4d672b 100644
--- a/src/transport/test_transport_api_udp_nat_peer2.conf
+++ b/src/transport/test_transport_api_udp_nat_peer2.conf
@@ -5,29 +5,10 @@ EXTERNAL_ADDRESS = 127.0.0.1
INTERNAL_ADDRESS = 127.0.0.1
[fs]
-ACCEPT_FROM6 = ::1;
-ACCEPT_FROM = 127.0.0.1;
-BINARY = gnunet-service-fs
-CONFIG = $DEFAULTCONFIG
-HOME = $SERVICEHOME
-HOSTNAME = localhost
-PORT = 2094
-INDEXDB = $SERVICEHOME/idxinfo.lst
-
-[datastore-sqlite]
-FILENAME = $SERVICEHOME/datastore/sqlite.db
+AUTOSTART = NO
[datastore]
-DATABASE = sqlite
-BLOOMFILTER = $SERVICEHOME/fs/bloomfilter
-QUOTA = 100000000
-ACCEPT_FROM6 = ::1;
-ACCEPT_FROM = 127.0.0.1;
-BINARY = gnunet-service-datastore
-CONFIG = $DEFAULTCONFIG
-HOME = $SERVICEHOME
-HOSTNAME = localhost
-PORT = 2093
+AUTOSTART = NO
[hostlist]
HTTP-PROXY =
@@ -49,15 +30,7 @@ FRIENDS-ONLY = NO
MINIMUM-FRIENDS = 0
[core]
-TOTAL_QUOTA_OUT = 3932160
-TOTAL_QUOTA_IN = 3932160
-ACCEPT_FROM6 = ::1;
-ACCEPT_FROM = 127.0.0.1;
-BINARY = gnunet-service-core
-CONFIG = $DEFAULTCONFIG
-HOME = $SERVICEHOME
-HOSTNAME = localhost
-PORT = 2092
+AUTOSTART = NO
[transport]
PLUGINS = udp_nat
@@ -71,6 +44,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22365
+UNIXPATH = /tmp/gnunet-p2-service-transport.sock
#PREFIX = xterm -e xterm -T transport -e gdb --args
[peerinfo]
@@ -83,6 +57,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22369
+UNIXPATH = /tmp/gnunet-p2-service-peerinfo.sock
[resolver]
ACCEPT_FROM6 = ::1;
@@ -92,6 +67,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22364
+UNIXPATH = /tmp/gnunet-p2-service-resolver.sock
[statistics]
ACCEPT_FROM6 = ::1;
@@ -101,6 +77,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22367
+UNIXPATH = /tmp/gnunet-p2-service-statistics.sock
[arm]
DEFAULTSERVICES =
@@ -111,6 +88,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22366
+UNIXPATH = /tmp/gnunet-p2-service-arm.sock
[transport-tcp]
TIMEOUT = 300000
diff --git a/src/transport/test_transport_api_udp_peer1.conf b/src/transport/test_transport_api_udp_peer1.conf
index e1ff1644e..49efbff63 100644
--- a/src/transport/test_transport_api_udp_peer1.conf
+++ b/src/transport/test_transport_api_udp_peer1.conf
@@ -30,15 +30,7 @@ FRIENDS-ONLY = NO
MINIMUM-FRIENDS = 0
[core]
-TOTAL_QUOTA_OUT = 3932160
-TOTAL_QUOTA_IN = 3932160
-ACCEPT_FROM6 = ::1;
-ACCEPT_FROM = 127.0.0.1;
-BINARY = gnunet-service-core
-CONFIG = $DEFAULTCONFIG
-HOME = $SERVICEHOME
-HOSTNAME = localhost
-PORT = 2092
+AUTOSTART = NO
[transport]
PLUGINS = udp
@@ -51,6 +43,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12365
+UNIXPATH = /tmp/gnunet-p1-service-transport.sock
#PREFIX = valgrind --track-origins=yes --leak-check=full --log-file=valgrind_udp_peer1.log
#PREFIX = xterm -e xterm -T transport -e gdb --args
@@ -64,6 +57,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12369
+UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
[resolver]
ACCEPT_FROM6 = ::1;
@@ -73,6 +67,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12364
+UNIXPATH = /tmp/gnunet-p1-service-resolver.sock
[statistics]
ACCEPT_FROM6 = ::1;
@@ -82,6 +77,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12367
+UNIXPATH = /tmp/gnunet-p1-service-statistics.sock
[arm]
DEFAULTSERVICES =
@@ -92,6 +88,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 12366
+UNIXPATH = /tmp/gnunet-p1-service-arm.sock
[transport-tcp]
TIMEOUT = 300000
diff --git a/src/transport/test_transport_api_udp_peer2.conf b/src/transport/test_transport_api_udp_peer2.conf
index cb4d4778d..2259e23f7 100644
--- a/src/transport/test_transport_api_udp_peer2.conf
+++ b/src/transport/test_transport_api_udp_peer2.conf
@@ -29,17 +29,6 @@ AUTOCONNECT = YES
FRIENDS-ONLY = NO
MINIMUM-FRIENDS = 0
-[core]
-TOTAL_QUOTA_OUT = 3932160
-TOTAL_QUOTA_IN = 3932160
-ACCEPT_FROM6 = ::1;
-ACCEPT_FROM = 127.0.0.1;
-BINARY = gnunet-service-core
-CONFIG = $DEFAULTCONFIG
-HOME = $SERVICEHOME
-HOSTNAME = localhost
-PORT = 2092
-
[transport]
PLUGINS = udp
DEBUG = NO
@@ -52,6 +41,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22365
+UNIXPATH = /tmp/gnunet-p1-service-transport.sock
#PREFIX = valgrind --track-origins=yes --leak-check=full --log-file=valgrind_udp_peer2.log
[peerinfo]
@@ -64,6 +54,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22369
+UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock
[resolver]
ACCEPT_FROM6 = ::1;
@@ -73,6 +64,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22364
+UNIXPATH = /tmp/gnunet-p1-service-resolver.sock
[statistics]
ACCEPT_FROM6 = ::1;
@@ -82,6 +74,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22367
+UNIXPATH = /tmp/gnunet-p1-service-statistics.sock
[arm]
DEFAULTSERVICES =
@@ -92,6 +85,7 @@ CONFIG = $DEFAULTCONFIG
HOME = $SERVICEHOME
HOSTNAME = localhost
PORT = 22366
+UNIXPATH = /tmp/gnunet-p1-service-arm.sock
[transport-tcp]
TIMEOUT = 300000
diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c
index 124cede9b..e47df4382 100644
--- a/src/util/bandwidth.c
+++ b/src/util/bandwidth.c
@@ -211,7 +211,7 @@ int
GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av,
ssize_t size)
{
- uint64_t nc;
+ int64_t nc;
#if DEBUG_BANDWIDTH
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/util/client.c b/src/util/client.c
index f964b7322..c7853d146 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -250,19 +250,55 @@ struct GNUNET_CLIENT_Connection
* Are we ignoring shutdown signals?
*/
int ignore_shutdown;
+
+ /**
+ * How often have we tried to connect?
+ */
+ unsigned int attempts;
};
+/**
+ * Try to connect to the service.
+ *
+ * @param sched scheduler to use
+ * @param service_name name of service to connect to
+ * @param cfg configuration to use
+ * @param attempt counter used to alternate between IP and UNIX domain sockets
+ * @return NULL on error
+ */
static struct GNUNET_CONNECTION_Handle *
do_connect (struct GNUNET_SCHEDULER_Handle *sched,
const char *service_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ unsigned int attempt)
{
struct GNUNET_CONNECTION_Handle *sock;
char *hostname;
+ char *unixpath;
unsigned long long port;
+#if AF_UNIX
+ if (0 == attempt % 2)
+ {
+ /* on even rounds, try UNIX */
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ service_name,
+ "UNIXPATH", &unixpath))
+ {
+ sock = GNUNET_CONNECTION_create_from_connect_to_unixpath (sched,
+ cfg,
+ unixpath,
+ GNUNET_SERVER_MAX_MESSAGE_SIZE);
+ GNUNET_free (unixpath);
+ if (sock != NULL)
+ return sock;
+ }
+ }
+#endif
+
if ((GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg,
service_name,
@@ -314,10 +350,13 @@ GNUNET_CLIENT_connect (struct GNUNET_SCHEDULER_Handle *sched,
struct GNUNET_CLIENT_Connection *ret;
struct GNUNET_CONNECTION_Handle *sock;
- sock = do_connect (sched, service_name, cfg);
+ sock = do_connect (sched,
+ service_name,
+ cfg, 0);
if (sock == NULL)
return NULL;
ret = GNUNET_malloc (sizeof (struct GNUNET_CLIENT_Connection));
+ ret->attempts = 1;
ret->sock = sock;
ret->sched = sched;
ret->service_name = GNUNET_strdup (service_name);
@@ -770,7 +809,9 @@ client_notify (void *cls, size_t size, void *buf)
/* auto-retry */
GNUNET_CONNECTION_destroy (th->sock->sock, GNUNET_NO);
th->sock->sock = do_connect (th->sock->sched,
- th->sock->service_name, th->sock->cfg);
+ th->sock->service_name,
+ th->sock->cfg,
+ th->sock->attempts++);
GNUNET_assert (NULL != th->sock->sock);
GNUNET_CONNECTION_ignore_shutdown (th->sock->sock,
th->sock->ignore_shutdown);
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index 73a374f46..c06aadc2f 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -510,7 +510,9 @@ GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen)
static char buf[INET6_ADDRSTRLEN + 8];
static char b2[6];
const struct sockaddr_in *v4;
+ const struct sockaddr_un *un;
const struct sockaddr_in6 *v6;
+ unsigned int off;
if (addr == NULL)
return _("unknown address");
@@ -535,6 +537,17 @@ GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen)
sprintf (b2, "%u", ntohs (v6->sin6_port));
strcat (buf, b2);
return buf;
+ case AF_UNIX:
+ un = (const struct sockaddr_un*) addr;
+ off = 0;
+ if (un->sun_path[0] == '\0') off++;
+ snprintf (buf,
+ sizeof (buf),
+ "%s%.*s",
+ (off == 1) ? "@" : "",
+ addrlen - sizeof (sa_family_t) - 1 - off,
+ &un->sun_path[off]);
+ return buf;
default:
return _("invalid address");
}
diff --git a/src/util/connection.c b/src/util/connection.c
index fdd454105..d218714c0 100644
--- a/src/util/connection.c
+++ b/src/util/connection.c
@@ -889,6 +889,72 @@ GNUNET_CONNECTION_create_from_connect (struct GNUNET_SCHEDULER_Handle *sched,
/**
+ * Create a socket handle by connecting to a UNIX domain service.
+ * This function returns immediately, even if the connection has not
+ * yet been established. This function only creates UNIX connections.
+ *
+ * @param sched scheduler to use
+ * @param cfg configuration to use
+ * @param unixpath path to connect to
+ * @param maxbuf maximum write buffer size for the socket (use
+ * 0 for sockets that need no write buffers, such as listen sockets)
+ * @return the socket handle, NULL on systems without UNIX support
+ */
+struct GNUNET_CONNECTION_Handle *
+GNUNET_CONNECTION_create_from_connect_to_unixpath (struct GNUNET_SCHEDULER_Handle *sched,
+ const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ const char *unixpath,
+ size_t maxbuf)
+{
+#ifdef AF_UNIX
+ struct GNUNET_CONNECTION_Handle *ret;
+ struct sockaddr_un *un;
+ size_t slen;
+
+ GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
+ un = GNUNET_malloc (sizeof (struct sockaddr_un));
+ un->sun_family = AF_UNIX;
+ slen = strlen (unixpath) + 1;
+ if (slen >= sizeof (un->sun_path))
+ slen = sizeof (un->sun_path) - 1;
+ memcpy (un->sun_path,
+ unixpath,
+ slen);
+ un->sun_path[slen] = '\0';
+ slen += sizeof (sa_family_t);
+#if LINUX
+ un->sun_path[0] = '\0';
+ slen = sizeof (struct sockaddr_un);
+#endif
+ ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf);
+ ret->cfg = cfg;
+ ret->sched = sched;
+ ret->write_buffer = (char *) &ret[1];
+ ret->write_buffer_size = maxbuf;
+ ret->port = 0;
+ ret->hostname = NULL;
+ ret->addr = (struct sockaddr*) un;
+ ret->addrlen = slen;
+ ret->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
+ if (GNUNET_OK != GNUNET_NETWORK_socket_connect (ret->sock,
+ ret->addr,
+ ret->addrlen))
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret->sock));
+ GNUNET_free (ret->addr);
+ GNUNET_free (ret);
+ return NULL;
+ }
+ connect_success_continuation (ret);
+ return ret;
+#else
+ return NULL;
+#endif
+}
+
+
+/**
* Create a socket handle by (asynchronously) connecting to a host.
* This function returns immediately, even if the connection has not
* yet been established. This function only creates TCP connections.
diff --git a/src/util/network.c b/src/util/network.c
index 0b4168034..8ec365269 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -226,7 +226,10 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
#ifdef DARWIN
socket_set_nosigpipe (ret);
#endif
- socket_set_nodelay (ret);
+#ifdef AF_UNIX
+ if (address->sa_family != AF_UNIX)
+#endif
+ socket_set_nodelay (ret);
return ret;
}
@@ -590,7 +593,11 @@ GNUNET_NETWORK_socket_create (int domain, int type, int protocol)
#ifdef DARWIN
socket_set_nosigpipe (ret);
#endif
- if (type == SOCK_STREAM)
+ if ( (type == SOCK_STREAM)
+#ifdef AF_UNIX
+ && (domain != AF_UNIX)
+#endif
+ )
socket_set_nodelay (ret);
return ret;
}
diff --git a/src/util/service.c b/src/util/service.c
index 82e7070a1..9ab99de3e 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -612,6 +612,10 @@ check_access (void *cls, const struct sockaddr *addr, socklen_t addrlen)
&& ((sctx->v6_denied == NULL) ||
(!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr)));
break;
+ case AF_UNIX:
+ /* FIXME: support checking UID/GID in the future... */
+ ret = GNUNET_OK; /* always OK for now */
+ break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Unknown address family %d\n"), addr->sa_family);
@@ -702,6 +706,46 @@ process_acl6 (struct IPv6NetworkSet **ret,
return GNUNET_OK;
}
+/**
+ * Add the given UNIX domain path as an address to the
+ * list (as the first entry).
+ *
+ * @param saddrs array to update
+ * @param saddrlens where to store the address length
+ * @param unixpath path to add
+ */
+static void
+add_unixpath (struct sockaddr **saddrs,
+ socklen_t *saddrlens,
+ const char *unixpath)
+{
+#ifdef AF_UNIX
+ struct sockaddr_un *un;
+ size_t slen;
+
+ un = GNUNET_malloc (sizeof (struct sockaddr_un));
+ un->sun_family = AF_UNIX;
+ slen = strlen (unixpath) + 1;
+ if (slen >= sizeof (un->sun_path))
+ slen = sizeof (un->sun_path) - 1;
+ memcpy (un->sun_path,
+ unixpath,
+ slen);
+ un->sun_path[slen] = '\0';
+ slen += sizeof (sa_family_t);
+#if LINUX
+ un->sun_path[0] = '\0';
+ slen = sizeof (struct sockaddr_un);
+#endif
+ *saddrs = (struct sockaddr*) un;
+ *saddrlens = slen;
+#else
+ /* this function should never be called
+ unless AF_UNIX is defined! */
+ GNUNET_assert (0);
+#endif
+}
+
/**
* Get the list of addresses that a server for the given service
@@ -732,6 +776,7 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
int disablev6;
struct GNUNET_NETWORK_Handle *desc;
unsigned long long port;
+ char *unixpath;
struct addrinfo hints;
struct addrinfo *res;
struct addrinfo *pos;
@@ -781,19 +826,25 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
}
}
-
- if ((GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- serviceName,
- "PORT",
- &port)) || (port > 65535))
+ port = 0;
+ if (GNUNET_CONFIGURATION_have_value (cfg,
+ serviceName, "PORT"))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Require valid port number for service `%s' in configuration!\n"),
- serviceName);
- return GNUNET_SYSERR;
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ serviceName,
+ "PORT",
+ &port));
+ if (port > 65535)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _
+ ("Require valid port number for service `%s' in configuration!\n"),
+ serviceName);
+ return GNUNET_SYSERR;
+ }
}
+
if (GNUNET_CONFIGURATION_have_value (cfg,
serviceName, "BINDTO"))
{
@@ -806,6 +857,49 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
else
hostname = NULL;
+#ifdef AF_UNIX
+ if (GNUNET_CONFIGURATION_have_value (cfg,
+ serviceName, "UNIXPATH"))
+ {
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ serviceName,
+ "UNIXPATH",
+ &unixpath));
+
+ /* probe UNIX support */
+ desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
+ if (NULL == desc)
+ {
+ if ((errno == ENOBUFS) ||
+ (errno == ENOMEM) || (errno == ENFILE) || (errno == EACCES))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
+ return GNUNET_SYSERR;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _
+ ("Disabling UNIX domainn socket support for service `%s', failed to create UNIX domain socket: %s\n"),
+ serviceName, STRERROR (errno));
+ GNUNET_free (unixpath);
+ unixpath = NULL;
+ }
+ }
+ else
+ unixpath = NULL;
+#else
+ unixpath = NULL;
+#endif
+
+ if ( (port == 0) &&
+ (unixpath == NULL) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
+ serviceName);
+ return GNUNET_SYSERR;
+ }
+
if (hostname != NULL)
{
#if DEBUG_SERVICE
@@ -845,9 +939,16 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
return GNUNET_SYSERR;
}
resi = i;
- saddrs = GNUNET_malloc ((i+1) * sizeof(struct sockaddr*));
- saddrlens = GNUNET_malloc ((i+1) * sizeof (socklen_t));
+ if (NULL != unixpath)
+ resi++;
+ saddrs = GNUNET_malloc ((resi+1) * sizeof(struct sockaddr*));
+ saddrlens = GNUNET_malloc ((resi+1) * sizeof (socklen_t));
i = 0;
+ if (NULL != unixpath)
+ {
+ add_unixpath (saddrs, saddrlens, unixpath);
+ i++;
+ }
next = res;
while (NULL != (pos = next))
{
@@ -890,40 +991,56 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
{
/* V4-only */
resi = 1;
- saddrs = GNUNET_malloc (2 * sizeof(struct sockaddr*));
- saddrlens = GNUNET_malloc (2 * sizeof (socklen_t));
- saddrlens[0] = sizeof (struct sockaddr_in);
- saddrs[0] = GNUNET_malloc (saddrlens[0]);
+ if (NULL != unixpath)
+ resi++;
+ i = 0;
+ saddrs = GNUNET_malloc ((resi+1) * sizeof(struct sockaddr*));
+ saddrlens = GNUNET_malloc ((resi+1) * sizeof (socklen_t));
+ if (NULL != unixpath)
+ {
+ add_unixpath (saddrs, saddrlens, unixpath);
+ i++;
+ }
+ saddrlens[i] = sizeof (struct sockaddr_in);
+ saddrs[i] = GNUNET_malloc (saddrlens[i]);
#if HAVE_SOCKADDR_IN_SIN_LEN
- ((struct sockaddr_in *) saddrs[0])->sin_len = saddrlens[0];
+ ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
#endif
- ((struct sockaddr_in *) saddrs[0])->sin_family = AF_INET;
- ((struct sockaddr_in *) saddrs[0])->sin_port = htons (port);
+ ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
+ ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
}
else
{
/* dual stack */
resi = 2;
- saddrs = GNUNET_malloc (3 * sizeof(struct sockaddr*));
- saddrlens = GNUNET_malloc (3 * sizeof (socklen_t));
-
- saddrlens[0] = sizeof (struct sockaddr_in6);
- saddrs[0] = GNUNET_malloc (saddrlens[0]);
+ if (NULL != unixpath)
+ resi++;
+ saddrs = GNUNET_malloc ((resi+1) * sizeof(struct sockaddr*));
+ saddrlens = GNUNET_malloc ((resi+1) * sizeof (socklen_t));
+ i = 0;
+ if (NULL != unixpath)
+ {
+ add_unixpath (saddrs, saddrlens, unixpath);
+ i++;
+ }
+ saddrlens[i] = sizeof (struct sockaddr_in6);
+ saddrs[i] = GNUNET_malloc (saddrlens[i]);
#if HAVE_SOCKADDR_IN_SIN_LEN
- ((struct sockaddr_in6 *) saddrs[0])->sin6_len = saddrlens[0];
+ ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
#endif
- ((struct sockaddr_in6 *) saddrs[0])->sin6_family = AF_INET6;
- ((struct sockaddr_in6 *) saddrs[0])->sin6_port = htons (port);
-
- saddrlens[1] = sizeof (struct sockaddr_in);
- saddrs[1] = GNUNET_malloc (saddrlens[1]);
+ ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
+ ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
+ i++;
+ saddrlens[i] = sizeof (struct sockaddr_in);
+ saddrs[i] = GNUNET_malloc (saddrlens[i]);
#if HAVE_SOCKADDR_IN_SIN_LEN
- ((struct sockaddr_in *) saddrs[1])->sin_len = saddrlens[1];
+ ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
#endif
- ((struct sockaddr_in *) saddrs[1])->sin_family = AF_INET;
- ((struct sockaddr_in *) saddrs[1])->sin_port = htons (port);
+ ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
+ ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
}
}
+ GNUNET_free_non_null (unixpath);
*addrs = saddrs;
*addr_lens = saddrlens;
return resi;
@@ -934,8 +1051,9 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
* Setup addr, addrlen, maxbuf, idle_timeout
* based on configuration!
*
- * Configuration must specify a "PORT". It may
- * specify:
+ * Configuration may specify:
+ * - PORT (where to bind to for TCP)
+ * - UNIXPATH (where to bind to for UNIX domain sockets)
* - TIMEOUT (after how many ms does an inactive service timeout);
* - MAXBUF (maximum incoming message size supported)
* - DISABLEV6 (disable support for IPv6, otherwise we use dual-stack)
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c
index e6496e7ac..c24646d07 100644
--- a/src/util/test_resolver_api.c
+++ b/src/util/test_resolver_api.c
@@ -222,6 +222,7 @@ static void
run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args,
const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
+ int *ok = cls;
struct sockaddr_in sa;
struct GNUNET_TIME_Relative timeout = GNUNET_TIME_relative_multiply(
GNUNET_TIME_UNIT_MILLISECONDS, 2500);
@@ -267,6 +268,7 @@ run(void *cls, struct GNUNET_SCHEDULER_Handle *sched, char * const *args,
#endif
fprintf (stderr,
"System seems to be off-line, will not run all DNS tests\n");
+ *ok = 0; /* mark test as passing anyway */
return;
}