};
+/**
+ * We have been notified that our readset has something to read. We don't
+ * know which socket needs to be read, so we have to check each one
+ * Then reschedule this function to be called again once more is available.
+ *
+ * @param cls the plugin handle
+ * @param tc the scheduling context (for rescheduling this function again)
+ */
+static void
+udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+/**
+ * We have been notified that our readset has something to read. We don't
+ * know which socket needs to be read, so we have to check each one
+ * Then reschedule this function to be called again once more is available.
+ *
+ * @param cls the plugin handle
+ * @param tc the scheduling context (for rescheduling this function again)
+ */
+static void
+udp_plugin_select_v6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
* Function called for a quick conversion of the binary address to
}
+/**
+ * Function called to convert a string address to
+ * a binary address.
+ *
+ * @param cls closure ('struct Plugin*')
+ * @param addr string address
+ * @param addrlen length of the address
+ * @param buf location to store the buffer
+ * @param added location to store the number of bytes in the buffer.
+ * If the function returns GNUNET_SYSERR, its contents are undefined.
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ */
+int
+udp_string_to_address (void *cls, const char *addr, uint16_t addrlen,
+ void **buf, size_t *added)
+{
+ struct sockaddr_storage socket_address;
+ int ret = GNUNET_STRINGS_to_address_ip (addr, addrlen,
+ &socket_address);
+
+ if (ret != GNUNET_OK)
+ return GNUNET_SYSERR;
+
+ if (socket_address.ss_family == AF_INET)
+ {
+ struct IPv4UdpAddress *u4;
+ struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address;
+ u4 = GNUNET_malloc (sizeof (struct IPv4UdpAddress));
+ u4->ipv4_addr = in4->sin_addr.s_addr;
+ u4->u4_port = in4->sin_port;
+ *buf = u4;
+ *added = sizeof (struct IPv4UdpAddress);
+ }
+ else if (socket_address.ss_family == AF_INET6)
+ {
+ struct IPv6UdpAddress *u6;
+ struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address;
+ u6 = GNUNET_malloc (sizeof (struct IPv6UdpAddress));
+ u6->ipv6_addr = in6->sin6_addr;
+ u6->u6_port = in6->sin6_port;
+ *buf = u6;
+ *added = sizeof (struct IPv6UdpAddress);
+ }
+ return GNUNET_SYSERR;
+}
+
+
/**
* Append our port and forward the result.
*
struct Plugin *plugin = cls;
struct Session *s = value;
struct UDPMessageWrapper *udpw;
+ struct UDPMessageWrapper *next;
#if DEBUG_UDP
LOG (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_i2s (&s->target),
GNUNET_a2s (s->sock_addr, s->addrlen));
#endif
- plugin->env->session_end (plugin->env->cls, &s->target, s);
if (s->frag_ctx != NULL)
{
s->frag_ctx = NULL;
}
- udpw = plugin->msg_head;
+ udpw = plugin->ipv4_queue_head;
+ while (udpw != NULL)
+ {
+ next = udpw->next;
+ if (udpw->session == s)
+ {
+ GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
+
+ if (udpw->cont != NULL)
+ udpw->cont (udpw->cont_cls, &s->target, GNUNET_SYSERR);
+ GNUNET_free (udpw);
+ }
+ udpw = next;
+ }
+
+ udpw = plugin->ipv6_queue_head;
while (udpw != NULL)
{
+ next = udpw->next;
if (udpw->session == s)
{
- GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, udpw);
+ GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
if (udpw->cont != NULL)
udpw->cont (udpw->cont_cls, &s->target, GNUNET_SYSERR);
GNUNET_free (udpw);
}
- udpw = plugin->msg_head;
+ udpw = next;
}
+ plugin->env->session_end (plugin->env->cls, &s->target, s);
+
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_remove (plugin->sessions,
&s->target.hashPubKey,
#endif
/* Clean up sessions */
GNUNET_CONTAINER_multihashmap_get_multiple (plugin->sessions, &target->hashPubKey, &disconnect_and_free_it, plugin);
-
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "FREEED SESSIONS from peer `%s'\n", GNUNET_i2s (target));
}
static struct Session *
{
struct Session * s = NULL;
struct Plugin * plugin = cls;
+ struct IPv6UdpAddress * udp_a6;
+ struct IPv4UdpAddress * udp_a4;
GNUNET_assert (plugin != NULL);
GNUNET_assert (address != NULL);
+
if ((address->address == NULL) ||
((address->address_length != sizeof (struct IPv4UdpAddress)) &&
(address->address_length != sizeof (struct IPv6UdpAddress))))
return NULL;
}
+ if (address->address_length == sizeof (struct IPv4UdpAddress))
+ {
+ if (plugin->sockv4 == NULL)
+ return NULL;
+ udp_a4 = (struct IPv4UdpAddress *) address->address;
+ if (udp_a4->u4_port == 0)
+ return NULL;
+ }
+
+ if (address->address_length == sizeof (struct IPv6UdpAddress))
+ {
+ if (plugin->sockv6 == NULL)
+ return NULL;
+ udp_a6 = (struct IPv6UdpAddress *) address->address;
+ if (udp_a6->u6_port == 0)
+ return NULL;
+ }
+
/* check if session already exists */
struct SessionCompareContext cctx;
cctx.addr = address;
return s;
}
+static void enqueue (struct Plugin *plugin, struct UDPMessageWrapper * udpw)
+{
+
+ if (udpw->session->addrlen == sizeof (struct sockaddr_in))
+ GNUNET_CONTAINER_DLL_insert(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
+ if (udpw->session->addrlen == sizeof (struct sockaddr_in6))
+ GNUNET_CONTAINER_DLL_insert(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
+}
+
/**
* Function that is called with messages created by the fragmentation
* module. In the case of the 'proc' callback of the
struct FragmentationContext *frag_ctx = cls;
struct Plugin *plugin = frag_ctx->plugin;
struct UDPMessageWrapper * udpw;
+ struct Session *s;
size_t msg_len = ntohs (msg->size);
udpw = GNUNET_malloc (sizeof (struct UDPMessageWrapper) + msg_len);
udpw->session = frag_ctx->session;
+ s = udpw->session;
udpw->udp = (char *) &udpw[1];
udpw->msg_size = msg_len;
udpw->frag_ctx = frag_ctx;
memcpy (udpw->udp, msg, msg_len);
- GNUNET_CONTAINER_DLL_insert(plugin->msg_head, plugin->msg_tail, udpw);
+ enqueue (plugin, udpw);
+
+
+ if (s->addrlen == sizeof (struct sockaddr_in))
+ {
+ if (plugin->with_v4_ws == GNUNET_NO)
+ {
+ if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel(plugin->select_task);
+
+ plugin->select_task =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->rs_v4,
+ plugin->ws_v4,
+ &udp_plugin_select, plugin);
+ plugin->with_v4_ws = GNUNET_YES;
+ }
+ }
+
+ else if (s->addrlen == sizeof (struct sockaddr_in6))
+ {
+ if (plugin->with_v6_ws == GNUNET_NO)
+ {
+ if (plugin->select_task_v6 != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel(plugin->select_task_v6);
+
+ plugin->select_task_v6 =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->rs_v6,
+ plugin->ws_v6,
+ &udp_plugin_select_v6, plugin);
+ plugin->with_v6_ws = GNUNET_YES;
+ }
+ }
+
}
+
+
/**
* Function that can be used by the transport service to transmit
* a message using the plugin. Note that in the case of a
* a fresh connection to another peer.
*
* @param cls closure
- * @param session which session must be used
+ * @param s which session must be used
* @param msgbuf the message to transmit
* @param msgbuf_size number of bytes in 'msgbuf'
* @param priority how important is the message (most plugins will
GNUNET_assert (plugin != NULL);
GNUNET_assert (s != NULL);
+ if ((s->addrlen == sizeof (struct sockaddr_in6)) && (plugin->sockv6 == NULL))
+ return GNUNET_SYSERR;
+
+ if ((s->addrlen == sizeof (struct sockaddr_in)) && (plugin->sockv4 == NULL))
+ return GNUNET_SYSERR;
+
+
if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
{
GNUNET_break (0);
memcpy (udpw->udp, udp, sizeof (struct UDPMessage));
memcpy (&udpw->udp[sizeof (struct UDPMessage)], msgbuf, msgbuf_size);
- GNUNET_CONTAINER_DLL_insert(plugin->msg_head, plugin->msg_tail, udpw);
+ enqueue (plugin, udpw);
}
else
{
s->frag_ctx = frag_ctx;
}
- return mlen;
-}
-static ssize_t udp_plugin_send_wrapper (void *cls,
- const struct
- GNUNET_PeerIdentity *
- target,
- const char *msgbuf,
- size_t msgbuf_size,
- uint32_t priority,
- struct
- GNUNET_TIME_Relative
- timeout,
- struct Session * session,
- const void *addr,
- size_t addrlen,
- int force_address,
- GNUNET_TRANSPORT_TransmitContinuation
- cont, void *cont_cls)
-{
- int ret;
- struct Session * s = NULL;
- struct GNUNET_HELLO_Address * ha = NULL;
+ if (s->addrlen == sizeof (struct sockaddr_in))
+ {
+ if (plugin->with_v4_ws == GNUNET_NO)
+ {
+ if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel(plugin->select_task);
+
+ plugin->select_task =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->rs_v4,
+ plugin->ws_v4,
+ &udp_plugin_select, plugin);
+ plugin->with_v4_ws = GNUNET_YES;
+ }
+ }
- ha = GNUNET_HELLO_address_allocate(target, "", addr,addrlen);
- GNUNET_assert (ha != NULL);
- s = udp_plugin_get_session(cls, ha);
- GNUNET_assert (s != NULL);
- GNUNET_free (ha);
- ret = udp_plugin_send (cls, s, msgbuf, msgbuf_size, priority, timeout, cont, cont_cls);
+ else if (s->addrlen == sizeof (struct sockaddr_in6))
+ {
+ if (plugin->with_v6_ws == GNUNET_NO)
+ {
+ if (plugin->select_task_v6 != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel(plugin->select_task_v6);
+
+ plugin->select_task_v6 =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->rs_v6,
+ plugin->ws_v6,
+ &udp_plugin_select_v6, plugin);
+ plugin->with_v6_ws = GNUNET_YES;
+ }
+ }
- return ret;
+ return mlen;
}
struct Session * s = NULL;
struct IPv4UdpAddress u4;
struct IPv6UdpAddress u6;
- struct GNUNET_ATS_Information ats;
const void *arg;
size_t args;
return;
}
- ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
- ats.value = htonl (GNUNET_ATS_NET_UNSPECIFIED);
/* convert address */
switch (sender_addr->sa_family)
{
&l_ctx);
s = l_ctx.res;
- GNUNET_assert (s != NULL);
+ if (NULL == s)
+ return;
if (s->flow_delay_for_other_peer.rel_value <= UINT32_MAX)
delay = s->flow_delay_for_other_peer.rel_value;
udp_ack->sender = *rc->plugin->env->my_identity;
memcpy (&udp_ack[1], msg, ntohs (msg->size));
- GNUNET_CONTAINER_DLL_insert(rc->plugin->msg_head, rc->plugin->msg_tail, udpw);
+ enqueue (rc->plugin, udpw);
}
#endif
s->last_expected_delay = GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag);
- struct UDPMessageWrapper * udpw = plugin->msg_head;
- while (udpw!= NULL)
+ struct UDPMessageWrapper * udpw = NULL;
+ if (s->addrlen == sizeof (struct sockaddr_in6))
{
- if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == s->frag_ctx))
+ udpw = plugin->ipv6_queue_head;
+ while (udpw!= NULL)
{
- GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, udpw);
- GNUNET_free (udpw);
+ if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == s->frag_ctx))
+ {
+ GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
+ GNUNET_free (udpw);
+ }
+ udpw = udpw->next;
+ }
+ }
+ if (s->addrlen == sizeof (struct sockaddr_in))
+ {
+ udpw = plugin->ipv4_queue_head;
+ while (udpw!= NULL)
+ {
+ if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == s->frag_ctx))
+ {
+ GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
+ GNUNET_free (udpw);
+ }
+ udpw = udpw->next;
}
- udpw = udpw->next;
}
if (s->frag_ctx->cont != NULL)
}
size_t
-udp_select_send (struct Plugin *plugin)
+udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
{
ssize_t sent;
size_t slen;
struct GNUNET_TIME_Absolute max;
struct GNUNET_TIME_Absolute ;
- struct UDPMessageWrapper *udpw = plugin->msg_head;
+ struct UDPMessageWrapper *udpw = NULL;
+
+ if (sock == plugin->sockv4)
+ {
+ udpw = plugin->ipv4_queue_head;
+ }
+ else if (sock == plugin->sockv6)
+ {
+ udpw = plugin->ipv6_queue_head;
+ }
+ else
+ {
+ GNUNET_break (0);
+ return 0;
+ }
+
const struct sockaddr * sa = udpw->session->sock_addr;
+ slen = udpw->session->addrlen;
max = GNUNET_TIME_absolute_max(udpw->timeout, GNUNET_TIME_absolute_get());
#endif
}
- GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, udpw);
- GNUNET_free (udpw);
- udpw = plugin->msg_head;
+ if (sock == plugin->sockv4)
+ {
+ GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
+ GNUNET_free (udpw);
+ udpw = plugin->ipv4_queue_head;
+ }
+ else if (sock == plugin->sockv6)
+ {
+ GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
+ GNUNET_free (udpw);
+ udpw = plugin->ipv6_queue_head;
+ }
}
else
{
udpw = udpw->next;
}
}
-
}
if (udpw == NULL)
return 0;
}
- switch (sa->sa_family)
+ sent = GNUNET_NETWORK_socket_sendto (sock, udpw->udp, udpw->msg_size, sa, slen);
+
+ if (GNUNET_SYSERR == sent)
{
- case AF_INET:
- if (NULL == plugin->sockv4)
- return 0;
- sent =
- GNUNET_NETWORK_socket_sendto (plugin->sockv4, udpw->udp, udpw->msg_size,
- sa, slen = sizeof (struct sockaddr_in));
- break;
- case AF_INET6:
- if (NULL == plugin->sockv6)
- return 0;
- sent =
- GNUNET_NETWORK_socket_sendto (plugin->sockv6, udpw->udp, udpw->msg_size,
- sa, slen = sizeof (struct sockaddr_in6));
- break;
- default:
- GNUNET_break (0);
- return 0;
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "UDP could not transmit %u-byte message to `%s': `%s'\n",
+ (unsigned int) (udpw->msg_size), GNUNET_a2s (sa, slen),
+ STRERROR (errno));
+ if (udpw->cont != NULL)
+ udpw->cont (udpw->cont_cls, &udpw->session->target, GNUNET_SYSERR);
}
- if (GNUNET_SYSERR == sent)
+ else
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "UDP transmitted %u-byte message to %s (%d: %s)\n",
+ "UDP transmitted %u-byte message to `%s' (%d: %s)\n",
(unsigned int) (udpw->msg_size), GNUNET_a2s (sa, slen), (int) sent,
(sent < 0) ? STRERROR (errno) : "ok");
- if (udpw->cont != NULL)
- udpw->cont (udpw->cont_cls, &udpw->session->target, GNUNET_SYSERR);
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "UDP transmitted %u-byte message to %s (%d: %s)\n",
- (unsigned int) (udpw->msg_size), GNUNET_a2s (sa, slen), (int) sent,
- (sent < 0) ? STRERROR (errno) : "ok");
-
/* This was just a message fragment */
if (udpw->frag_ctx != NULL)
{
udpw->cont (udpw->cont_cls, &udpw->session->target, GNUNET_OK);
}
- GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, udpw);
+ if (sock == plugin->sockv4)
+ GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
+ else if (sock == plugin->sockv6)
+ GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
GNUNET_free (udpw);
+ udpw = NULL;
return sent;
}
plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
return;
+ plugin->with_v4_ws = GNUNET_NO;
if ((tc->reason & GNUNET_SCHEDULER_REASON_READ_READY) != 0)
{
if ((NULL != plugin->sockv4) &&
(GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4)))
udp_select_read (plugin, plugin->sockv4);
- if ((NULL != plugin->sockv6) &&
- (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6)))
- udp_select_read (plugin, plugin->sockv6);
+
}
if ((tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0)
{
- if (plugin->msg_head != NULL)
- udp_select_send (plugin);
+ if ((NULL != plugin->sockv4) && (plugin->ipv4_queue_head != NULL) &&
+ (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv4)))
+ {
+ udp_select_send (plugin, plugin->sockv4);
+ }
}
+ if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (plugin->select_task);
plugin->select_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
- plugin->ws, &udp_plugin_select, plugin);
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->rs_v4,
+ (plugin->ipv4_queue_head != NULL) ? plugin->ws_v4 : NULL,
+ &udp_plugin_select, plugin);
+ if (plugin->ipv4_queue_head != NULL)
+ plugin->with_v4_ws = GNUNET_YES;
+ else
+ plugin->with_v4_ws = GNUNET_NO;
+}
+
+/**
+ * We have been notified that our readset has something to read. We don't
+ * know which socket needs to be read, so we have to check each one
+ * Then reschedule this function to be called again once more is available.
+ *
+ * @param cls the plugin handle
+ * @param tc the scheduling context (for rescheduling this function again)
+ */
+static void
+udp_plugin_select_v6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct Plugin *plugin = cls;
+
+ plugin->select_task_v6 = GNUNET_SCHEDULER_NO_TASK;
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+ return;
+
+ plugin->with_v6_ws = GNUNET_NO;
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_READ_READY) != 0)
+ {
+ if ((NULL != plugin->sockv6) &&
+ (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6)))
+ udp_select_read (plugin, plugin->sockv6);
+ }
+
+ if ((tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0)
+ {
+ if ((NULL != plugin->sockv6) && (plugin->ipv6_queue_head != NULL) &&
+ (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv6)))
+ {
+ udp_select_send (plugin, plugin->sockv6);
+ }
+ }
+ if (plugin->select_task_v6 != GNUNET_SCHEDULER_NO_TASK)
+ GNUNET_SCHEDULER_cancel (plugin->select_task_v6);
+ plugin->select_task_v6 = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->rs_v6,
+ (plugin->ipv6_queue_head != NULL) ? plugin->ws_v6 : NULL,
+ &udp_plugin_select_v6, plugin);
+ if (plugin->ipv6_queue_head != NULL)
+ plugin->with_v6_ws = GNUNET_YES;
+ else
+ plugin->with_v6_ws = GNUNET_NO;
}
plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0);
if (NULL == plugin->sockv6)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Disabling IPv6 since it is not supported on this system!\n");
+ plugin->enable_ipv6 = GNUNET_NO;
}
else
{
#if HAVE_SOCKADDR_IN_SIN_LEN
- serverAddrv6.sin6_len = sizeof (serverAddrv6);
+ serverAddrv6->sin6_len = sizeof (serverAddrv6);
#endif
serverAddrv6->sin6_family = AF_INET6;
serverAddrv6->sin6_addr = in6addr_any;
else
{
#if HAVE_SOCKADDR_IN_SIN_LEN
- serverAddrv4.sin_len = sizeof (serverAddrv4);
+ serverAddrv4->sin_len = sizeof (serverAddrv4);
#endif
serverAddrv4->sin_family = AF_INET;
serverAddrv4->sin_addr.s_addr = INADDR_ANY;
}
/* Create file descriptors */
- plugin->rs = GNUNET_NETWORK_fdset_create ();
- plugin->ws = GNUNET_NETWORK_fdset_create ();
- GNUNET_NETWORK_fdset_zero (plugin->rs);
- GNUNET_NETWORK_fdset_zero (plugin->ws);
+ plugin->rs_v4 = GNUNET_NETWORK_fdset_create ();
+ plugin->ws_v4 = GNUNET_NETWORK_fdset_create ();
+ GNUNET_NETWORK_fdset_zero (plugin->rs_v4);
+ GNUNET_NETWORK_fdset_zero (plugin->ws_v4);
if (NULL != plugin->sockv4)
{
- GNUNET_NETWORK_fdset_set (plugin->rs, plugin->sockv4);
- GNUNET_NETWORK_fdset_set (plugin->ws, plugin->sockv4);
- }
- if (NULL != plugin->sockv6)
- {
- GNUNET_NETWORK_fdset_set (plugin->rs, plugin->sockv6);
- GNUNET_NETWORK_fdset_set (plugin->ws, plugin->sockv6);
+ GNUNET_NETWORK_fdset_set (plugin->rs_v4, plugin->sockv4);
+ GNUNET_NETWORK_fdset_set (plugin->ws_v4, plugin->sockv4);
}
if (sockets_created == 0)
plugin->select_task =
GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
GNUNET_SCHEDULER_NO_TASK,
- GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
- plugin->ws, &udp_plugin_select, plugin);
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->rs_v4,
+ NULL,
+ &udp_plugin_select, plugin);
+ plugin->with_v4_ws = GNUNET_NO;
+
+ if (plugin->enable_ipv6 == GNUNET_YES)
+ {
+ plugin->rs_v6 = GNUNET_NETWORK_fdset_create ();
+ plugin->ws_v6 = GNUNET_NETWORK_fdset_create ();
+ GNUNET_NETWORK_fdset_zero (plugin->rs_v6);
+ GNUNET_NETWORK_fdset_zero (plugin->ws_v6);
+ if (NULL != plugin->sockv6)
+ {
+ GNUNET_NETWORK_fdset_set (plugin->rs_v6, plugin->sockv6);
+ GNUNET_NETWORK_fdset_set (plugin->ws_v6, plugin->sockv6);
+ }
+
+ plugin->select_task_v6 =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ plugin->rs_v6,
+ NULL,
+ &udp_plugin_select_v6, plugin);
+ plugin->with_v6_ws = GNUNET_NO;
+ }
plugin->nat = GNUNET_NAT_register (plugin->env->cfg,
GNUNET_NO, plugin->port,
int res;
+ if (NULL == env->receive)
+ {
+ /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
+ initialze the plugin or the API */
+ api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
+ api->cls = NULL;
+ api->address_pretty_printer = &udp_plugin_address_pretty_printer;
+ api->address_to_string = &udp_address_to_string;
+ api->string_to_address = &udp_string_to_address;
+ return api;
+ }
+
/* Get port number */
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "PORT",
api->disconnect = &udp_disconnect;
api->address_pretty_printer = &udp_plugin_address_pretty_printer;
api->address_to_string = &udp_address_to_string;
+ api->string_to_address = &udp_string_to_address;
api->check_address = &udp_plugin_check_address;
api->get_session = &udp_plugin_get_session;
- api->send = &udp_plugin_send_wrapper;
- api->send_with_session = &udp_plugin_send;
+ api->send = &udp_plugin_send;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Setting up sockets\n");
res = setup_sockets (plugin, &serverAddrv6, &serverAddrv4);
return api;
}
-int heap_cleanup_iterator (void *cls,
- struct GNUNET_CONTAINER_HeapNode *
- node, void *element,
- GNUNET_CONTAINER_HeapCostType
- cost)
+
+static int
+heap_cleanup_iterator (void *cls,
+ struct GNUNET_CONTAINER_HeapNode *
+ node, void *element,
+ GNUNET_CONTAINER_HeapCostType
+ cost)
{
struct DefragContext * d_ctx = element;
* returns the udp transport API.
*
* @param cls our 'struct GNUNET_TRANSPORT_PluginEnvironment'
- * @return our 'struct GNUNET_TRANSPORT_PluginFunctions'
+ * @return NULL
*/
void *
libgnunet_plugin_transport_udp_done (void *cls)
{
struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
struct Plugin *plugin = api->cls;
+
+ if (NULL == plugin)
+ {
+ GNUNET_free (api);
+ return NULL;
+ }
+
stop_broadcast (plugin);
if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (plugin->select_task);
plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
}
+ if (plugin->select_task_v6 != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (plugin->select_task_v6);
+ plugin->select_task_v6 = GNUNET_SCHEDULER_NO_TASK;
+ }
/* Closing sockets */
if (plugin->sockv4 != NULL)
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4));
plugin->sockv4 = NULL;
}
+ GNUNET_NETWORK_fdset_destroy (plugin->rs_v4);
+ GNUNET_NETWORK_fdset_destroy (plugin->ws_v4);
+
if (plugin->sockv6 != NULL)
{
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6));
plugin->sockv6 = NULL;
+
+ GNUNET_NETWORK_fdset_destroy (plugin->rs_v6);
+ GNUNET_NETWORK_fdset_destroy (plugin->ws_v6);
}
- GNUNET_NETWORK_fdset_destroy (plugin->rs);
- GNUNET_NETWORK_fdset_destroy (plugin->ws);
+
GNUNET_NAT_unregister (plugin->nat);
if (plugin->defrag_ctxs != NULL)
}
/* Clean up leftover messages */
- struct UDPMessageWrapper *udpw = plugin->msg_head;
+ struct UDPMessageWrapper * udpw;
+ udpw = plugin->ipv4_queue_head;
+ while (udpw != NULL)
+ {
+ struct UDPMessageWrapper *tmp = udpw->next;
+ GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, plugin->ipv4_queue_tail, udpw);
+ if (udpw->cont != NULL)
+ udpw->cont (udpw->cont_cls, &udpw->session->target, GNUNET_SYSERR);
+ GNUNET_free (udpw);
+ udpw = tmp;
+ }
+ udpw = plugin->ipv6_queue_head;
while (udpw != NULL)
{
struct UDPMessageWrapper *tmp = udpw->next;
- GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, udpw);
+ GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, plugin->ipv6_queue_tail, udpw);
if (udpw->cont != NULL)
udpw->cont (udpw->cont_cls, &udpw->session->target, GNUNET_SYSERR);
GNUNET_free (udpw);