#include "gnunet_protocols.h"
#include "gnunet_constants.h"
#include "gnunet_resolver_service.h"
+#include "speedup.h"
#if HAVE_MALLINFO
#include <malloc.h>
/* ******************* access control ******************** */
-/**
- * Start task that may speed up our system clock artificially
- *
- * @param cfg configuration to use
- * @return GNUNET_OK on success, GNUNET_SYSERR if the speedup was not configured
- */
-int
-GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg);
-
-/**
- * Stop tasks that modify clock behavior.
- */
-void
-GNUNET_SPEEDUP_stop_ (void);
-
-
/**
* Check if the given IP address is in the list of IP addresses.
*
* @param saddrs array to update
* @param saddrlens where to store the address length
* @param unixpath path to add
+ * @param abstract GNUNET_YES to add an abstract UNIX domain socket. This
+ * parameter is ignore on systems other than LINUX
*/
static void
add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens,
- const char *unixpath)
+ const char *unixpath,
+ int abstract)
{
#ifdef AF_UNIX
struct sockaddr_un *un;
un = GNUNET_new (struct sockaddr_un);
un->sun_family = AF_UNIX;
strncpy (un->sun_path, unixpath, sizeof (un->sun_path) - 1);
+#ifdef LINUX
+ if (GNUNET_YES == abstract)
+ un->sun_path[0] = '\0';
+#endif
#if HAVE_SOCKADDR_IN_SIN_LEN
un->sun_len = (u_char) sizeof (struct sockaddr_un);
#endif
* addresses the server should bind to and listen on; the
* array will be NULL-terminated (on success)
* @param addr_lens set (call by reference) to an array of the lengths
- * of the respective 'struct sockaddr' struct in the 'addrs'
+ * of the respective `struct sockaddr` struct in the @a addrs
* array (on success)
* @return number of addresses found on success,
* #GNUNET_SYSERR if the configuration
*/
int
GNUNET_SERVICE_get_server_addresses (const char *service_name,
- const struct GNUNET_CONFIGURATION_Handle
- *cfg, struct sockaddr ***addrs,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct sockaddr ***addrs,
socklen_t ** addr_lens)
{
int disablev6;
unsigned int i;
int resi;
int ret;
+ int abstract;
struct sockaddr **saddrs;
socklen_t *saddrlens;
char *hostname;
hostname = NULL;
unixpath = NULL;
+ abstract = GNUNET_NO;
#ifdef AF_UNIX
if ((GNUNET_YES ==
GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
LOG (GNUNET_ERROR_TYPE_INFO,
_("Using `%s' instead\n"), unixpath);
}
- if (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (unixpath))
+#ifdef LINUX
+ abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ "TESTING",
+ "USE_ABSTRACT_SOCKETS");
+ if (GNUNET_SYSERR == abstract)
+ abstract = GNUNET_NO;
+#endif
+ if ((GNUNET_YES != abstract)
+ && (GNUNET_OK !=
+ GNUNET_DISK_directory_create_for_file (unixpath)))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
"mkdir",
unixpath);
{
saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *));
saddrlens = GNUNET_malloc (2 * sizeof (socklen_t));
- add_unixpath (saddrs, saddrlens, unixpath);
+ add_unixpath (saddrs, saddrlens, unixpath, abstract);
GNUNET_free_non_null (unixpath);
GNUNET_free_non_null (hostname);
*addrs = saddrs;
if (NULL != hostname)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Resolving `%s' since that is where `%s' will bind to.\n", hostname,
+ "Resolving `%s' since that is where `%s' will bind to.\n",
+ hostname,
service_name);
memset (&hints, 0, sizeof (struct addrinfo));
if (disablev6)
hints.ai_family = AF_INET;
hints.ai_protocol = IPPROTO_TCP;
if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
- (res == NULL))
+ (NULL == res))
{
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to resolve `%s': %s\n"), hostname,
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to resolve `%s': %s\n"),
+ hostname,
gai_strerror (ret));
GNUNET_free (hostname);
GNUNET_free_non_null (unixpath);
}
if (0 == i)
{
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Failed to find %saddress for `%s'.\n"),
- disablev6 ? "IPv4 " : "", hostname);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to find %saddress for `%s'.\n"),
+ disablev6 ? "IPv4 " : "",
+ hostname);
freeaddrinfo (res);
GNUNET_free (hostname);
GNUNET_free_non_null (unixpath);
i = 0;
if (NULL != unixpath)
{
- add_unixpath (saddrs, saddrlens, unixpath);
+ add_unixpath (saddrs, saddrlens, unixpath, abstract);
i++;
}
next = res;
saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
if (NULL != unixpath)
{
- add_unixpath (saddrs, saddrlens, unixpath);
+ add_unixpath (saddrs, saddrlens, unixpath, abstract);
i++;
}
saddrlens[i] = sizeof (struct sockaddr_in);
i = 0;
if (NULL != unixpath)
{
- add_unixpath (saddrs, saddrlens, unixpath);
+ add_unixpath (saddrs, saddrlens, unixpath, abstract);
i++;
}
saddrlens[i] = sizeof (struct sockaddr_in6);
#ifndef WINDOWS
if (NULL != sctx->addrs)
for (i = 0; NULL != sctx->addrs[i]; i++)
- if (AF_UNIX == sctx->addrs[i]->sa_family)
+ if ((AF_UNIX == sctx->addrs[i]->sa_family)
+ && ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0]))
GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path,
sctx->match_uid,
sctx->match_gid);
#ifndef WINDOWS
if (NULL != sctx->addrs)
for (i = 0; NULL != sctx->addrs[i]; i++)
- if (AF_UNIX == sctx->addrs[i]->sa_family)
+ if ((AF_UNIX == sctx->addrs[i]->sa_family)
+ && ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0]))
GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path,
sctx->match_uid,
sctx->match_gid);