/*
This file is part of GNUnet.
- (C) 2001, 2002, 2006, 2008, 2009, 2012 Christian Grothoff (and other contributing authors)
+ (C) 2001-2013 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 2, or (at your
+ by the Free Software Foundation; either version 3, or (at your
option) any later version.
GNUnet is distributed in the hope that it will be useful, but
struct sockaddr_un s_un;
unixpath = NULL;
- if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", &unixpath)) &&
- (0 < strlen (unixpath)))
+ if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", &unixpath)) &&
+ (0 < strlen (unixpath)))
{
/* We have a non-NULL unixpath, need to validate it */
if (strlen (unixpath) >= sizeof (s_un.sun_path))
unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
LOG (GNUNET_ERROR_TYPE_INFO,
_("Using `%s' instead\n"), unixpath);
+ if (NULL == unixpath)
+ return NULL;
}
connection = GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, unixpath);
if (NULL != connection)
/**
- * Try connecting to the server using UNIX domain sockets.
+ * Test whether the configuration has proper values for connection
+ * (UNIXPATH || (PORT && HOSTNAME)).
*
* @param service_name name of service to connect to
* @param cfg configuration to use
#if AF_UNIX
char *unixpath = NULL;
- if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", &unixpath)) &&
- (0 < strlen (unixpath)))
+ if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", &unixpath)) &&
+ (0 < strlen (unixpath)))
ret = GNUNET_OK;
GNUNET_free_non_null (unixpath);
#endif
if ( (GNUNET_YES ==
GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) &&
(GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", &port)) &&
+ GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", &port)) &&
(port <= 65535) && (0 != port) &&
(GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "HOSTNAME",
struct GNUNET_CLIENT_Connection *client;
struct GNUNET_CONNECTION_Handle *connection;
- if (GNUNET_OK !=
+ if (GNUNET_OK !=
test_service_configuration (service_name,
cfg))
return NULL;
connection = do_connect (service_name, cfg, 0);
- client = GNUNET_malloc (sizeof (struct GNUNET_CLIENT_Connection));
+ client = GNUNET_new (struct GNUNET_CLIENT_Connection);
client->first_message = GNUNET_YES;
client->attempts = 1;
client->connection = connection;
check_complete (client);
/* check for timeout */
remaining = GNUNET_TIME_absolute_get_remaining (client->receive_timeout);
- if (0 == remaining.rel_value)
+ if (0 == remaining.rel_value_us)
{
/* signal timeout! */
if (NULL != client->receiver_handler)
/**
* Handle for a test to check if a service is running.
*/
-struct GNUNET_CLIENT_TestHandle
+struct GNUNET_CLIENT_TestHandle
{
/**
* Function to call with the result of the test.
/**
* Client connection we are using for the test, if any.
- */
+ */
struct GNUNET_CLIENT_Connection *client;
/**
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_CLIENT_TestHandle *th = cls;
-
+
th->task = GNUNET_SCHEDULER_NO_TASK;
th->cb (th->cb_cls, th->result);
GNUNET_CLIENT_service_test_cancel (th);
{
th->result = result;
th->task = GNUNET_SCHEDULER_add_now (&report_result,
- th);
+ th);
}
th->th = NULL;
if (size < sizeof (struct GNUNET_MessageHeader))
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Failed to transmit TEST request.\n");
service_test_report (th, GNUNET_NO);
return 0; /* client disconnected */
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting `%s' request.\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting `%s' request.\n",
"TEST");
msg = (struct GNUNET_MessageHeader *) buf;
msg->type = htons (GNUNET_MESSAGE_TYPE_TEST);
msg->size = htons (sizeof (struct GNUNET_MessageHeader));
- GNUNET_CLIENT_receive (th->client,
+ GNUNET_CLIENT_receive (th->client,
&confirm_handler, th,
GNUNET_TIME_absolute_get_remaining
(th->test_deadline));
th->cb = cb;
th->cb_cls = cb_cls;
th->test_deadline = GNUNET_TIME_relative_to_absolute (timeout);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Testing if service `%s' is running.\n",
service);
#ifdef AF_UNIX
#endif
if (GNUNET_OK !=
GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_un,
- slen))
+ slen, GNUNET_BIND_EXCLUSIVE))
{
/* failed to bind => service must be running */
GNUNET_free (unixpath);
service_test_report (th, GNUNET_YES);
return th;
}
- (void) GNUNET_NETWORK_socket_close (sock);
+ (void) GNUNET_NETWORK_socket_close (sock);
/* let's try IP */
}
}
{
if (GNUNET_OK !=
GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in,
- sizeof (s_in)))
+ sizeof (s_in), GNUNET_BIND_EXCLUSIVE))
{
/* failed to bind => service must be running */
GNUNET_free (hostname);
{
if (GNUNET_OK !=
GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in6,
- sizeof (s_in6)))
+ sizeof (s_in6), GNUNET_BIND_EXCLUSIVE))
{
/* failed to bind => service must be running */
GNUNET_free (hostname);
{
struct GNUNET_CLIENT_TransmitHandle *th = cls;
struct GNUNET_TIME_Relative delay;
-
+
th->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
{
if (NULL == buf)
{
delay = GNUNET_TIME_absolute_get_remaining (th->timeout);
- delay.rel_value /= 2;
+ delay.rel_value_us /= 2;
if ((GNUNET_YES != th->auto_retry) || (0 == --th->attempts_left) ||
- (delay.rel_value < 1)||
+ (delay.rel_value_us < 1)||
(0 != (GNUNET_SCHEDULER_get_reason() & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
{
GNUNET_CONNECTION_receive_cancel (client->connection);
client->in_receive = GNUNET_NO;
- }
+ }
GNUNET_CONNECTION_destroy (client->connection);
client->connection = NULL;
delay = GNUNET_TIME_relative_min (delay, client->back_off);