gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r13881 - gnunet/src/transport
Date: Mon, 6 Dec 2010 17:53:51 +0100

Author: wachs
Date: 2010-12-06 17:53:51 +0100 (Mon, 06 Dec 2010)
New Revision: 13881

Modified:
   gnunet/src/transport/gnunet-service-transport.c
   gnunet/src/transport/transport_api.c
Log:
transport api now passes ATS data to clients


Modified: gnunet/src/transport/gnunet-service-transport.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport.c     2010-12-06 15:43:18 UTC 
(rev 13880)
+++ gnunet/src/transport/gnunet-service-transport.c     2010-12-06 16:53:51 UTC 
(rev 13881)
@@ -562,6 +562,16 @@
    */
   int public_key_valid;
 
+  /**
+   * Performance data for the peer.
+   */
+  struct GNUNET_TRANSPORT_ATS_Information *ats;
+
+  /**
+   * Identity of the neighbour.
+   */
+  struct GNUNET_PeerIdentity peer;
+
 };
 
 /**
@@ -2211,7 +2221,7 @@
   struct ConnectInfoMessage * cim;
   struct TransportClient *cpos;
   uint32_t ats_count;
-  uint16_t size;
+  size_t size;
 
 #if DEBUG_TRANSPORT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2225,6 +2235,10 @@
 
   ats_count = 2;
   size  = sizeof (struct ConnectInfoMessage) + ats_count * sizeof (struct 
GNUNET_TRANSPORT_ATS_Information);
+  if (size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
+  {
+         GNUNET_break(0);
+  }
   cim = GNUNET_malloc (size);
 
   cim->header.size = htons (size);
@@ -3456,7 +3470,9 @@
                            GNUNET_NO);
   /* transmit message to all clients */
   uint32_t ats_count = 2;
-  uint16_t size = sizeof (struct InboundMessage) + ats_count * sizeof (struct 
GNUNET_TRANSPORT_ATS_Information) + msize;
+  size_t size = sizeof (struct InboundMessage) + ats_count * sizeof (struct 
GNUNET_TRANSPORT_ATS_Information) + msize;
+  if (size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
+         GNUNET_break(0);
 
   im = GNUNET_malloc (size);
   im->header.size = htons (size);
@@ -4817,8 +4833,10 @@
 {
   const struct StartMessage *start;
   struct TransportClient *c;
-  struct ConnectInfoMessage cim;
+  struct ConnectInfoMessage * cim;
   struct NeighbourList *n;
+  uint32_t ats_count;
+  size_t size;
 
   start = (const struct StartMessage*) message;
 #if DEBUG_TRANSPORT
@@ -4853,7 +4871,7 @@
   clients = c;
   c->client = client;
   if (our_hello != NULL)
-    {
+  {
 #if DEBUG_TRANSPORT
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Sending our own `%s' to new client\n", "HELLO");
@@ -4862,23 +4880,36 @@
                           (const struct GNUNET_MessageHeader *) our_hello,
                           GNUNET_NO);
       /* tell new client about all existing connections */
-      cim.header.size = htons (sizeof (struct ConnectInfoMessage));
-      cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
-      cim.ats_count = htonl(0);
-      cim.ats.type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
-      cim.ats.value = htonl (0);
+      ats_count = 2;
+      size  = sizeof (struct ConnectInfoMessage) + ats_count * sizeof (struct 
GNUNET_TRANSPORT_ATS_Information);
+      if (size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
+      {
+         GNUNET_break(0);
+      }
+      cim = GNUNET_malloc (size);
+
+      cim->header.size = htons (size);
+      cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
+      cim->ats_count = htonl(ats_count);
+      (&(cim->ats))[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
+      (&(cim->ats))[2].value = htonl (0);
       n = neighbours;
       while (n != NULL)
-       {
-         if (GNUNET_YES == n->received_pong)
-           {
-             cim.id = n->id;
-             transmit_to_client (c, &cim.header, GNUNET_NO);
-            }
+         {
+                 if (GNUNET_YES == n->received_pong)
+                 {
+                         (&(cim->ats))[0].type = htonl 
(GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+                         (&(cim->ats))[0].value = htonl (n->distance);
+                         (&(cim->ats))[1].type = htonl 
(GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
+                         (&(cim->ats))[1].value = htonl ((uint32_t) 
n->latency.rel_value);
+                         cim->id = n->id;
+                         transmit_to_client (c, &cim->header, GNUNET_NO);
+                 }
            n = n->next;
-        }
-    }
+      }
+  }
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
+  GNUNET_free(cim);
 }
 
 

Modified: gnunet/src/transport/transport_api.c
===================================================================
--- gnunet/src/transport/transport_api.c        2010-12-06 15:43:18 UTC (rev 
13880)
+++ gnunet/src/transport/transport_api.c        2010-12-06 16:53:51 UTC (rev 
13881)
@@ -1709,6 +1709,7 @@
           GNUNET_break (0);
           break;
         }
+
 #if DEBUG_TRANSPORT
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Receiving `%s' message for `%4s'.\n",
@@ -1724,7 +1725,7 @@
       /* FIXME */
       if (h->nc_cb != NULL)
          h->nc_cb (h->cls, &n->id,
-                 NULL,0);
+                 &cim->ats,ats_count);
       /* FIXEND */
       break;
     case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT:
@@ -1796,6 +1797,7 @@
       ats_count = ntohl(im->ats_count);
       //imm = (const struct GNUNET_MessageHeader *) &im[1];
       imm = (const struct GNUNET_MessageHeader *) &((&(im->ats))[ats_count+1]);
+
       if (ntohs (imm->size) + sizeof (struct InboundMessage) + ats_count * 
sizeof (struct GNUNET_TRANSPORT_ATS_Information) != size)
         {
           GNUNET_break (0);
@@ -1819,8 +1821,8 @@
        }
       /* FIXME: */
       if (h->rec != NULL)
-       h->rec (h->cls, &im->peer, imm,
-               NULL, 0);
+               h->rec (h->cls, &im->peer, imm,
+                       &im->ats, ats_count);
       /* ENDFIX */
       break;
     default:




reply via email to

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