#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_statistics_service.h"
+#include "gnunet_ats_service.h"
#include "gnunet-service-ats_addresses_mlp.h"
-#define VERBOSE GNUNET_EXTRA_LOGGING
+#define VERBOSE GNUNET_YES
#define VERBOSE_ARM GNUNET_EXTRA_LOGGING
#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
struct GNUNET_STATISTICS_Handle * stats;
+struct GNUNET_CONTAINER_MultiHashMap * addresses;
+
struct GAS_MLP_Handle *mlp;
+static void
+create_address (struct ATS_Address *addr, char * plugin, int ats_count, struct GNUNET_ATS_Information *ats)
+{
+ addr->mlp_information = NULL;
+ addr->next = NULL;
+ addr->prev = NULL;
+ addr->plugin = strdup (plugin);
+ addr->ats_count = ats_count;
+ addr->ats = ats;
+}
+
+static void
+set_ats (struct GNUNET_ATS_Information *ats, uint32_t type, uint32_t value)
+{
+ ats->type = type;
+ ats->value = value;
+}
+
static void
check (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
ret = 1;
return;
#endif
+ struct ATS_Address addr[10];
+
stats = GNUNET_STATISTICS_create("ats", cfg);
+ addresses = GNUNET_CONTAINER_multihashmap_create (10);
+
+ /* Creating address 1 */
+ GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &addr[0].peer.hashPubKey);
+ struct GNUNET_ATS_Information a1_ats[3];
+ set_ats (&a1_ats[0], GNUNET_ATS_QUALITY_NET_DISTANCE, 1);
+ set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 32);
+ set_ats (&a1_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0);
+ create_address (&addr[0], "dummy", 3, &a1_ats[0]);
+
+ GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &addr[1].peer.hashPubKey);
+ struct GNUNET_ATS_Information a2_ats[3];
+ set_ats (&a2_ats[0], GNUNET_ATS_ARRAY_TERMINATOR, 0);
+ set_ats (&a2_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 32);
+ set_ats (&a2_ats[2], GNUNET_ATS_QUALITY_NET_DISTANCE, 1);
+
+ create_address (&addr[1], "dummy2", 3, &a2_ats[0]);
+
+ GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey, &addr[0], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+
mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
+ mlp->auto_solve = GNUNET_NO;
+
+ /* Add a new address */
+ GAS_mlp_address_update (mlp, addresses, &addr[0]);
+
GNUNET_assert (mlp != NULL);
+ GNUNET_assert (mlp->addr_in_problem == 1);
+
+ /* Update an new address */
+ set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 20);
+ GAS_mlp_address_update (mlp, addresses, &addr[0]);
+ GNUNET_assert (mlp->addr_in_problem == 1);
+
+ /* Add a second address for same peer */
+ GNUNET_CONTAINER_multihashmap_put(addresses, &addr[1].peer.hashPubKey, &addr[1], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ GAS_mlp_address_update (mlp, addresses, &addr[1]);
+ GNUNET_assert (mlp->addr_in_problem == 2);
+
+ GNUNET_assert (GNUNET_OK == GAS_mlp_solve_problem(mlp));
+
+ /* Delete an address */
+ GNUNET_CONTAINER_multihashmap_remove (addresses, &addr[0].peer.hashPubKey, &addr[0]);
+ GAS_mlp_address_delete (mlp, addresses, &addr[0]);
+ GAS_mlp_address_delete (mlp, addresses, &addr[1]);
GAS_mlp_done (mlp);
+ GNUNET_free (addr[0].plugin);
+ GNUNET_free (addr[1].plugin);
+ GNUNET_CONTAINER_multihashmap_destroy (addresses);
GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
ret = 0;