t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
t4.t4_port = ((struct sockaddr_in *) addr)->sin_port;
arg = &t4;
- args = sizeof(t4);
+ args = sizeof (t4);
break;
case AF_INET6:
GNUNET_assert(addrlen == sizeof(struct sockaddr_in6));
t6.options = htonl (myoptions);
t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
arg = &t6;
- args = sizeof(t6);
+ args = sizeof (t6);
break;
default:
GNUNET_break(0);
return;
}
/* modify our published address list */
+ GNUNET_assert ((args == sizeof (struct IPv4TcpAddress)) ||
+ (args == sizeof (struct IPv6TcpAddress)));
address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
PLUGIN_NAME, arg, args, GNUNET_HELLO_ADDRESS_INFO_NONE);
plugin->env->notify_address (plugin->env->cls, add_remove, address);
memcpy (&a4, &t4->ipv4_addr, sizeof(a4));
sb = &a4;
break;
- case 0:
- {
- GNUNET_snprintf (rbuf, sizeof(rbuf), "%s",
- TRANSPORT_SESSION_INBOUND_STRING);
- return rbuf;
- }
default:
LOG(GNUNET_ERROR_TYPE_WARNING, _("Unexpected address length: %u bytes\n"),
(unsigned int ) addrlen);
GNUNET_SERVER_notify_transmit_ready_cancel (session->transmit_handle);
session->transmit_handle = NULL;
}
+ plugin->env->unregister_quota_notification (plugin->env->cls,
+ &session->target, PLUGIN_NAME, session);
session->plugin->env->session_end (session->plugin->env->cls,
- &session->target, session);
+ session->address, session);
if (GNUNET_SCHEDULER_NO_TASK != session->nat_connection_timeout)
{
* Create a new session. Also queues a welcome message.
*
* @param plugin the plugin
- * @param target peer to connect to
+ * @param address the address to create the session for
* @param client client to use, reference counter must have already been increased
* @param is_nat this a NAT session, we should wait for a client to
* connect to us from an address, then assign that to
GNUNET_STATISTICS_update (plugin->env->stats,
gettext_noop ("# TCP sessions active"), 1, GNUNET_NO);
}
+ plugin->env->register_quota_notification (plugin->env->cls,
+ &address->peer, PLUGIN_NAME, session);
session->timeout_task = GNUNET_SCHEDULER_add_delayed (
GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session);
return session;
reschedule_session_timeout (session);
}
+/**
+ * Task to signal the server that we can continue
+ * receiving from the TCP client now.
+ *
+ * @param cls the `struct Session*`
+ * @param tc task context (unused)
+ */
+static void
+delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct Session *session = cls;
+
+ session->receive_delay_task = GNUNET_SCHEDULER_NO_TASK;
+ reschedule_session_timeout (session);
+
+ GNUNET_SERVER_receive_done (session->client, GNUNET_OK);
+}
+
+static void tcp_plugin_update_inbound_delay (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ struct Session *session,
+ struct GNUNET_TIME_Relative delay)
+{
+ if (GNUNET_SCHEDULER_NO_TASK == session->receive_delay_task)
+ return;
+
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "New inbound delay %llu us\n",delay.rel_value_us);
+
+ GNUNET_SCHEDULER_cancel (session->receive_delay_task);
+ session->receive_delay_task = GNUNET_SCHEDULER_add_delayed (delay,
+ &delayed_done, session);
+}
+
+
/**
* Create a new session to transmit data to the target
* This session will used to send data to this peer and the plugin will
sb = &a4;
sbs = sizeof(a4);
}
- else if (0 == addrlen)
- {
- asc (asc_cls, TRANSPORT_SESSION_INBOUND_STRING);
- asc (asc_cls, NULL );
- return;
- }
else
{
/* invalid address */
- GNUNET_break_op(0);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Trying to print invalid `%s' address with size %u\n", type, addrlen);
asc (asc_cls, NULL );
return;
}
case AF_INET:
s4 = vaddr;
t4 = GNUNET_new (struct IPv4TcpAddress);
- t4->options = 0;
+ t4->options = htonl(0);
t4->t4_port = s4->sin_port;
t4->ipv4_addr = s4->sin_addr.s_addr;
session->address = GNUNET_HELLO_address_allocate (
&tcp_nat_probe->clientIdentity, PLUGIN_NAME, &t4,
- sizeof(struct IPv4TcpAddress), GNUNET_HELLO_ADDRESS_INFO_NONE);
+ sizeof(struct IPv4TcpAddress),
+ GNUNET_HELLO_ADDRESS_INFO_NONE);
break;
case AF_INET6:
s6 = vaddr;
t6 = GNUNET_new (struct IPv6TcpAddress);
- t6->options = 0;
+ t6->options = htonl(0);
t6->t6_port = s6->sin6_port;
memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr));
session->address = GNUNET_HELLO_address_allocate (
- &tcp_nat_probe->clientIdentity, PLUGIN_NAME, &t6,
- sizeof(struct IPv6TcpAddress), GNUNET_HELLO_ADDRESS_INFO_NONE);
+ &tcp_nat_probe->clientIdentity,
+ PLUGIN_NAME, &t6, sizeof(struct IPv6TcpAddress),
+ GNUNET_HELLO_ADDRESS_INFO_NONE);
break;
default:
GNUNET_break_op(0);
const struct sockaddr_in6 *s6;
struct GNUNET_ATS_Information ats;
+
if (0 == memcmp (&wm->clientIdentity, plugin->env->my_identity,
sizeof(struct GNUNET_PeerIdentity)))
{
GNUNET_break_op(0);
return;
}
+
LOG(GNUNET_ERROR_TYPE_DEBUG, "Received %s message from `%4s' %p\n", "WELCOME",
GNUNET_i2s (&wm->clientIdentity), client);
GNUNET_STATISTICS_update (plugin->env->stats,
t4.t4_port = s4->sin_port;
t4.ipv4_addr = s4->sin_addr.s_addr;
address = GNUNET_HELLO_address_allocate (&wm->clientIdentity,
- PLUGIN_NAME, &t4, sizeof(struct IPv4TcpAddress),
+ PLUGIN_NAME, &t4, sizeof(t4),
GNUNET_HELLO_ADDRESS_INFO_INBOUND);
}
else if (alen == sizeof(struct sockaddr_in6))
t6.t6_port = s6->sin6_port;
memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr));
address = GNUNET_HELLO_address_allocate (&wm->clientIdentity,
- PLUGIN_NAME, &t6, sizeof(struct IPv6TcpAddress),
+ PLUGIN_NAME, &t6, sizeof (t6),
GNUNET_HELLO_ADDRESS_INFO_INBOUND);
}
+ else
+ {
+ GNUNET_break (0);
+ GNUNET_free_non_null (vaddr);
+ return;
+ }
session = create_session (plugin, address, client, GNUNET_NO);
GNUNET_HELLO_address_free (address);
ats = plugin->env->get_address_type (plugin->env->cls, vaddr, alen);
session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (
ats.value);
- LOG(GNUNET_ERROR_TYPE_DEBUG, "Creating new%s session %p for peer `%s'\n",
- GNUNET_HELLO_address_check_option (session->address, GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? " inbound" : "",
- session,
- tcp_address_to_string(NULL, (void *) session->address->address,session->address->address_length));
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "Creating new%s session %p for peer `%s' client %p \n",
+ GNUNET_HELLO_address_check_option (session->address,
+ GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? " inbound" : "", session,
+ tcp_address_to_string(NULL, (void *) session->address->address,
+ session->address->address_length),
+ client);
GNUNET_free(vaddr);
GNUNET_SERVER_client_set_user_context(session->client, session);
GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, &session->target,
session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+
+ /* Notify transport and ATS about new session */
+ plugin->env->session_start (NULL, session->address, session, &ats, 1);
}
else
{
LOG(GNUNET_ERROR_TYPE_DEBUG,
"Did not obtain TCP socket address for incoming connection\n");
GNUNET_break(0);
+ return;
}
}
session->last_activity = GNUNET_TIME_absolute_get ();
session->expecting_welcome = GNUNET_NO;
- /* Notify transport and ATS about new session */
- plugin->env->session_start (NULL, session->address, session, &ats, 1);
-
process_pending_messages (session);
GNUNET_SERVER_client_set_timeout (client,
GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
-/**
- * Task to signal the server that we can continue
- * receiving from the TCP client now.
- *
- * @param cls the `struct Session*`
- * @param tc task context (unused)
- */
-static void
-delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct Session *session = cls;
-
- session->receive_delay_task = GNUNET_SCHEDULER_NO_TASK;
- reschedule_session_timeout (session);
-
- GNUNET_SERVER_receive_done (session->client, GNUNET_OK);
-}
/**
* We've received data for this peer via TCP. Unbox,
static enum GNUNET_ATS_Network_Type
tcp_get_network (void *cls, struct Session *session)
{
- GNUNET_assert(NULL != session);
+ struct Plugin * plugin = cls;
+ GNUNET_assert (NULL != plugin);
+ GNUNET_assert (NULL != session);
+ if (GNUNET_SYSERR == find_session (plugin,session))
+ return GNUNET_ATS_NET_UNSPECIFIED;
return session->ats_address_network_type;
}
api->string_to_address = &tcp_string_to_address;
api->get_network = &tcp_get_network;
api->update_session_timeout = &tcp_plugin_update_session_timeout;
+ api->update_inbound_delay = &tcp_plugin_update_inbound_delay;
plugin->service = service;
if (NULL != service)
{