making udp maybe, possibly, do something
authorNathan S. Evans <evans@in.tum.de>
Tue, 19 Jan 2010 15:21:42 +0000 (15:21 +0000)
committerNathan S. Evans <evans@in.tum.de>
Tue, 19 Jan 2010 15:21:42 +0000 (15:21 +0000)
src/transport/gnunet-service-transport.c
src/transport/plugin_transport_http.c
src/transport/plugin_transport_tcp.c
src/transport/plugin_transport_udp.c
src/transport/test_plugin_transport_udp.c
src/transport/transport_api_address_lookup.c

index acdac052c9921e6102c63a363da98ba925ffc530..306efeac10aeb93001a31c60354d3594d1d92cb4 100644 (file)
@@ -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);
 }
index e5f1361ac57d1bfcbda493786ba990eed9768c70..6d4413bbaa74e231adddce2f28d79a19b5b20a76 100644 (file)
@@ -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;
index d877a7f5bda0f7802b5b3615e5d55ef04657414e..9221f7e497ceaeb7f573af2309297a651c95b213 100644 (file)
@@ -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))
index 5dca2a748880a90d83e29f236023dce4adf6f90f..d3c2bac85cb5af9224944acf400b73c5993b7c3e 100644 (file)
 
 #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.
  */
@@ -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;
index 1bfe0f2695834bcefdc5c18cbc5ef0f9d0ee0394..c8122e2e20110886656f9e67f5bde9313b5e3d0e 100644 (file)
@@ -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);
index 961ee0713e74c6348dac00169f908ad8b0268702..d2bc51d471a94384e120b14de2bf755d221f8136 100644 (file)
@@ -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);