moved eval tool to ats
[oweals/gnunet.git] / src / ats / ats_api_scheduling.c
index 1ef6ce09585222f60be81b99bc6124b32085956b..b9574ff5c955afca2b96df3ddf5a20e98917221c 100644 (file)
@@ -643,6 +643,7 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
   address.address = plugin_address;
   address.address_length = plugin_address_length;
   address.transport_name = plugin_name;
+  address.local_info = ntohl(m->address_local_info);
 
   if ((s == NULL) && (0 == address.address_length))
   {
@@ -656,7 +657,9 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
     return;
   }
 
-  sh->suggest_cb (sh->suggest_cb_cls, &address, s, m->bandwidth_out,
+  sh->suggest_cb (sh->suggest_cb_cls,
+                  (const struct GNUNET_PeerIdentity *) &m->peer,
+                  &address, s, m->bandwidth_out,
                   m->bandwidth_in, atsi, ats_count);
 
   GNUNET_CLIENT_receive (sh->client, &process_ats_message, sh,
@@ -967,7 +970,7 @@ GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
 {
   struct GNUNET_ATS_SchedulingHandle *sh;
 
-  sh = GNUNET_malloc (sizeof (struct GNUNET_ATS_SchedulingHandle));
+  sh = GNUNET_new (struct GNUNET_ATS_SchedulingHandle);
   sh->cfg = cfg;
   sh->suggest_cb = suggest_cb;
   sh->suggest_cb_cls = suggest_cb_cls;
@@ -1055,16 +1058,23 @@ GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh,
 }
 
 /**
- * We would like to establish a new connection with a peer.  ATS
- * should suggest a good address to begin with.
+ * We would like to receive address suggestions for a peer. ATS will
+ * respond with a call to the continuation immediately containing an address or
+ * no address if none is available. ATS can suggest more addresses until we call
+ * #GNUNET_ATS_suggest_address_cancel.
+ *
  *
  * @param sh handle
  * @param peer identity of the peer we need an address for
+ * @param cont the continuation to call with the address
+ * @param cont_cls the cls for the continuation
  * @return suggest handle
  */
 struct GNUNET_ATS_SuggestHandle *
 GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
-                            const struct GNUNET_PeerIdentity *peer)
+                            const struct GNUNET_PeerIdentity *peer,
+                            GNUNET_ATS_AddressSuggestionCallback cont,
+                            void *cont_cls)
 {
   struct PendingMessage *p;
   struct RequestAddressMessage *m;
@@ -1083,7 +1093,7 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
   m->peer = *peer;
   GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
   do_transmit (sh);
-  s = GNUNET_malloc (sizeof (struct GNUNET_ATS_SuggestHandle));
+  s = GNUNET_new (struct GNUNET_ATS_SuggestHandle);
   s->id = (*peer);
   GNUNET_CONTAINER_DLL_insert_tail (sh->sug_head, sh->sug_tail, s);
   return s;
@@ -1191,11 +1201,9 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
     return GNUNET_SYSERR;
   }
 
-  namelen =
-      (address->transport_name ==
-       NULL) ? 0 : strlen (address->transport_name) + 1;
-  msize =
-      sizeof (struct AddressUpdateMessage) + address->address_length +
+  namelen = (address->transport_name == NULL) ? 0 : strlen (address->transport_name) + 1;
+
+  msize = sizeof (struct AddressUpdateMessage) + address->address_length +
       ats_count * sizeof (struct GNUNET_ATS_Information) + namelen;
   if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
       (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
@@ -1227,6 +1235,7 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
   m->ats_count = htonl (ats_count);
   m->peer = address->peer;
   m->address_length = htons (address->address_length);
+  m->address_local_info = htonl ((uint32_t) address->local_info);
   m->plugin_name_length = htons (namelen);
   m->session_id = htonl (s);
 
@@ -1321,6 +1330,7 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
   m->ats_count = htonl (ats_count);
   m->peer = address->peer;
   m->address_length = htons (address->address_length);
+  m->address_local_info = htonl ((uint32_t) address->local_info);
   m->plugin_name_length = htons (namelen);
 
   m->session_id = htonl (s);
@@ -1404,6 +1414,7 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
   m->peer = address->peer;
   m->in_use = htons (in_use);
   m->address_length = htons (address->address_length);
+  m->address_local_info = htonl ((uint32_t) address->local_info);
   m->plugin_name_length = htons (namelen);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1479,6 +1490,7 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
   m->reserved = htonl (0);
   m->peer = address->peer;
   m->address_length = htons (address->address_length);
+  m->address_local_info = htonl ((uint32_t) address->local_info);
   m->plugin_name_length = htons (namelen);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,