static int
http_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
{
-
struct Plugin *plugin = cls;
struct IPv4HttpAddressWrapper *w_tv4 = plugin->ipv4_addr_head;
struct IPv6HttpAddressWrapper *w_tv6 = plugin->ipv6_addr_head;
-
-
GNUNET_assert (cls != NULL);
if ((addrlen != sizeof (struct sockaddr_in)) ||
(addrlen != sizeof (struct sockaddr_in6)))
* @param added length of created address
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
-int http_string_to_address (void *cls,
- const char *addr,
- uint16_t addrlen,
- void **buf,
- size_t *added)
+int
+http_string_to_address (void *cls,
+ const char *addr,
+ uint16_t addrlen,
+ void **buf,
+ size_t *added)
{
#if !BUILD_HTTPS
char *protocol = "http";
(*added) = sizeof (struct IPv4HttpAddress);
return GNUNET_OK;
}
- else if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv6(addr_str, strlen(addr_str), &addr_6))
+ if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv6(addr_str, strlen(addr_str), &addr_6))
{
http_6addr = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
http_6addr->u6_port = addr_6.sin6_port;
(*added) = sizeof (struct IPv6HttpAddress);
return GNUNET_OK;
}
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Invalid address string `%s' to convert to address\n",
- addr_str);
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid address string `%s' to convert to address\n",
+ addr_str);
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
}
-
/**
* Function called for a quick conversion of the binary address to
* a numeric address. Note that the caller must not free the
return rbuf;
}
+
struct Session *
lookup_session_old (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
struct Session *session, const void *addr, size_t addrlen,
{
#if 0
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
- "Comparing peer `%s' address `%s' len %i session %X to \n",
+ "Comparing peer `%s' address `%s' len %i session %p to \n",
GNUNET_i2s (target), GNUNET_a2s (addr, addrlen), addrlen,
session);
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
- "peer `%s' address `%s' len %i session %X \n\n",
+ "peer `%s' address `%s' len %i session %p \n\n",
GNUNET_i2s (&t->target), GNUNET_a2s (t->addr, t->addrlen),
t->addrlen, t);
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, "memcmp %i \n",
return NULL;
}
+
struct Session *
lookup_session (struct Plugin *plugin,
const struct GNUNET_HELLO_Address *address)
return NULL;
}
+
int
exist_session (struct Plugin *plugin, struct Session *s)
{
}
-
void
delete_session (struct Session *s)
{
GNUNET_free (s);
}
+
struct Session *
create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
const void *addr, size_t addrlen)
}
-
void
notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
struct Session *s)
delete_session (s);
}
+
/**
* Creates a new outbound session the transport service will use to send data to the
* peer
* @param address the address
* @return the session or NULL of max connections exceeded
*/
-
static struct Session *
http_get_session (void *cls,
const struct GNUNET_HELLO_Address *address)
return s;
}
+
/**
* Function that can be used by the transport service to transmit
* a message using the plugin. Note that in the case of a
}
/* create new message and schedule */
-
msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
msg->next = NULL;
msg->size = msgbuf_size;
}
}
+
static void *
find_address (struct Plugin *plugin, const struct sockaddr *addr, socklen_t addrlen)
{
return NULL;
}
+
static void
nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
socklen_t addrlen)
}
+
static void
nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
socklen_t addrlen)
default:
return;
}
-
}
+
/**
* Our external IP address/port mapping has changed.
*
}
}
+
void
http_check_ipv6 (struct Plugin *plugin)
{
}
}
+
int
http_get_addresses (struct Plugin *plugin, const char *serviceName,
const struct GNUNET_CONFIGURATION_Handle *cfg,
}
}
+
static void
stop_report_addresses (struct Plugin *plugin)
{
}
}
+
static int
configure_plugin (struct Plugin *plugin)
{
}
+
/**
* Start session timeout
*/
s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
}
+
/**
* Increment session timeout due to activity
*/
s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
}
+
/**
* Cancel timeout
*/
/*
This file is part of GNUnet
- (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
+ (C) 2002--2012 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
}
#if BUILD_HTTPS
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-https",
- "Client: %X - %s", cls, text);
+ "Client: %p - %s", cls, text);
#else
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-http",
- "Client: %X - %s", cls, text);
+ "Client: %p - %s", cls, text);
#endif
}
return 0;
static void
client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+
/**
* Function setting up file descriptors and scheduling task to run
*
GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
}
-
max = -1;
FD_ZERO (&rs);
FD_ZERO (&ws);
GNUNET_break (0);
return GNUNET_SYSERR;
}
-
if (s->client_put_paused == GNUNET_YES)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
- "Client: %X was suspended, unpausing\n", s->client_put);
+ "Client: %p was suspended, unpausing\n", s->client_put);
s->client_put_paused = GNUNET_NO;
curl_easy_pause (s->client_put, CURLPAUSE_CONT);
}
-
client_schedule (s->plugin, GNUNET_YES);
return GNUNET_OK;
}
-
/**
* Task performing curl operations
+ *
* @param cls plugin as closure
* @param tc gnunet scheduler task context
*/
if (msg->msg == CURLMSG_DONE)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: %X connection to '%s' %s ended with reason %i: `%s'\n",
+ "Client: %p connection to '%s' %s ended with reason %i: `%s'\n",
msg->easy_handle, GNUNET_i2s (&s->target),
http_plugin_address_to_string (NULL, s->addr,
s->addrlen),
curl_easy_strerror (msg->data.result));
client_disconnect (s);
- //GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,"Notifying about ended session to peer `%s' `%s'\n", GNUNET_i2s (&s->target), http_plugin_address_to_string (plugin, s->addr, s->addrlen));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ plugin->name,
+ "Notifying about ended session to peer `%s' `%s'\n",
+ GNUNET_i2s (&s->target),
+ http_plugin_address_to_string (plugin, s->addr, s->addrlen));
notify_session_end (plugin, &s->target, s);
}
}
client_schedule (plugin, GNUNET_NO);
}
+
int
client_disconnect (struct Session *s)
{
if (s->client_put != NULL)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: %X Deleting outbound PUT session to peer `%s'\n",
+ "Client: %p Deleting outbound PUT session to peer `%s'\n",
s->client_put, GNUNET_i2s (&s->target));
mret = curl_multi_remove_handle (plugin->client_mh, s->client_put);
if (s->client_get != NULL)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: %X Deleting outbound GET session to peer `%s'\n",
+ "Client: %p Deleting outbound GET session to peer `%s'\n",
s->client_get, GNUNET_i2s (&s->target));
mret = curl_multi_remove_handle (plugin->client_mh, s->client_get);
return GNUNET_OK;
}
+
static void
client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_break (0);
return;
}
-
s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
-
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
-
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
- "Client: %X Waking up receive handle\n", s->client_get);
-
+ "Client: %p Waking up receive handle\n", s->client_get);
if (s->client_get != NULL)
curl_easy_pause (s->client_get, CURLPAUSE_CONT);
-
}
+
/**
-* Callback method used with libcurl
-* Method is called when libcurl needs to write data during sending
-* @param stream pointer where to write data
-* @param size size of an individual element
-* @param nmemb count of elements that can be written to the buffer
-* @param cls destination pointer, passed to the libcurl handle
-* @return bytes read from stream
-*/
+ * Callback method used with libcurl
+ * Method is called when libcurl needs to write data during sending
+ *
+ * @param stream pointer where to write data
+ * @param size size of an individual element
+ * @param nmemb count of elements that can be written to the buffer
+ * @param cls destination pointer, passed to the libcurl handle
+ * @return bytes read from stream
+ */
static size_t
client_receive (void *stream, size_t size, size_t nmemb, void *cls)
{
struct GNUNET_TIME_Relative delta =
GNUNET_TIME_absolute_get_difference (now, s->next_receive);
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: %X No inbound bandwidth available! Next read was delayed for %llu ms\n",
+ "Client: %p No inbound bandwidth available! Next read was delayed for %llu ms\n",
s->client_get, delta.rel_value);
if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_add_delayed (delta, &client_wake_up, s);
return CURLPAUSE_ALL;
}
-
-
- if (s->msg_tk == NULL)
+ if (NULL == s->msg_tk)
s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s);
-
GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, GNUNET_NO);
-
return len;
}
+
/**
* Callback method used with libcurl
* Method is called when libcurl needs to read data during sending
+ *
* @param stream pointer where to write data
* @param size size of an individual element
* @param nmemb count of elements that can be written to the buffer
{
struct Session *s = cls;
struct Plugin *plugin = s->plugin;
+ struct HTTP_Message *msg = s->msg_head;
size_t bytes_sent = 0;
size_t len;
if (GNUNET_YES != exist_session(plugin, s))
{
GNUNET_break (0);
- return GNUNET_SYSERR;
+ return 0;
}
-
- struct HTTP_Message *msg = s->msg_head;
-
- if (msg == NULL)
+ if (NULL == msg)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: %X Nothing to send! Suspending PUT handle!\n",
+ "Client: %p Nothing to send! Suspending PUT handle!\n",
s->client_put);
s->client_put_paused = GNUNET_YES;
return CURL_READFUNC_PAUSE;
}
-
- GNUNET_assert (msg != NULL);
/* data to send */
- if (msg->pos < msg->size)
- {
- /* data fit in buffer */
- if ((msg->size - msg->pos) <= (size * nmemb))
- {
- len = (msg->size - msg->pos);
- memcpy (stream, &msg->buf[msg->pos], len);
- msg->pos += len;
- bytes_sent = len;
- }
- else
- {
- len = size * nmemb;
- memcpy (stream, &msg->buf[msg->pos], len);
- msg->pos += len;
- bytes_sent = len;
- }
- }
- /* no data to send */
- else
- {
- GNUNET_assert (0);
- bytes_sent = 0;
- }
-
+ GNUNET_assert (msg->pos < msg->size);
+ /* calculate how much fits in buffer */
+ bytes_sent = GNUNET_MIN (msg->size - msg->pos,
+ size * nmemb);
+ memcpy (stream, &msg->buf[msg->pos], len);
+ msg->pos += len;
+ bytes_sent = len;
if (msg->pos == msg->size)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Client: %X Message with %u bytes sent, removing message from queue\n",
+ "Client: %p Message with %u bytes sent, removing message from queue\n",
s->client_put, msg->size, msg->pos);
/* Calling transmit continuation */
+ GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
if (NULL != msg->transmit_cont)
msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK);
- GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
GNUNET_free (msg);
}
return bytes_sent;
}
+
int
client_connect (struct Session *s)
{
return res;
}
+
int
client_start (struct Plugin *plugin)
{
return res;
}
+
void
client_stop (struct Plugin *plugin)
{
GNUNET_free_non_null (plugin->cert);
plugin->cert = NULL;
-#if VERBOSE_SERVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"No usable TLS certificate found, creating certificate\n");
-#endif
errno = 0;
cert_creation =
GNUNET_OS_start_process (GNUNET_NO, NULL, NULL,
* @param now GNUNET_YES to schedule execution immediately, GNUNET_NO to wait
* until timeout
*/
-
static void
server_reschedule (struct Plugin *plugin, struct MHD_Daemon *server, int now)
{
return GNUNET_OK;
}
+
/**
* Callback called by MHD when it needs data to send
* @param cls current session
server_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
{
struct Session *s = cls;
+ ssize_t bytes_read = 0;
+ struct HTTP_Message *msg;
+
GNUNET_assert (NULL != p);
if (GNUNET_NO == exist_session(p, s))
return 0;
-
- struct HTTP_Message *msg;
- int bytes_read = 0;
-
- //static int c = 0;
msg = s->msg_head;
- if (msg != NULL)
+ if (NULL != msg)
{
/* sending */
- if ((msg->size - msg->pos) <= max)
- {
- memcpy (buf, &msg->buf[msg->pos], (msg->size - msg->pos));
- bytes_read = msg->size - msg->pos;
- msg->pos += (msg->size - msg->pos);
- }
- else
- {
- memcpy (buf, &msg->buf[msg->pos], max);
- msg->pos += max;
- bytes_read = max;
- }
+ bytes_read = GNUNET_MIN (msg->size - msg->pos,
+ max);
+ memcpy (buf, &msg->buf[msg->pos], bytes_read);
+ msg->pos += bytes_read;
/* removing message */
if (msg->pos == msg->size)
{
+ GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
if (NULL != msg->transmit_cont)
msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK);
- GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
GNUNET_free (msg);
}
}
-
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
- "Server: %X: sent %u bytes\n", s, bytes_read);
-
+ "Server: %p: sent %u bytes\n", s, bytes_read);
return bytes_read;
}
int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000);
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: Setting timeout for %X to %u sec.\n", sc, to);
+ "Server: Setting timeout for %p to %u sec.\n", sc, to);
MHD_set_connection_option (mhd_connection, MHD_CONNECTION_OPTION_TIMEOUT, to);
struct MHD_Daemon *d = NULL;
if ((s->next_receive.abs_value <= now.abs_value))
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: %X: PUT with %u bytes forwarded to MST\n", s,
+ "Server: %p: PUT with %u bytes forwarded to MST\n", s,
*upload_data_size);
if (s->msg_tk == NULL)
{
{
t = s->server_recv;
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: Setting timeout for %X to %u sec.\n", t,
+ "Server: Setting timeout for %p to %u sec.\n", t,
to);
MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
to);
{
t = s->server_send;
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: Setting timeout for %X to %u sec.\n", t,
+ "Server: Setting timeout for %p to %u sec.\n", t,
to);
MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
to);
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Server: %X no inbound bandwidth available! Next read was delayed by %llu ms\n",
+ "Server: %p no inbound bandwidth available! Next read was delayed by %llu ms\n",
s, now.abs_value - s->next_receive.abs_value);
}
return MHD_YES;
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: %X peer `%s' GET on address `%s' disconnected\n",
+ "Server: %p peer `%s' GET on address `%s' disconnected\n",
s->server_send, GNUNET_i2s (&s->target),
http_plugin_address_to_string (NULL, s->addr, s->addrlen));
s->server_send = NULL;
if (sc->direction == _RECEIVE)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: %X peer `%s' PUT on address `%s' disconnected\n",
+ "Server: %p peer `%s' PUT on address `%s' disconnected\n",
s->server_recv, GNUNET_i2s (&s->target),
http_plugin_address_to_string (NULL, s->addr, s->addrlen));
s->server_recv = NULL;
if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected message %u with bits %u, but body did not match\n", n,
+ "Expected message %u with bits %u, but body did not match at position %u\n", n,
(unsigned char) n);
if (die_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (die_task);