#include "gnunet_server_lib.h"
#include "gnunet_scheduler_lib.h"
-#define DEBUG_CLIENT GNUNET_NO
+#define DEBUG_CLIENT GNUNET_EXTRA_LOGGING
/**
* How often do we re-try tranmsitting requests before giving up?
*/
#define MAX_ATTEMPTS 50
+#define LOG(kind,...) GNUNET_log_from (kind, "util",__VA_ARGS__)
+
/**
* Handle for a transmission request.
*/
*/
int in_receive;
- /**
- * Are we ignoring shutdown signals?
- */
- int ignore_shutdown;
-
/**
* How often have we tried to connect?
*/
if (sock != NULL)
{
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to unixpath `%s'!\n",
- unixpath);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to unixpath `%s'!\n",
+ unixpath);
#endif
GNUNET_free (unixpath);
return sock;
GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "HOSTNAME",
&hostname)))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Could not determine valid hostname and port for service `%s' from configuration.\n"),
- service_name);
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Could not determine valid hostname and port for service `%s' from configuration.\n"),
+ service_name);
return NULL;
}
if (0 == strlen (hostname))
{
GNUNET_free (hostname);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Need a non-empty hostname for service `%s'.\n"),
- service_name);
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Need a non-empty hostname for service `%s'.\n"), service_name);
return NULL;
}
if (port == 0)
}
#endif
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Port is 0 for service `%s', UNIXPATH did not work, returning NULL!\n",
- service_name);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Port is 0 for service `%s', UNIXPATH did not work, returning NULL!\n",
+ service_name);
#endif
GNUNET_free (hostname);
return NULL;
}
-/**
- * Configure this connection to ignore shutdown signals.
- *
- * @param h client handle
- * @param do_ignore GNUNET_YES to ignore, GNUNET_NO to restore default
- */
-void
-GNUNET_CLIENT_ignore_shutdown (struct GNUNET_CLIENT_Connection *h,
- int do_ignore)
-{
- h->ignore_shutdown = do_ignore;
- if (h->sock != NULL)
- GNUNET_CONNECTION_ignore_shutdown (h->sock, do_ignore);
-}
-
-
/**
* Destroy connection with the service. This will automatically
* cancel any pending "receive" request (however, the handler will
{
/* signal timeout! */
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Timeout in receive_helper, available %u, conn->sock %s, errCode `%s'\n",
- (unsigned int) available,
- conn->sock == NULL ? "NULL" : "non-NULL", STRERROR (errCode));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Timeout in receive_helper, available %u, conn->sock %s, errCode `%s'\n",
+ (unsigned int) available, conn->sock == NULL ? "NULL" : "non-NULL",
+ STRERROR (errCode));
#endif
if (NULL != (receive_handler = conn->receiver_handler))
{
struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf;
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %u and size %u\n", ntohs (cmsg->type),
- msize);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %u and size %u\n",
+ ntohs (cmsg->type), msize);
#endif
sock->receive_task = GNUNET_SCHEDULER_NO_TASK;
GNUNET_assert (GNUNET_YES == sock->msg_complete);
GNUNET_assert (sock->in_receive == GNUNET_NO);
sock->in_receive = GNUNET_YES;
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "calling GNUNET_CONNECTION_receive\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "calling GNUNET_CONNECTION_receive\n");
#endif
GNUNET_CONNECTION_receive (sock->sock, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
timeout, &receive_helper, sock);
if (msg != NULL)
{
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received confirmation that service is running.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received confirmation that service is running.\n");
#endif
GNUNET_SCHEDULER_add_continuation (conn->test_cb, conn->test_cb_cls,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
if (size < sizeof (struct GNUNET_MessageHeader))
{
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Failure to transmit TEST request.\n"));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, _("Failure to transmit TEST request.\n"));
#endif
service_test_error (conn->test_cb, conn->test_cb_cls);
GNUNET_CLIENT_disconnect (conn, GNUNET_NO);
return 0; /* client disconnected */
}
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "TEST");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "TEST");
#endif
msg = (struct GNUNET_MessageHeader *) buf;
msg->type = htons (GNUNET_MESSAGE_TYPE_TEST);
struct GNUNET_CLIENT_Connection *conn;
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing if service `%s' is running.\n",
- service);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Testing if service `%s' is running.\n",
+ service);
#endif
#ifdef AF_UNIX
{
{
if (strlen (unixpath) >= sizeof (s_un.sun_path))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("UNIXPATH `%s' too long, maximum length is %llu\n"),
- unixpath, sizeof (s_un.sun_path));
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath,
+ sizeof (s_un.sun_path));
}
else
{
}
if (0 == strcmp ("localhost", hostname)
-#if WINDOWS
+#if !LINUX
&& 0
#endif
)
}
if (0 == strcmp ("ip6-localhost", hostname)
-#if WINDOWS
+#if !LINUX
&& 0
#endif
)
if (((0 == strcmp ("localhost", hostname)) ||
(0 == strcmp ("ip6-localhost", hostname)))
-#if WINDOWS
+#if !LINUX
&& 0
#endif
)
conn = GNUNET_CLIENT_connect (service, cfg);
if (conn == NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Could not connect to service `%s', must not be running.\n"),
- service);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("Could not connect to service `%s', must not be running.\n"),
+ service);
service_test_error (task, task_cls);
return;
}
timeout, GNUNET_YES, &write_test,
conn))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failure to transmit request to service `%s'\n"), service);
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Failure to transmit request to service `%s'\n"), service);
service_test_error (task, task_cls);
GNUNET_CLIENT_disconnect (conn, GNUNET_NO);
return;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
{
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission failed due to shutdown.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmission failed due to shutdown.\n");
#endif
th->sock->th = NULL;
th->notify (th->notify_cls, 0, NULL);
(th->sock->back_off, 2),
GNUNET_TIME_UNIT_SECONDS);
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission failed %u times, trying again in %llums.\n",
- MAX_ATTEMPTS - th->attempts_left,
- (unsigned long long) delay.rel_value);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission failed %u times, trying again in %llums.\n",
+ MAX_ATTEMPTS - th->attempts_left,
+ (unsigned long long) delay.rel_value);
#endif
th->reconnect_task =
GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
return;
}
- GNUNET_CONNECTION_ignore_shutdown (th->sock->sock, th->sock->ignore_shutdown);
th->th =
GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock, th->size,
GNUNET_TIME_absolute_get_remaining
(delay.rel_value < 1))
{
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission failed %u times, giving up.\n",
- MAX_ATTEMPTS - th->attempts_left);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission failed %u times, giving up.\n",
+ MAX_ATTEMPTS - th->attempts_left);
#endif
GNUNET_break (0 == th->notify (th->notify_cls, 0, NULL));
GNUNET_free (th);
}
/* auto-retry */
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to connect to `%s', automatically trying again.\n",
- th->sock->service_name);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect to `%s', automatically trying again.\n",
+ th->sock->service_name);
#endif
GNUNET_CONNECTION_destroy (th->sock->sock, GNUNET_NO);
th->sock->sock = NULL;
(th->sock->back_off, 2),
GNUNET_TIME_UNIT_SECONDS);
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission failed %u times, trying again in %llums.\n",
- MAX_ATTEMPTS - th->attempts_left,
- (unsigned long long) delay.rel_value);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission failed %u times, trying again in %llums.\n",
+ MAX_ATTEMPTS - th->attempts_left,
+ (unsigned long long) delay.rel_value);
#endif
th->sock->th = th;
th->reconnect_task =
if (NULL == buf)
{
#if DEBUG_CLIENT
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _
- ("Could not submit request, not expecting to receive a response.\n"));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ _("Could not submit request, not expecting to receive a response.\n"));
#endif
if (NULL != tc->rn)
tc->rn (tc->rn_cls, NULL);