gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r34959 - gnunet/src/ats


From: gnunet
Subject: [GNUnet-SVN] r34959 - gnunet/src/ats
Date: Thu, 22 Jan 2015 21:59:08 +0100

Author: grothoff
Date: 2015-01-22 21:59:08 +0100 (Thu, 22 Jan 2015)
New Revision: 34959

Modified:
   gnunet/src/ats/ats_api_scheduling.c
Log:
splitting add/update logic in preparation for changing msg formats

Modified: gnunet/src/ats/ats_api_scheduling.c
===================================================================
--- gnunet/src/ats/ats_api_scheduling.c 2015-01-22 20:54:15 UTC (rev 34958)
+++ gnunet/src/ats/ats_api_scheduling.c 2015-01-22 20:59:08 UTC (rev 34959)
@@ -561,14 +561,10 @@
  *
  * @param sh the scheduling handle to use for transmission
  * @param ar the address to inform the ATS service about
- * @param msg_type the message type to use when sending the message
- *
- * FIXME: maybe overloading with msg_type was not the best idea here...
  */
 static void
 send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh,
-                          const struct GNUNET_ATS_AddressRecord *ar,
-                          uint16_t msg_type)
+                          const struct GNUNET_ATS_AddressRecord *ar)
 {
   struct GNUNET_MQ_Envelope *ev;
   struct AddressUpdateMessage *m;
@@ -585,7 +581,7 @@
   msize = ar->address->address_length +
     ar->ats_count * sizeof (struct GNUNET_ATS_Information) + namelen;
 
-  ev = GNUNET_MQ_msg_extra (m, msize, msg_type);
+  ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD);
   m->ats_count = htonl (ar->ats_count);
   m->peer = ar->address->peer;
   m->address_length = htons (ar->address->address_length);
@@ -1249,9 +1245,11 @@
   GNUNET_array_grow (ar->ats,
                      ar->ats_count,
                      ats_count);
-  memcpy (ar->ats, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
+  memcpy (ar->ats,
+          ats,
+          ats_count * sizeof (struct GNUNET_ATS_Information));
   sh->session_array[s] = ar;
-  send_add_address_message (sh, ar, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD);
+  send_add_address_message (sh, ar);
   return ar;
 }
 
@@ -1289,6 +1287,7 @@
 {
   GNUNET_break (session == ar->session);
   ar->session = NULL;
+  GNUNET_break (GNUNET_NO == ar->in_use);
   if (GNUNET_HELLO_address_check_option (ar->address,
                                          GNUNET_HELLO_ADDRESS_INFO_INBOUND))
   {
@@ -1316,15 +1315,57 @@
                            const struct GNUNET_ATS_Information *ats,
                            uint32_t ats_count)
 {
+  struct GNUNET_ATS_SchedulingHandle *sh = ar->sh;
+  struct GNUNET_MQ_Envelope *ev;
+  struct AddressUpdateMessage *m;
+  struct GNUNET_ATS_Information *am;
+  char *pm;
+  size_t namelen;
+  size_t msize;
+
   GNUNET_array_grow (ar->ats,
                      ar->ats_count,
                      ats_count);
   memcpy (ar->ats,
           ats,
           ats_count * sizeof (struct GNUNET_ATS_Information));
-  send_add_address_message (ar->sh,
-                            ar,
-                            GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
+
+
+  if (NULL == sh->mq)
+    return; /* disconnected, skip for now */
+  namelen = (NULL == ar->address->transport_name)
+    ? 0
+    : strlen (ar->address->transport_name) + 1;
+  msize = ar->address->address_length +
+    ar->ats_count * sizeof (struct GNUNET_ATS_Information) + namelen;
+
+  ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
+  m->ats_count = htonl (ar->ats_count);
+  m->peer = ar->address->peer;
+  m->address_length = htons (ar->address->address_length);
+  m->address_local_info = htonl ((uint32_t) ar->address->local_info);
+  m->plugin_name_length = htons (namelen);
+  m->session_id = htonl (ar->slot);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Adding address for peer `%s', plugin `%s', session %p id %u\n",
+              GNUNET_i2s (&ar->address->peer),
+              ar->address->transport_name,
+              ar->session,
+              ar->slot);
+  am = (struct GNUNET_ATS_Information *) &m[1];
+  memcpy (am,
+          ar->ats,
+          ar->ats_count * sizeof (struct GNUNET_ATS_Information));
+  pm = (char *) &am[ar->ats_count];
+  memcpy (pm,
+          ar->address->address,
+          ar->address->address_length);
+  if (NULL != ar->address->transport_name)
+    memcpy (&pm[ar->address->address_length],
+            ar->address->transport_name,
+            namelen);
+  GNUNET_MQ_send (sh->mq, ev);
 }
 
 




reply via email to

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