-LRN: fix dv test dependencies
[oweals/gnunet.git] / src / dv / gnunet-service-dv.c
index 876d056ac6ee4b28a2fa11f71c54fc3ef0f566ea..6ee95c051c1c915d292469b14b716d0705d3ef8b 100644 (file)
@@ -582,7 +582,7 @@ static char *my_short_id;
 /**
  * Transmit handle to the plugin.
  */
-static struct GNUNET_CONNECTION_TransmitHandle *plugin_transmit_handle;
+static struct GNUNET_SERVER_TransmitHandle *plugin_transmit_handle;
 
 /**
  * Head of DLL for client messages
@@ -761,8 +761,8 @@ transmit_to_plugin (void *cls, size_t size, void *buf)
   if (plugin_pending_head != NULL)
     plugin_transmit_handle =
         GNUNET_SERVER_notify_transmit_ready (client_handle,
-                                             ntohs (plugin_pending_head->
-                                                    msg->size),
+                                             ntohs (plugin_pending_head->msg->
+                                                    size),
                                              GNUNET_TIME_UNIT_FOREVER_REL,
                                              &transmit_to_plugin, NULL);
 
@@ -858,7 +858,8 @@ send_to_plugin (const struct GNUNET_PeerIdentity *sender,
 }
 
 /* Declare here so retry_core_send is aware of it */
-size_t core_transmit_notify (void *cls, size_t size, void *buf);
+size_t
+core_transmit_notify (void *cls, size_t size, void *buf);
 
 /**
  *  Try to send another message from our core sending list
@@ -999,9 +1000,9 @@ send_message_via (const struct GNUNET_PeerIdentity *sender,
   find_context.via = recipient;
   find_context.tid = 0;
   GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
-                                              &send_context->distant_peer->
-                                              hashPubKey, &find_specific_id,
-                                              &find_context);
+                                              &send_context->
+                                              distant_peer->hashPubKey,
+                                              &find_specific_id, &find_context);
 
   if (find_context.tid == 0)
   {
@@ -1287,7 +1288,7 @@ checkPeerID (void *cls, const GNUNET_HashCode * key, void *value)
  * @param client the TokenizedMessageContext which contains message information
  * @param message the actual message
  */
-void
+int
 tokenized_message_handler (void *cls, void *client,
                            const struct GNUNET_MessageHeader *message)
 {
@@ -1311,6 +1312,7 @@ tokenized_message_handler (void *cls, void *client,
     send_to_plugin (ctx->peer, message, ntohs (message->size),
                     &ctx->distant->identity, ctx->distant->cost);
   }
+  return GNUNET_OK;
 }
 
 #if DELAY_FORWARDS
@@ -1332,7 +1334,7 @@ send_message_delayed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   {
     send_message (&msg_ctx->dest, &msg_ctx->sender, NULL, msg_ctx->message,
                   msg_ctx->message_size, default_dv_priority, msg_ctx->uid,
-                  GNUNET_TIME_relative_get_forever ());
+                  GNUNET_TIME_UNIT_FOREVER_REL);
     GNUNET_free (msg_ctx->message);
     GNUNET_free (msg_ctx);
   }
@@ -1343,44 +1345,42 @@ send_message_delayed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * Get distance information from 'atsi'.
  *
  * @param atsi performance data
+ * @param atsi_count number of entries in atsi
  * @return connected transport distance
  */
 static uint32_t
-get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+get_atsi_distance (const struct GNUNET_ATS_Information *atsi,
+                   unsigned int atsi_count)
 {
-  while ((ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
-         (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE))
-    atsi++;
-  if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
-  {
-    GNUNET_break (0);
-    /* FIXME: we do not have distance data? Assume direct neighbor. */
-    return DIRECT_NEIGHBOR_COST;
-  }
-  return ntohl (atsi->value);
+  unsigned int i;
+
+  for (i = 0; i < atsi_count; i++)
+    if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DISTANCE)
+      return ntohl (atsi->value);
+  /* FIXME: we do not have distance data? Assume direct neighbor. */
+  return DIRECT_NEIGHBOR_COST;
 }
 
 /**
  * Find latency information in 'atsi'.
  *
  * @param atsi performance data
+ * @param atsi_count number of entries in atsi
  * @return connection latency
  */
 static struct GNUNET_TIME_Relative
