/*
This file is part of GNUnet
- (C) 2010-2015 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2010-2015 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
#define LOG(kind,...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
+/**
+ * After how much inactivity should a UDP session time out?
+ */
#define UDP_SESSION_TIME_OUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
/**
/**
* We keep a defragmentation queue per sender address. How many
* sender addresses do we support at the same time? Memory consumption
- * is roughly a factor of 32k * UDP_MAX_MESSAGES_IN_DEFRAG times this
+ * is roughly a factor of 32k * #UDP_MAX_MESSAGES_IN_DEFRAG times this
* value. (So 128 corresponds to 12 MB and should suffice for
* connecting to roughly 128 peers via UDP).
*/
*/
struct GNUNET_TIME_Relative last_expected_msg_delay;
- /**
- * Address metrics (as set by the "update_address_metrics" by
- * the environment).
- */
- struct GNUNET_ATS_Information ats;
-
/**
* Our own address.
*/
*/
unsigned int rc;
+ /**
+ * Network type of the address.
+ */
+ enum GNUNET_ATS_Network_Type scope;
+
/**
* Is this session about to be destroyed (sometimes we cannot
* destroy a session immediately as below us on the stack
};
-/**
- * Closure for #process_inbound_tokenized_messages().
- */
-struct SourceInformation
-{
- /**
- * Sender identity.
- */
- struct GNUNET_PeerIdentity sender;
-
- /**
- * Associated session.
- */
- struct Session *session;
-
-};
-
/**
* Closure for #find_receive_context().
*/
if (NULL == plugin->sic)
return;
+ if (GNUNET_YES == session->in_destroy)
+ return; /* already destroyed, just RC>0 left-over actions */
memset (&info, 0, sizeof (info));
info.state = state;
info.is_inbound = GNUNET_SYSERR; /* hard to say */
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Calling continuation for %u byte message to `%s' with result %s\n",
- udpw->payload_size, GNUNET_i2s (&udpw->session->target),
+ udpw->payload_size,
+ GNUNET_i2s (&udpw->session->target),
(GNUNET_OK == result) ? "OK" : "SYSERR");
if (udpw->msg_size >= udpw->payload_size)
if (NULL != udpw->cont)
{
/* Transport continuation */
- udpw->cont (udpw->cont_cls, &udpw->session->target, result,
- udpw->payload_size, udpw->msg_size);
+ udpw->cont (udpw->cont_cls,
+ &udpw->session->target,
+ result,
+ udpw->payload_size,
+ udpw->msg_size);
}
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, unfragmented msgs, messages, sent, success", 1, GNUNET_NO);
+ "# UDP, unfragmented msgs, messages, sent, success",
+ 1,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, unfragmented msgs, bytes payload, sent, success",
- udpw->payload_size, GNUNET_NO);
+ "# UDP, unfragmented msgs, bytes payload, sent, success",
+ udpw->payload_size,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, unfragmented msgs, bytes overhead, sent, success", overhead,
- GNUNET_NO);
+ "# UDP, unfragmented msgs, bytes overhead, sent, success",
+ overhead,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO);
+ "# UDP, total, bytes overhead, sent",
+ overhead,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, total, bytes payload, sent", udpw->payload_size, GNUNET_NO);
+ "# UDP, total, bytes payload, sent",
+ udpw->payload_size,
+ GNUNET_NO);
break;
case UMT_MSG_FRAGMENTED_COMPLETE:
GNUNET_assert(NULL != udpw->frag_ctx);
if (udpw->frag_ctx->cont != NULL )
- udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target,
- GNUNET_OK, udpw->frag_ctx->payload_size,
- udpw->frag_ctx->on_wire_size);
+ udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls,
+ &udpw->session->target,
+ GNUNET_OK,
+ udpw->frag_ctx->payload_size,
+ udpw->frag_ctx->on_wire_size);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, messages, sent, success", 1, GNUNET_NO);
+ "# UDP, fragmented msgs, messages, sent, success",
+ 1,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, bytes payload, sent, success",
- udpw->payload_size, GNUNET_NO);
+ "# UDP, fragmented msgs, bytes payload, sent, success",
+ udpw->payload_size,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, bytes overhead, sent, success", overhead,
- GNUNET_NO);
+ "# UDP, fragmented msgs, bytes overhead, sent, success",
+ overhead,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO);
+ "# UDP, total, bytes overhead, sent",
+ overhead,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, total, bytes payload, sent", udpw->payload_size, GNUNET_NO);
+ "# UDP, total, bytes payload, sent",
+ udpw->payload_size,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, messages, pending", -1, GNUNET_NO);
+ "# UDP, fragmented msgs, messages, pending",
+ -1,
+ GNUNET_NO);
break;
case UMT_MSG_FRAGMENTED:
/* Fragmented message: enqueue next fragment */
if (NULL != udpw->cont)
- udpw->cont (udpw->cont_cls, &udpw->session->target, result,
- udpw->payload_size, udpw->msg_size);
+ udpw->cont (udpw->cont_cls,
+ &udpw->session->target,
+ result,
+ udpw->payload_size,
+ udpw->msg_size);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, fragments, sent, success", 1, GNUNET_NO);
+ "# UDP, fragmented msgs, fragments, sent, success",
+ 1,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, fragments bytes, sent, success",
- udpw->msg_size, GNUNET_NO);
+ "# UDP, fragmented msgs, fragments bytes, sent, success",
+ udpw->msg_size,
+ GNUNET_NO);
break;
case UMT_MSG_ACK:
/* No continuation */
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, ACK msgs, messages, sent, success", 1, GNUNET_NO);
+ "# UDP, ACK msgs, messages, sent, success",
+ 1,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, ACK msgs, bytes overhead, sent, success", overhead,
- GNUNET_NO);
+ "# UDP, ACK msgs, bytes overhead, sent, success",
+ overhead,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO);
+ "# UDP, total, bytes overhead, sent",
+ overhead,
+ GNUNET_NO);
break;
default:
GNUNET_break(0);
case UMT_MSG_UNFRAGMENTED:
/* Unfragmented message: failed to send */
if (NULL != udpw->cont)
- udpw->cont (udpw->cont_cls, &udpw->session->target, result,
- udpw->payload_size, overhead);
+ udpw->cont (udpw->cont_cls,
+ &udpw->session->target,
+ result,
+ udpw->payload_size,
+ overhead);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, unfragmented msgs, messages, sent, failure", 1, GNUNET_NO);
+ "# UDP, unfragmented msgs, messages, sent, failure",
+ 1,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, unfragmented msgs, bytes payload, sent, failure",
- udpw->payload_size, GNUNET_NO);
+ "# UDP, unfragmented msgs, bytes payload, sent, failure",
+ udpw->payload_size,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, unfragmented msgs, bytes overhead, sent, failure", overhead,
- GNUNET_NO);
+ "# UDP, unfragmented msgs, bytes overhead, sent, failure",
+ overhead,
+ GNUNET_NO);
break;
case UMT_MSG_FRAGMENTED_COMPLETE:
- GNUNET_assert(NULL != udpw->frag_ctx);
- if (udpw->frag_ctx->cont != NULL )
- udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target,
- GNUNET_SYSERR, udpw->frag_ctx->payload_size,
- udpw->frag_ctx->on_wire_size);
+ GNUNET_assert (NULL != udpw->frag_ctx);
+ if (udpw->frag_ctx->cont != NULL)
+ udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls,
+ &udpw->session->target,
+ GNUNET_SYSERR,
+ udpw->frag_ctx->payload_size,
+ udpw->frag_ctx->on_wire_size);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, messages, sent, failure", 1, GNUNET_NO);
+ "# UDP, fragmented msgs, messages, sent, failure",
+ 1,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, bytes payload, sent, failure",
- udpw->payload_size, GNUNET_NO);
+ "# UDP, fragmented msgs, bytes payload, sent, failure",
+ udpw->payload_size,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, bytes payload, sent, failure", overhead,
- GNUNET_NO);
+ "# UDP, fragmented msgs, bytes payload, sent, failure",
+ overhead,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, bytes payload, sent, failure", overhead,
- GNUNET_NO);
+ "# UDP, fragmented msgs, bytes payload, sent, failure",
+ overhead,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, messages, pending", -1, GNUNET_NO);
+ "# UDP, fragmented msgs, messages, pending",
+ -1,
+ GNUNET_NO);
break;
case UMT_MSG_FRAGMENTED:
- GNUNET_assert(NULL != udpw->frag_ctx);
+ GNUNET_assert (NULL != udpw->frag_ctx);
/* Fragmented message: failed to send */
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, fragments, sent, failure", 1, GNUNET_NO);
+ "# UDP, fragmented msgs, fragments, sent, failure",
+ 1,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, fragmented msgs, fragments bytes, sent, failure",
- udpw->msg_size, GNUNET_NO);
+ "# UDP, fragmented msgs, fragments bytes, sent, failure",
+ udpw->msg_size,
+ GNUNET_NO);
break;
case UMT_MSG_ACK:
/* ACK message: failed to send */
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, ACK msgs, messages, sent, failure", 1, GNUNET_NO);
+ "# UDP, ACK msgs, messages, sent, failure",
+ 1,
+ GNUNET_NO);
break;
default:
GNUNET_break(0);
/**
- * FIXME.
+ * We have completed our (attempt) to transmit a message
+ * that had to be fragmented -- either because we got an
+ * ACK saying that all fragments were received, or because
+ * of timeout / disconnect. Clean up our state.
+ *
+ * @param fc fragmentation context to clean up
+ * @param result #GNUNET_OK if we succeeded (got ACK),
+ * #GNUNET_SYSERR if the transmission failed
*/
static void
fragmented_message_done (struct UDP_FragmentationContext *fc,
while (NULL != udpw)
{
tmp = udpw->next;
- if ((udpw->frag_ctx != NULL )&& (udpw->frag_ctx == s->frag_ctx)){
- dequeue (plugin, udpw);
- call_continuation (udpw, GNUNET_SYSERR);
- GNUNET_free (udpw);
- }
+ if ( (udpw->frag_ctx != NULL) &&
+ (udpw->frag_ctx == s->frag_ctx) )
+ {
+ dequeue (plugin, udpw);
+ call_continuation (udpw, GNUNET_SYSERR);
+ GNUNET_free (udpw);
+ }
udpw = tmp;
}
}
GNUNET_assert (GNUNET_YES != s->in_destroy);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Session %p to peer `%s' address ended\n", s,
+ "Session %p to peer `%s' address ended\n",
+ s,
GNUNET_i2s (&s->target),
- udp_address_to_string (NULL,
+ udp_address_to_string (plugin,
s->address->address,
s->address->address_length));
/* stop timeout task */
s);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Session %p was idle for %s, disconnecting\n",
- s,
- GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT,
- GNUNET_YES));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Session %p was idle for %s, disconnecting\n",
+ s,
+ GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT,
+ GNUNET_YES));
/* call session destroy function */
udp_disconnect_session (plugin, s);
}
}
-/**
- * FIXME.
- */
-static struct Session *
-create_session (struct Plugin *plugin,
- const struct GNUNET_HELLO_Address *address)
-{
- struct Session *s;
-
- s = GNUNET_new (struct Session);
- s->plugin = plugin;
- s->address = GNUNET_HELLO_address_copy (address);
- s->target = address->peer;
- s->last_expected_ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- 250);
- s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS;
- s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO_ABS;
- s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO;
- s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT);
- s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT,
- &session_timeout, s);
- return s;
-}
-
-
/**
* Function obtain the network type for a session
*
- * @param cls closure ('struct Plugin*')
+ * @param cls closure (`struct Plugin *`)
* @param session the session
* @return the network type
*/
udp_get_network (void *cls,
struct Session *session)
{
- return ntohl (session->ats.value);
+ return session->scope;
}
void *value)
{
struct SessionCompareContext *cctx = cls;
- const struct GNUNET_HELLO_Address *address = cctx->address;
struct Session *s = value;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Comparing address %s <-> %s\n",
- udp_address_to_string (NULL,
- address->address,
- address->address_length),
- udp_address_to_string (NULL,
- s->address->address,
- s->address->address_length));
- if (0 == GNUNET_HELLO_address_cmp(s->address, cctx->address))
+ if (0 == GNUNET_HELLO_address_cmp (s->address,
+ cctx->address))
{
cctx->res = s;
return GNUNET_NO;
(address->address_length != sizeof (struct IPv6UdpAddress))))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Trying to locate session for address of unexpected length %u (should be %u or %u)\n"),
+ "Trying to locate session for address of unexpected length %u (should be %u or %u)\n",
address->address_length,
sizeof (struct IPv4UdpAddress),
sizeof (struct IPv6UdpAddress));
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Looking for existing session for peer `%s' `%s' \n",
GNUNET_i2s (&address->peer),
- udp_address_to_string(NULL, address->address, address->address_length));
+ udp_address_to_string (plugin,
+ address->address,
+ address->address_length));
GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions,
&address->peer,
&session_cmp_it,
struct Plugin *plugin = cls;
struct Session *s;
- s = create_session (plugin, address);
- s->ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
- s->ats.value = htonl (network_type);
+ s = GNUNET_new (struct Session);
+ s->plugin = plugin;
+ s->address = GNUNET_HELLO_address_copy (address);
+ s->target = address->peer;
+ s->last_expected_ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+ 250);
+ s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS;
+ s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO_ABS;
+ s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO;
+ s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT);
+ s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT,
+ &session_timeout, s);
+ s->scope = network_type;
- if (NULL == s)
- return NULL; /* protocol not supported or address invalid */
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Creating new session %p for peer `%s' address `%s'\n",
s,
* notify the plugin that a session is still active and in use and
* therefore the session timeout for this session has to be updated
*
- * @param cls closure
+ * @param cls closure with the `struct Plugin`
* @param peer which peer was the session for
* @param session which session is being updated
*/
* Creates a new outbound session the transport service will use to
* send data to the peer.
*
- * @param cls the plugin
+ * @param cls the `struct Plugin *`
* @param address the address
* @return the session or NULL of max connections exceeded
*/
if (NULL == address)
{
- GNUNET_break(0);
+ GNUNET_break (0);
return NULL;
}
if ( (address->address_length != sizeof(struct IPv4UdpAddress)) &&
(address->address_length != sizeof(struct IPv6UdpAddress)) )
+ {
+ GNUNET_break_op (0);
return NULL;
+ }
if (NULL != (s = udp_plugin_lookup_session (cls,
address)))
return s;
+ /* need to create new session */
if (sizeof (struct IPv4UdpAddress) == address->address_length)
{
struct sockaddr_in v4;
(const struct sockaddr *) &v4,
sizeof (v4));
}
- else if (sizeof (struct IPv6UdpAddress) == address->address_length)
+ if (sizeof (struct IPv6UdpAddress) == address->address_length)
{
struct sockaddr_in6 v6;
(const struct sockaddr *) &v6,
sizeof (v6));
}
-
- /* otherwise create new */
- return udp_plugin_create_session (cls, address, network_type);
+ return udp_plugin_create_session (cls,
+ address,
+ network_type);
}
else
{
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, total, bytes in buffers", udpw->msg_size, GNUNET_NO);
+ "# UDP, total, bytes in buffers",
+ udpw->msg_size,
+ GNUNET_NO);
plugin->bytes_in_buffer += udpw->msg_size;
}
GNUNET_STATISTICS_update (plugin->env->stats,
struct UDP_MessageWrapper * udpw;
struct UDPMessage *udp;
char mbuf[udpmlen];
- GNUNET_assert(plugin != NULL);
- GNUNET_assert(s != NULL);
if ( (s->address->address_length == sizeof(struct IPv6UdpAddress)) &&
(plugin->sockv6 == NULL) )
"UDP transmits %u-byte message to `%s' using address `%s'\n",
udpmlen,
GNUNET_i2s (&s->target),
- udp_address_to_string (NULL,
+ udp_address_to_string (plugin,
s->address->address,
s->address->address_length));
* to the service.
*
* @param cls the `struct Plugin *`
- * @param client the `struct SourceInformation *`
+ * @param client the `struct Session *`
* @param hdr the actual message
* @return #GNUNET_OK (always)
*/
const struct GNUNET_MessageHeader *hdr)
{
struct Plugin *plugin = cls;
- struct SourceInformation *si = client;
+ struct Session *session = client;
struct GNUNET_TIME_Relative delay;
- GNUNET_assert (NULL != si->session);
- if (GNUNET_YES == si->session->in_destroy)
+ if (GNUNET_YES == session->in_destroy)
return GNUNET_OK;
/* setup ATS */
- GNUNET_break (ntohl (si->session->ats.value) != GNUNET_ATS_NET_UNSPECIFIED);
- reschedule_session_timeout (si->session);
+ reschedule_session_timeout (session);
delay = plugin->env->receive (plugin->env->cls,
- si->session->address,
- si->session,
+ session->address,
+ session,
hdr);
- plugin->env->update_address_metrics (plugin->env->cls,
- si->session->address,
- si->session,
- &si->session->ats, 1);
- si->session->flow_delay_for_other_peer = delay;
+ session->flow_delay_for_other_peer = delay;
return GNUNET_OK;
}
size_t udp_addr_len,
enum GNUNET_ATS_Network_Type network_type)
{
- struct SourceInformation si;
struct Session *s;
struct GNUNET_HELLO_Address *address;
+ GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != network_type);
if (0 != ntohl (msg->reserved))
{
GNUNET_break_op(0);
udp_addr,
udp_addr_len,
GNUNET_HELLO_ADDRESS_INFO_NONE);
- if (NULL == (s = udp_plugin_lookup_session (plugin, address)))
+ if (NULL ==
+ (s = udp_plugin_lookup_session (plugin, address)))
{
s = udp_plugin_create_session (plugin,
address,
network_type);
plugin->env->session_start (plugin->env->cls,
- address, s, NULL, 0);
+ address,
+ s,
+ s->scope);
notify_session_monitor (s->plugin,
s,
GNUNET_TRANSPORT_SS_INIT);
GNUNET_free (address);
/* iterate over all embedded messages */
- si.session = s;
- si.sender = msg->sender;
s->rc++;
GNUNET_SERVER_mst_receive (plugin->mst,
- &si,
+ s,
(const char *) &msg[1],
ntohs (msg->header.size) - sizeof(struct UDPMessage),
GNUNET_YES,
GNUNET_HELLO_address_free (address);
if (NULL == s)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Trying to transmit ACK to peer `%s' but no session found!\n",
- udp_address_to_string (rc->plugin,
- rc->udp_addr,
- rc->udp_addr_len));
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Trying to transmit ACK to peer `%s' but no session found!\n",
+ udp_address_to_string (rc->plugin,
+ rc->udp_addr,
+ rc->udp_addr_len));
GNUNET_CONTAINER_heap_remove_node (rc->hnode);
GNUNET_DEFRAGMENT_context_destroy (rc->defrag);
GNUNET_free (rc);
GNUNET_HELLO_ADDRESS_INFO_NONE);
s = udp_plugin_lookup_session (plugin,
address);
- GNUNET_HELLO_address_free (address);
- if ( (NULL == s) ||
- (NULL == s->frag_ctx) )
+ if (NULL == s)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "UDP session for ACK not found\n");
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "UDP session of address %s for ACK not found\n",
+ udp_address_to_string (plugin,
+ address->address,
+ address->address_length));
+ GNUNET_HELLO_address_free (address);
return;
}
+ if (NULL == s->frag_ctx)
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Fragmentation context of address %s for ACK not found\n",
+ udp_address_to_string (plugin,
+ address->address,
+ address->address_length));
+ GNUNET_HELLO_address_free (address);
+ return;
+ }
+ GNUNET_HELLO_address_free (address);
flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "We received a sending delay of %s\n",
+ "We received a sending delay of %s for %s\n",
GNUNET_STRINGS_relative_time_to_string (flow_delay,
- GNUNET_YES));
+ GNUNET_YES),
+ GNUNET_i2s (&udp_ack->sender));
s->flow_delay_from_other_peer = GNUNET_TIME_relative_to_absolute (flow_delay);
ack = (const struct GNUNET_MessageHeader *) &udp_ack[1];
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Message full ACK'ed\n",
- (unsigned int ) ntohs (msg->size),
+ "Message from %s at %s full ACK'ed\n",
GNUNET_i2s (&udp_ack->sender),
udp_address_to_string (plugin,
udp_addr,
udp_addr_len));
-
/* Remove fragmented message after successful sending */
fragmented_message_done (s->frag_ctx,
GNUNET_OK);
/**
- * FIXME.
+ * Removes messages from the transmission queue that have
+ * timed out, and then selects a message that should be
+ * transmitted next.
+ *
+ * @param plugin the UDP plugin
+ * @param sock which socket should we process the queue for (v4 or v6)
+ * @return message selected for transmission, or NULL for none
*/
static struct UDP_MessageWrapper *
-remove_timeout_messages_and_select (struct UDP_MessageWrapper *head,
+remove_timeout_messages_and_select (struct Plugin *plugin,
struct GNUNET_NETWORK_Handle *sock)
{
struct UDP_MessageWrapper *udpw = NULL;
struct GNUNET_TIME_Relative remaining;
struct Session *session;
- struct Plugin *plugin;
int removed;
removed = GNUNET_NO;
- udpw = head;
+ udpw = (sock == plugin->sockv4)
+ ? plugin->ipv4_queue_head
+ : plugin->ipv6_queue_head;
while (NULL != udpw)
{
session = udpw->session;
- plugin = session->plugin;
/* Find messages with timeout */
remaining = GNUNET_TIME_absolute_get_remaining (udpw->timeout);
if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us)
"# UDP, total, messages, sent, timeout",
1,
GNUNET_NO);
- call_continuation (udpw, GNUNET_SYSERR);
+ call_continuation (udpw,
+ GNUNET_SYSERR);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Fragment for message for peer `%s' with size %u timed out\n",
GNUNET_i2s (&udpw->session->target),
udpw->frag_ctx->payload_size,
GNUNET_NO);
/* Remove fragmented message due to timeout */
- fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR);
+ fragmented_message_done (udpw->frag_ctx,
+ GNUNET_SYSERR);
break;
case UMT_MSG_ACK:
GNUNET_STATISTICS_update (plugin->env->stats,
"ACK Message for peer `%s' with size %u timed out\n",
GNUNET_i2s (&udpw->session->target),
udpw->payload_size);
- call_continuation (udpw, GNUNET_SYSERR);
+ call_continuation (udpw,
+ GNUNET_SYSERR);
removed = GNUNET_YES;
- dequeue (plugin, udpw);
- GNUNET_free(udpw);
+ dequeue (plugin,
+ udpw);
+ GNUNET_free (udpw);
break;
default:
break;
/* Message is delayed, try next */
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Message for peer `%s' (%u bytes) is delayed for %s\n",
- GNUNET_i2s (&udpw->session->target), udpw->payload_size,
- GNUNET_STRINGS_relative_time_to_string (remaining, GNUNET_YES));
+ GNUNET_i2s (&udpw->session->target),
+ udpw->payload_size,
+ GNUNET_STRINGS_relative_time_to_string (remaining,
+ GNUNET_YES));
udpw = udpw->next;
}
}
/**
- * FIXME.
+ * It is time to try to transmit a UDP message. Select one
+ * and send.
+ *
+ * @param plugin the plugin
+ * @param sock which socket (v4/v6) to send on
+ * @return number of bytes transmitted, #GNUNET_SYSERR on failure
*/
static size_t
udp_select_send (struct Plugin *plugin,
struct UDP_MessageWrapper *udpw;
/* Find message to send */
- udpw = remove_timeout_messages_and_select ((sock == plugin->sockv4)
- ? plugin->ipv4_queue_head
- : plugin->ipv6_queue_head,
+ udpw = remove_timeout_messages_and_select (plugin,
sock);
if (NULL == udpw)
return 0; /* No message to send */
a4.sin_len = sizeof (a4);
#endif
a4.sin_port = u4->u4_port;
- memcpy (&a4.sin_addr, &u4->ipv4_addr, sizeof(struct in_addr));
+ memcpy (&a4.sin_addr,
+ &u4->ipv4_addr,
+ sizeof(struct in_addr));
a = (struct sockaddr *) &a4;
slen = sizeof (a4);
}
}
else
{
- call_continuation (udpw, GNUNET_OK);
- dequeue (plugin, udpw);
+ call_continuation (udpw,
+ GNUNET_OK);
+ dequeue (plugin,
+ udpw);
notify_session_monitor (plugin,
udpw->session,
GNUNET_TRANSPORT_SS_UPDATE);
GNUNET_free (udpw);
return GNUNET_SYSERR;
}
-
sent = GNUNET_NETWORK_socket_sendto (sock,
udpw->msg_buf,
udpw->msg_size,
if (GNUNET_SYSERR == sent)
{
/* Failure */
- analyze_send_error (plugin, a, slen, errno);
- call_continuation (udpw, GNUNET_SYSERR);
+ analyze_send_error (plugin,
+ a,
+ slen,
+ errno);
+ call_continuation (udpw,
+ GNUNET_SYSERR);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, total, bytes, sent, failure", sent, GNUNET_NO);
+ "# UDP, total, bytes, sent, failure",
+ sent,
+ GNUNET_NO);
GNUNET_STATISTICS_update (plugin->env->stats,
- "# UDP, total, messages, sent, failure", 1, GNUNET_NO);
+ "# UDP, total, messages, sent, failure",
+ 1,
+ GNUNET_NO);
}
else
{
notify_session_monitor (plugin,
udpw->session,
GNUNET_TRANSPORT_SS_UPDATE);
- GNUNET_free(udpw);
+ GNUNET_free (udpw);
return sent;
}
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"socket");
- LOG(GNUNET_ERROR_TYPE_WARNING,
- "Disabling IPv4 since it is not supported on this system!\n");
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Disabling IPv4 since it is not supported on this system!\n");
plugin->enable_ipv4 = GNUNET_NO;
}
else
p->sessions = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
p->defrag_ctxs = GNUNET_CONTAINER_heap_create (
GNUNET_CONTAINER_HEAP_ORDER_MIN);
- p->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, p);
- GNUNET_BANDWIDTH_tracker_init (&p->tracker, NULL, NULL,
- GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps), 30);
+ p->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages,
+ p);
+ GNUNET_BANDWIDTH_tracker_init (&p->tracker,
+ NULL,
+ NULL,
+ GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps),
+ 30);
LOG(GNUNET_ERROR_TYPE_DEBUG,
"Setting up sockets\n");
res = setup_sockets (p,