summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-01-19 15:21:42 +0000
committerNathan S. Evans <evans@in.tum.de>2010-01-19 15:21:42 +0000
commit4afc7dedbafd7a9fa3ae96ddc68a3e9946c8fdb4 (patch)
tree6a5f042245a609d9df1c26c68c26e08cdc956103
parent08db56809eff3599cd47792d3dd8c5f0c27a11a8 (diff)
making udp maybe, possibly, do something
-rw-r--r--src/transport/gnunet-service-transport.c4
-rw-r--r--src/transport/plugin_transport_http.c10
-rw-r--r--src/transport/plugin_transport_tcp.c20
-rw-r--r--src/transport/plugin_transport_udp.c81
-rw-r--r--src/transport/test_plugin_transport_udp.c14
-rw-r--r--src/transport/transport_api_address_lookup.c4
6 files changed, 79 insertions, 54 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index acdac052c..306efeac1 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -1688,8 +1688,8 @@ check_hello_validated (void *cls,
va = va->next;
}
GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_TIME_absolute_get_remaining (chvc->e->
- timeout),
+ GNUNET_TIME_absolute_get_remaining (chvc->
+ e->timeout),
&cleanup_validation, NULL);
GNUNET_free (chvc);
}
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index e5f1361ac..6d4413bba 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -1006,8 +1006,9 @@ receiveContentCallback (void *ptr, size_t size, size_t nmemb, void *ctx)
cpy = sizeof (GNUNET_MessageHeader) - httpSession->cs.client.rpos1;
if (cpy > have)
cpy = have;
- memcpy (&httpSession->cs.client.
- rbuff1[httpSession->cs.client.rpos1], &inbuf[poff], cpy);
+ memcpy (&httpSession->cs.
+ client.rbuff1[httpSession->cs.client.rpos1], &inbuf[poff],
+ cpy);
httpSession->cs.client.rpos1 += cpy;
have -= cpy;
poff += cpy;
@@ -1027,8 +1028,9 @@ receiveContentCallback (void *ptr, size_t size, size_t nmemb, void *ctx)
httpSession->cs.client.rpos2;
if (cpy > have)
cpy = have;
- memcpy (&httpSession->cs.client.
- rbuff2[httpSession->cs.client.rpos2], &inbuf[poff], cpy);
+ memcpy (&httpSession->cs.
+ client.rbuff2[httpSession->cs.client.rpos2], &inbuf[poff],
+ cpy);
have -= cpy;
poff += cpy;
httpSession->cs.client.rpos2 += cpy;
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index d877a7f5b..9221f7e49 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -624,14 +624,16 @@ process_pending_messages (struct Session *session)
return;
session->transmit_handle
= GNUNET_SERVER_notify_transmit_ready (session->client,
- ntohs (session->pending_messages->
- msg->size) +
- (session->pending_messages->
- is_welcome ? 0 : sizeof (struct
- DataMessage)),
+ ntohs (session->
+ pending_messages->msg->
+ size) +
+ (session->
+ pending_messages->is_welcome ? 0 :
+ sizeof (struct DataMessage)),
GNUNET_TIME_absolute_get_remaining
- (session->pending_messages[0].
- timeout), &do_transmit, session);
+ (session->
+ pending_messages[0].timeout),
+ &do_transmit, session);
}
@@ -803,8 +805,8 @@ disconnect_session (struct Session *session)
}
if (session->transmit_handle != NULL)
{
- GNUNET_CONNECTION_notify_transmit_ready_cancel (session->
- transmit_handle);
+ GNUNET_CONNECTION_notify_transmit_ready_cancel
+ (session->transmit_handle);
session->transmit_handle = NULL;
}
while (NULL != (pm = session->pending_messages))
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 5dca2a748..d3c2bac85 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -43,12 +43,6 @@
#define DEBUG_UDP GNUNET_NO
/**
- * The default maximum size of each outbound UDP message,
- * optimal value for Ethernet (10 or 100 MBit).
- */
-#define MESSAGE_SIZE 1472
-
-/**
* Handle for request of hostname resolution, non-NULL if pending.
*/
static struct GNUNET_RESOLVER_RequestHandle *hostname_dns;
@@ -115,6 +109,15 @@ struct Session
*/
unsigned int validated;
+ /*
+ * What is the latency of this connection? (Time between ping and pong)
+ */
+ struct GNUNET_TIME_Relative latency;
+
+ /*
+ * At what GNUNET_TIME did we send a ping?
+ */
+ struct GNUNET_TIME_Absolute ping_sent;
};
/**
@@ -280,12 +283,11 @@ udp_transport_server_stop (void *cls)
}
static struct Session *
-find_session (void *cls, struct Session *session_list,
- const struct GNUNET_PeerIdentity *peer)
+find_session (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct Plugin *plugin = cls;
struct Session *pos;
- pos = session_list;
+ pos = plugin->sessions;
while (pos != NULL)
{
@@ -329,7 +331,7 @@ udp_plugin_send (void *cls,
int ssize;
size_t sent;
- session = find_session (plugin, plugin->sessions, target);
+ session = find_session (plugin, target);
if ((session == NULL) || (udp_sock == NULL))
return;
@@ -361,7 +363,7 @@ udp_plugin_send (void *cls,
else
cont (cont_cls, target, GNUNET_OK);
}
- GNUNET_free(message);
+ GNUNET_free (message);
return;
}
@@ -380,7 +382,6 @@ handle_udp_ping (void *cls,
const struct GNUNET_MessageHeader *message)
{
struct Plugin *plugin = cls;
- struct Session *head = plugin->sessions;
const struct UDPPingMessage *ping = (const struct UDPPingMessage *) message;
struct UDPPongMessage *pong;
struct Session *found;
@@ -390,7 +391,7 @@ handle_udp_ping (void *cls,
("handling ping, challenge is %d\n"),
ntohs (ping->challenge));
#endif
- found = find_session (plugin, head, sender);
+ found = find_session (plugin, sender);
if (found != NULL)
{
pong = GNUNET_malloc (sizeof (struct UDPPongMessage) + addrlen);
@@ -404,7 +405,7 @@ handle_udp_ping (void *cls,
&pong->header,
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 30), NULL, NULL);
- GNUNET_free(pong);
+ GNUNET_free (pong);
}
return;
@@ -434,7 +435,7 @@ handle_udp_pong (void *cls,
#if DEBUG_UDP
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _("handling pong\n"));
#endif
- found = find_session (plugin, plugin->sessions, sender);
+ found = find_session (plugin, sender);
#if DEBUG_UDP
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
("found->challenge %d, pong->challenge %d\n"),
@@ -443,6 +444,9 @@ handle_udp_pong (void *cls,
if ((found != NULL) && (found->challenge == ntohs (pong->challenge)))
{
found->validated = GNUNET_YES;
+ found->latency =
+ GNUNET_TIME_absolute_get_difference (found->ping_sent,
+ GNUNET_TIME_absolute_get ());
addr_len = ntohs (pong->addrlen);
#if DEBUG_UDP
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
@@ -479,6 +483,7 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
socklen_t fromlen;
struct sockaddr_storage addr;
ssize_t ret;
+ struct Session *found;
do
{
@@ -528,13 +533,13 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
("header reports message type of %d\n"),
ntohs (msg->header.type));
#endif
- /*if (ntohs(hdr->size) < sizeof(struct UDPMessage))
- {
- GNUNET_free(buf);
- GNUNET_NETWORK_fdset_zero(plugin->rs);
- GNUNET_NETWORK_fdset_set(plugin->rs, udp_sock);
- break;
- } */
+ if (ntohs (msg->header.size) < sizeof (struct UDPMessage))
+ {
+ GNUNET_free (buf);
+ GNUNET_NETWORK_fdset_zero (plugin->rs);
+ GNUNET_NETWORK_fdset_set (plugin->rs, udp_sock);
+ break;
+ }
hdr = (const struct GNUNET_MessageHeader *) &msg[1];
sender = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
memcpy (sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity));
@@ -553,12 +558,22 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
handle_udp_ping (plugin, sender, &addr, fromlen, hdr);
}
-
- if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_PONG)
+ else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_PONG)
{
handle_udp_pong (plugin, sender, hdr);
}
- GNUNET_free(sender);
+ else
+ {
+ found = find_session (plugin, sender);
+ if (found != NULL)
+ plugin->env->receive (plugin->env->cls, found->latency, sender,
+ &msg->header);
+ else
+ plugin->env->receive (plugin->env->cls,
+ GNUNET_TIME_relative_get_forever (), sender,
+ &msg->header);
+ }
+ GNUNET_free (sender);
GNUNET_free (buf);
}
@@ -676,7 +691,7 @@ udp_plugin_validate (void *cls,
{
struct Plugin *plugin = cls;
struct Session *new_session;
- struct UDPPongMessage *msg;
+ struct UDPPingMessage *msg;
if (addrlen <= 0)
return GNUNET_SYSERR;
@@ -697,11 +712,13 @@ udp_plugin_validate (void *cls,
memcpy (&new_session->target, target, sizeof (struct GNUNET_PeerIdentity));
new_session->challenge = challenge;
new_session->validated = GNUNET_NO;
+ new_session->latency = GNUNET_TIME_relative_get_zero ();
+ new_session->ping_sent = GNUNET_TIME_absolute_get ();
new_session->next = plugin->sessions;
plugin->sessions = new_session;
- msg = GNUNET_malloc (sizeof (struct UDPPongMessage));
- msg->header.size = htons (sizeof (struct UDPPongMessage));
+ msg = GNUNET_malloc (sizeof (struct UDPPingMessage));
+ msg->header.size = htons (sizeof (struct UDPPingMessage));
msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_PING);
msg->challenge = htons (challenge);
#if DEBUG_UDP
@@ -713,7 +730,7 @@ udp_plugin_validate (void *cls,
udp_plugin_send (plugin, target, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
&msg->header, timeout, NULL, NULL);
- GNUNET_free(msg);
+ GNUNET_free (msg);
return GNUNET_OK;
}
@@ -880,13 +897,13 @@ libgnunet_plugin_transport_udp_done (void *cls)
pos = plugin->sessions;
while (pos != NULL)
{
- GNUNET_free(pos->connect_addr);
+ GNUNET_free (pos->connect_addr);
oldpos = pos;
pos = pos->next;
- GNUNET_free(oldpos);
+ GNUNET_free (oldpos);
}
- GNUNET_NETWORK_fdset_destroy(plugin->rs);
+ GNUNET_NETWORK_fdset_destroy (plugin->rs);
GNUNET_free (plugin);
GNUNET_free (api);
return NULL;
diff --git a/src/transport/test_plugin_transport_udp.c b/src/transport/test_plugin_transport_udp.c
index 1bfe0f269..c8122e2e2 100644
--- a/src/transport/test_plugin_transport_udp.c
+++ b/src/transport/test_plugin_transport_udp.c
@@ -147,7 +147,7 @@ validation_notification (void *cls,
const struct GNUNET_PeerIdentity *peer,
uint32_t challenge, const char *sender_addr)
{
- struct sockaddr_storage *addr = (struct sockaddr_storage *)sender_addr;
+ struct sockaddr_storage *addr = (struct sockaddr_storage *) sender_addr;
if (validation_timeout_task != GNUNET_SCHEDULER_NO_TASK)
{
@@ -156,14 +156,18 @@ validation_notification (void *cls,
}
switch (addr->ss_family)
- {
+ {
case AF_INET:
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
- ("got address %s\n"),GNUNET_a2s((struct sockaddr *)addr, INET_ADDRSTRLEN));
+ ("got address %s\n"),
+ GNUNET_a2s ((struct sockaddr *) addr,
+ INET_ADDRSTRLEN));
case AF_INET6:
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
- ("got address %s\n"),GNUNET_a2s((struct sockaddr *)addr, INET6_ADDRSTRLEN));
- }
+ ("got address %s\n"),
+ GNUNET_a2s ((struct sockaddr *) addr,
+ INET6_ADDRSTRLEN));
+ }
GNUNET_assert (challenge == 42);
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c
index 961ee0713..d2bc51d47 100644
--- a/src/transport/transport_api_address_lookup.c
+++ b/src/transport/transport_api_address_lookup.c
@@ -57,8 +57,8 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
/* expect more replies */
GNUNET_CLIENT_receive (alucb->client, &address_response_processor,
alucb,
- GNUNET_TIME_absolute_get_remaining (alucb->
- timeout));
+ GNUNET_TIME_absolute_get_remaining
+ (alucb->timeout));
}
}
alucb->cb (alucb->cls, address);