-get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+get_atsi_latency (const struct GNUNET_ATS_Information *atsi,
+                  unsigned int atsi_count)
 {
-  while ((ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
-         (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY))
-    atsi++;
-  if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
-  {
-    GNUNET_break (0);
-    /* how can we not have latency data? */
-    return GNUNET_TIME_UNIT_SECONDS;
-  }
-  /* FIXME: Multiply by GNUNET_TIME_UNIT_MILLISECONDS (1) to get as a GNUNET_TIME_Relative */
-  return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
-                                        ntohl (atsi->value));
+  unsigned int i;
+
+  for (i = 0; i < atsi_count; i++)
+    if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DELAY)
+      return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+                                            ntohl (atsi->value));
+  GNUNET_break (0);
+  /* how can we not have latency data? */
+  return GNUNET_TIME_UNIT_SECONDS;
 }
 
 /**
@@ -1393,11 +1393,13 @@ get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
  * @param peer peer which sent the message (immediate sender)
  * @param message the message
  * @param atsi transport ATS information (latency, distance, etc.)
+ * @param atsi_count number of entries in atsi
  */
 static int
 handle_dv_data_message (void *cls, const struct GNUNET_PeerIdentity *peer,
                         const struct GNUNET_MessageHeader *message,
-                        const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+                        const struct GNUNET_ATS_Information *atsi,
+                        unsigned int atsi_count)
 {
   const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message;
   const struct GNUNET_MessageHeader *packed_message;
@@ -1450,8 +1452,8 @@ handle_dv_data_message (void *cls, const struct GNUNET_PeerIdentity *peer,
   }
 
   /* Iterate over ATS_Information to get distance and latency */
-  latency = get_atsi_latency (atsi);
-  distance = get_atsi_distance (atsi);
+  latency = get_atsi_latency (atsi, atsi_count);
+  distance = get_atsi_distance (atsi, atsi_count);
   dn = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey);
   if (dn == NULL)
     return GNUNET_OK;
@@ -1488,7 +1490,7 @@ handle_dv_data_message (void *cls, const struct GNUNET_PeerIdentity *peer,
     pos = dn->referee_head;
     while ((NULL != pos) && (pos->referrer_id != sid))
     {
-      sender_id = strdup (GNUNET_i2s (&pos->identity));
+      sender_id = GNUNET_strdup (GNUNET_i2s (&pos->identity));
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I know sender %u %s\n",
                   pos->referrer_id, sender_id);
       GNUNET_free (sender_id);
@@ -1627,7 +1629,7 @@ handle_dv_data_message (void *cls, const struct GNUNET_PeerIdentity *peer,
         send_message (destination, original_sender, NULL, packed_message,
                       packed_message_size, default_dv_priority,
                       ntohl (incoming->uid),
-                      GNUNET_TIME_relative_get_forever ());
+                      GNUNET_TIME_UNIT_FOREVER_REL);
   }
   if (ret != GNUNET_SYSERR)
     return GNUNET_OK;
@@ -1762,7 +1764,7 @@ neighbor_send_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                        sizeof (p2p_dv_MESSAGE_NeighborInfo));
     pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
     pending_message->importance = default_dv_priority;
-    pending_message->timeout = GNUNET_TIME_relative_get_forever ();
+    pending_message->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
     memcpy (&pending_message->recipient, &to->identity,
             sizeof (struct GNUNET_PeerIdentity));
     pending_message->msg_size = sizeof (p2p_dv_MESSAGE_NeighborInfo);
@@ -1782,7 +1784,7 @@ neighbor_send_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
     GNUNET_SCHEDULER_add_now (try_core_send, NULL);
     /*if (core_transmit_handle == NULL)
-     * core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES,  default_dv_priority, GNUNET_TIME_relative_get_forever(), &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, NULL); */
+     * core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES,  default_dv_priority, GNUNET_TIME_UNIT_FOREVER_REL, &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, NULL); */
 
   }
 
