gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r10065 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r10065 - gnunet/src/transport
Date: Tue, 19 Jan 2010 16:21:42 +0100

Author: nevans
Date: 2010-01-19 16:21:42 +0100 (Tue, 19 Jan 2010)
New Revision: 10065

Modified:
   gnunet/src/transport/gnunet-service-transport.c
   gnunet/src/transport/plugin_transport_http.c
   gnunet/src/transport/plugin_transport_tcp.c
   gnunet/src/transport/plugin_transport_udp.c
   gnunet/src/transport/test_plugin_transport_udp.c
   gnunet/src/transport/transport_api_address_lookup.c
Log:
making udp maybe, possibly, do something

Modified: gnunet/src/transport/gnunet-service-transport.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport.c     2010-01-19 14:53:10 UTC 
(rev 10064)
+++ gnunet/src/transport/gnunet-service-transport.c     2010-01-19 15:21:42 UTC 
(rev 10065)
@@ -1688,8 +1688,8 @@
       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);
 }

Modified: gnunet/src/transport/plugin_transport_http.c
===================================================================
--- gnunet/src/transport/plugin_transport_http.c        2010-01-19 14:53:10 UTC 
(rev 10064)
+++ gnunet/src/transport/plugin_transport_http.c        2010-01-19 15:21:42 UTC 
(rev 10065)
@@ -1006,8 +1006,9 @@
           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 @@
             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;

Modified: gnunet/src/transport/plugin_transport_tcp.c
===================================================================
--- gnunet/src/transport/plugin_transport_tcp.c 2010-01-19 14:53:10 UTC (rev 
10064)
+++ gnunet/src/transport/plugin_transport_tcp.c 2010-01-19 15:21:42 UTC (rev 
10065)
@@ -624,14 +624,16 @@
     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 @@
     }
   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))

Modified: gnunet/src/transport/plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp.c 2010-01-19 14:53:10 UTC (rev 
10064)
+++ gnunet/src/transport/plugin_transport_udp.c 2010-01-19 15:21:42 UTC (rev 
10065)
@@ -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 @@
    */
   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 @@
 }
 
 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 @@
   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 @@
       else
         cont (cont_cls, target, GNUNET_OK);
     }
-  GNUNET_free(message);
+  GNUNET_free (message);
   return;
 }
 
@@ -380,7 +382,6 @@
                  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 @@
                    ("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 @@
                        &pong->header,
                        GNUNET_TIME_relative_multiply
                        (GNUNET_TIME_UNIT_SECONDS, 30), NULL, NULL);
-      GNUNET_free(pong);
+      GNUNET_free (pong);
     }
 
   return;
@@ -434,7 +435,7 @@
 #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 @@
   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 @@
   socklen_t fromlen;
   struct sockaddr_storage addr;
   ssize_t ret;
+  struct Session *found;
 
   do
     {
@@ -528,13 +533,13 @@
                        ("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 @@
         {
           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 @@
 {
   struct Plugin *plugin = cls;
   struct Session *new_session;
-  struct UDPPongMessage *msg;
+  struct UDPPingMessage *msg;
 
   if (addrlen <= 0)
     return GNUNET_SYSERR;
@@ -697,11 +712,13 @@
   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_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 @@
   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;

Modified: gnunet/src/transport/test_plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_udp.c    2010-01-19 14:53:10 UTC 
(rev 10064)
+++ gnunet/src/transport/test_plugin_transport_udp.c    2010-01-19 15:21:42 UTC 
(rev 10065)
@@ -147,7 +147,7 @@
                          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 @@
     }
 
   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);

Modified: gnunet/src/transport/transport_api_address_lookup.c
===================================================================
--- gnunet/src/transport/transport_api_address_lookup.c 2010-01-19 14:53:10 UTC 
(rev 10064)
+++ gnunet/src/transport/transport_api_address_lookup.c 2010-01-19 15:21:42 UTC 
(rev 10065)
@@ -57,8 +57,8 @@
           /* 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);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]