return ats_count;
}
+static unsigned int
+disassemble_ats_information (const struct GNUNET_ATS_Information *src,
+ uint32_t ats_count,
+ struct ATS_Address *dest)
+{
+ int i;
+ int res = 0;
+ for (i = 0; i < ats_count; i++)
+ switch (ntohl (src[i].type))
+ {
+ case GNUNET_ATS_UTILIZATION_UP:
+ dest->atsp_utilization_out.value__ = src[i].value;
+ res ++;
+ break;
+ case GNUNET_ATS_UTILIZATION_DOWN:
+ dest->atsp_utilization_in.value__ = src[i].value;
+ res ++;
+ break;
+ case GNUNET_ATS_QUALITY_NET_DELAY:
+ dest->atsp_latency.rel_value = ntohl (src[i].value);
+ res ++;
+ break;
+ case GNUNET_ATS_QUALITY_NET_DISTANCE:
+ dest->atsp_distance = ntohl (src[i].value);
+ res ++;
+ break;
+ case GNUNET_ATS_COST_WAN:
+ dest->atsp_cost_wan = ntohl (src[i].value);
+ res ++;
+ break;
+ case GNUNET_ATS_COST_LAN:
+ dest->atsp_cost_lan = ntohl (src[i].value);
+ res ++;
+ break;
+ case GNUNET_ATS_COST_WLAN:
+ dest->atsp_cost_wlan = ntohl (src[i].value);
+ res ++;
+ break;
+ case GNUNET_ATS_NETWORK_TYPE:
+ dest->atsp_network_type = ntohl (src[i].value);
+ res ++;
+ break;
+ case GNUNET_ATS_ARRAY_TERMINATOR:
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Received unsupported ATS type %u\n", ntohl (src[i].type));
+ GNUNET_break (0);
+ break;
+ }
+ return res;
+}
+
/**
* Free the given address
* @param addr address to destroy
static void
free_address (struct ATS_Address *addr)
{
- GNUNET_free_non_null (addr->ats);
GNUNET_free (addr->plugin);
GNUNET_free (addr);
}
session_id);
aa->mlp_information = NULL;
- aa->ats = GNUNET_malloc (atsi_count * sizeof (struct GNUNET_ATS_Information));
- aa->ats_count = atsi_count;
- memcpy (aa->ats, atsi, atsi_count * sizeof (struct GNUNET_ATS_Information));
/* Get existing address or address with session == 0 */
old = find_address (peer, aa);
{
struct ATS_Address *aa;
struct ATS_Address *old;
+ unsigned int ats_res;
if (GNUNET_NO == handle->running)
return;
plugin_addr, plugin_addr_len,
session_id);
aa->mlp_information = NULL;
- aa->ats = GNUNET_malloc (atsi_count * sizeof (struct GNUNET_ATS_Information));
- aa->ats_count = atsi_count;
- memcpy (aa->ats, atsi, atsi_count * sizeof (struct GNUNET_ATS_Information));
+ if (atsi_count != (ats_res = disassemble_ats_information(atsi, atsi_count, aa)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "While adding address: had %u ATS elements to add, could only add %u\n",
+ atsi_count, ats_res);
+ }
/* Get existing address or address with session == 0 */
old = find_address (peer, aa);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Updated existing address for peer `%s' %p with new session %u\n",
GNUNET_i2s (peer), old, session_id);
- GNUNET_free_non_null (old->ats);
old->session_id = session_id;
- old->ats = NULL;
- old->ats_count = 0;
- old->ats = aa->ats;
- old->ats_count = aa->ats_count;
+ if (atsi_count != (ats_res = disassemble_ats_information(atsi, atsi_count, old)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "While updating address: had %u ATS elements to add, could only add %u\n",
+ atsi_count, ats_res);
+ }
GNUNET_free (aa->plugin);
GNUNET_free (aa);
handle->s_update (handle->solver, handle->addresses, old);
*
* @return the index on success, otherwise GNUNET_SYSERR
*/
-
+#if 0
static int
mlp_lookup_ats (struct ATS_Address *addr, int ats_index)
{
else
return GNUNET_SYSERR;
}
+#endif
/**
* Adds the problem constraints for all addresses
GNUNET_assert (NULL != address);
GNUNET_assert (NULL != address->mlp_information);
- GNUNET_assert (NULL != address->ats);
+// GNUNET_assert (NULL != address->ats);
struct MLP_information *mlpi = address->mlp_information;
- struct GNUNET_ATS_Information *ats = address->ats;
+ //struct GNUNET_ATS_Information *ats = address->ats;
GNUNET_assert (mlpi != NULL);
int c;
for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++)
{
- int index = mlp_lookup_ats(address, mlp->q[c]);
+
+ /* FIXME int index = mlp_lookup_ats(address, mlp->q[c]); */
+ int index = GNUNET_SYSERR;
if (index == GNUNET_SYSERR)
continue;
-
+ /* FIXME
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating address for peer `%s' value `%s': %f\n",
GNUNET_i2s (&address->peer),
mlp_ats_to_string(mlp->q[c]),
(double) ats[index].value);
- int i = mlpi->q_avg_i[c];
+ int i = mlpi->q_avg_i[c];*/
double * qp = mlpi->q[c];
+ /* FIXME
qp[i] = (double) ats[index].value;
+ */
int t;
for (t = 0; t < MLP_AVERAGING_QUEUE_LENGTH; t++)
}
/* Update address */
+ /* Prepare ATS Information */
+ test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
+ test_ats_info[0].value = htonl(GNUNET_ATS_NET_LAN);
+ test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
+ test_ats_info[1].value = htonl(3);
+ test_ats_count = 2;
+
+ GNUNET_ATS_address_update (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count);
/* Request address */
GNUNET_ATS_suggest_address (sched_ats, &p.id);
ret = 1;
}
+ if (GNUNET_OK != compare_ats(atsi, ats_count, test_ats_info, test_ats_count))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage 1: Callback with incorrect ats info \n");
+ ret = 1;
+ GNUNET_SCHEDULER_add_now (&end, NULL);
+ return;
+ }
+
GNUNET_SCHEDULER_add_now (&end, NULL);
}
}