@@ -2071,19 +2073,17 @@ handle_dv_send_message (void *cls, struct GNUNET_SERVER_Client *client,
 }
 
 /** Forward declarations **/
-static int handle_dv_gossip_message (void *cls,
-                                     const struct GNUNET_PeerIdentity *peer,
-                                     const struct GNUNET_MessageHeader *message,
-                                     const struct
-                                     GNUNET_TRANSPORT_ATS_Information *atsi);
-
-static int handle_dv_disconnect_message (void *cls,
-                                         const struct GNUNET_PeerIdentity *peer,
-                                         const struct GNUNET_MessageHeader
-                                         *message,
-                                         const struct
-                                         GNUNET_TRANSPORT_ATS_Information
-                                         *atsi);
+static int
+handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer,
+                          const struct GNUNET_MessageHeader *message,
+                          const struct GNUNET_ATS_Information *atsi,
+                          unsigned int atsi_count);
+
+static int
+handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer,
+                              const struct GNUNET_MessageHeader *message,
+                              const struct GNUNET_ATS_Information *atsi,
+                              unsigned int atsi_count);
 /** End forward declarations **/
 
 
@@ -2193,7 +2193,7 @@ schedule_disconnect_messages (void *cls, const GNUNET_HashCode * key,
                      sizeof (p2p_dv_MESSAGE_Disconnect));
   pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
   pending_message->importance = default_dv_priority;
-  pending_message->timeout = GNUNET_TIME_relative_get_forever ();
+  pending_message->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
   memcpy (&pending_message->recipient, &notify->identity,
           sizeof (struct GNUNET_PeerIdentity));
   pending_message->msg_size = sizeof (p2p_dv_MESSAGE_Disconnect);
@@ -2207,7 +2207,7 @@ schedule_disconnect_messages (void *cls, const GNUNET_HashCode * key,
 
   GNUNET_SCHEDULER_add_now (try_core_send, NULL);
   /*if (core_transmit_handle == NULL)
-   * core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(), &notify->identity, sizeof(p2p_dv_MESSAGE_Disconnect), &core_transmit_notify, NULL); */
+   * core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, default_dv_priority, GNUNET_TIME_UNIT_FOREVER_REL, &notify->identity, sizeof(p2p_dv_MESSAGE_Disconnect), &core_transmit_notify, NULL); */
 
   return GNUNET_YES;
 }
@@ -2288,8 +2288,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  */
 void
 core_init (void *cls, struct GNUNET_CORE_Handle *server,
-           const struct GNUNET_PeerIdentity *identity,
-           const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
+           const struct GNUNET_PeerIdentity *identity)
 {
 
   if (server == NULL)
@@ -2454,6 +2453,7 @@ static size_t
 generate_hello_address (void *cls, size_t max, void *buf)
 {
   struct HelloContext *hello_context = cls;
+  struct GNUNET_HELLO_Address hello_address;
   char *addr_buffer;
   size_t offset;
   size_t size;
@@ -2475,11 +2475,14 @@ generate_hello_address (void *cls, size_t max, void *buf)
   /* Copy the direct peer identity to buffer */
   memcpy (&addr_buffer[offset], hello_context->direct_peer,
           sizeof (struct GNUNET_PeerIdentity));
+  memset (&hello_address.peer, 0, sizeof (struct GNUNET_PeerIdentity));
+  hello_address.address = addr_buffer;
+  hello_address.transport_name = "dv";
+  hello_address.address_length = size;
   ret =
-      GNUNET_HELLO_add_address ("dv",
+      GNUNET_HELLO_add_address (&hello_address,
                                 GNUNET_TIME_relative_to_absolute
-                                (GNUNET_TIME_UNIT_HOURS), addr_buffer, size,
-                                buf, max);
+                                (GNUNET_TIME_UNIT_HOURS), buf, max);
 
   hello_context->addresses_to_add--;
 
@@ -2652,20 +2655,17 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer,
                       "%s: learned about peer %llu from which we have a previous unknown message, processing!\n",
                       my_short_id, referrer_peer_id);
 #endif
-          struct GNUNET_TRANSPORT_ATS_Information atsi[3];
+          struct GNUNET_ATS_Information atsi[2];
 
-          atsi[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+          atsi[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
           atsi[0].value = htonl (referrer->pending_messages[i].distance);
-          atsi[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
+          atsi[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
           atsi[1].value =
-              htonl ((uint32_t) referrer->pending_messages[i].latency.
-                     rel_value);
-          atsi[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
-          atsi[2].value = htonl (0);
+              htonl ((uint32_t) referrer->pending_messages[i].
+                     latency.rel_value);
           handle_dv_data_message (NULL, &referrer->pending_messages[i].sender,
-                                  referrer->pending_messages[i].message,
-                                  (const struct GNUNET_TRANSPORT_ATS_Information
-                                   *) &atsi);
+                                  referrer->pending_messages[i].message, atsi,
+                                  2);
           GNUNET_free (referrer->pending_messages[i].message);
           referrer->pending_messages[i].sender_id = 0;
         }
@@ -2731,12 +2731,13 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer,
  * @param peer peer which sent the message (immediate sender)
  * @param message the message
  * @param atsi performance data
+ * @param atsi_count number of entries in atsi
  */
 static int
 handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer,
                               const struct GNUNET_MessageHeader *message,
-                              const struct GNUNET_TRANSPORT_ATS_Information
-                              *atsi)
+                              const struct GNUNET_ATS_Information *atsi,
+                              unsigned int atsi_count)
 {
   struct DirectNeighbor *referrer;
   struct DistantNeighbor *distant;
@@ -2780,11 +2781,13 @@ handle_dv_disconnect_message (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @param peer peer which sent the message (immediate sender)
  * @param message the message
  * @param atsi performance data
+ * @param atsi_count number of entries in atsi
  */
 static int
 handle_dv_gossip_message (void *cls, const struct GNUNET_PeerIdentity *peer,
                           const struct GNUNET_MessageHeader *message,
-                          const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+                          const struct GNUNET_ATS_Information *atsi,
+                          unsigned int atsi_count)
 {
   struct DirectNeighbor *referrer;
   p2p_dv_MESSAGE_NeighborInfo *enc_message =
@@ -3082,10 +3085,12 @@ process_peerinfo (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @param cls closure
  * @param peer peer identity this notification is about
  * @param atsi performance data
+ * @param atsi_count number of entries in atsi
  */
 static void
 handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
-                     const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+                     const struct GNUNET_ATS_Information *atsi,
+                     unsigned int atsi_count)
 {
   struct DirectNeighbor *neighbor;
   struct DistantNeighbor *about;
@@ -3098,7 +3103,7 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
   if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
     return;
 
-  distance = get_atsi_distance (atsi);
+  distance = get_atsi_distance (atsi, atsi_count);
   if ((distance == DIRECT_NEIGHBOR_COST) &&
       (GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey)
        == NULL))
@@ -3290,10 +3295,10 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
       GNUNET_CONTAINER_multihashmap_create (max_table_size * 3);
 
   GNUNET_SERVER_add_handlers (server, plugin_handlers);
-  coreAPI = GNUNET_CORE_connect (cfg, 1, NULL,  /* FIXME: anything we want to pass around? */
+  coreAPI = GNUNET_CORE_connect (cfg, NULL,  /* FIXME: anything we want to pass around? */
                                  &core_init, &handle_core_connect,
-                                 &handle_core_disconnect, NULL, NULL, GNUNET_NO,
-                                 NULL, GNUNET_NO, core_handlers);
+                                 &handle_core_disconnect, NULL, GNUNET_NO, NULL,
+                                 GNUNET_NO, core_handlers);
 
   if (coreAPI == NULL)
     return;