#include "gnunet_ats_service.h"
#include "ats.h"
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
-#define VERBOSE_ARM GNUNET_EXTRA_LOGGING
+#define VERBOSE_ARM GNUNET_NO
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
static struct GNUNET_ATS_SchedulingHandle *ats;
-struct GNUNET_OS_Process * arm_proc;
+struct GNUNET_OS_Process *arm_proc;
+
+
static int ret;
struct Address
{
- char * plugin;
+ char *plugin;
size_t plugin_len;
- void * addr;
+ void *addr;
size_t addr_len;
- struct GNUNET_TRANSPORT_ATS_Information * ats;
+ struct GNUNET_ATS_Information *ats;
int ats_count;
- void *session;
+ void *session;
};
struct PeerContext
{
struct GNUNET_PeerIdentity id;
- struct Address * addr;
+ struct Address *addr;
};
+struct Address addr[2];
+struct PeerContext p[2];
+struct GNUNET_ATS_Information atsi[2];
static void
stop_arm ()
static void
end ()
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
if (die_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel(die_task);
+ GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_NO_TASK;
}
static void
-address_suggest_cb (void *cls,
- const struct
- GNUNET_PeerIdentity *
- peer,
- const char *plugin_name,
- const void *plugin_addr,
- size_t plugin_addr_len,
- struct Session * session,
- struct
- GNUNET_BANDWIDTH_Value32NBO
- bandwidth_out,
- struct
- GNUNET_BANDWIDTH_Value32NBO
- bandwidth_in,
- const struct
- GNUNET_TRANSPORT_ATS_Information
- * ats,
+address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
+ struct Session *session,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+ const struct GNUNET_ATS_Information *ats,
uint32_t ats_count)
-
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "address_suggest_cb `%s'\n", GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n",
+ GNUNET_i2s (&address->peer));
+
+ GNUNET_assert (0 ==
+ memcmp (&address->peer, &p[0].id,
+ sizeof (struct GNUNET_PeerIdentity)));
+ GNUNET_assert (0 == strcmp (address->transport_name, addr[0].plugin));
+ GNUNET_assert (address->address_length == addr[0].addr_len);
+ GNUNET_assert (0 ==
+ memcmp (address->address, addr[0].plugin,
+ address->address_length));
+ GNUNET_assert (addr[0].session == session);
+
+
+ /* TODO ats merge
+ * GNUNET_assert (ats_count == 2);
+ * GNUNET_assert (atsi[0].type == htons (1));
+ * GNUNET_assert (atsi[0].type == htons (2));
+ * GNUNET_assert (atsi[1].type == htons (2));
+ * GNUNET_assert (atsi[1].type == htons (2));
+ */
+
+ ret = 0;
- end ();
+ GNUNET_SCHEDULER_add_now (&end, NULL);
}
void
start_arm (const char *cfgname)
{
- arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ arm_proc =
+ GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE_ARM
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
}
static void
check (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
+ struct GNUNET_HELLO_Address address0;
+
ret = GNUNET_SYSERR;
- struct Address addr;
- struct PeerContext p;
- die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL);
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
start_arm (cfgfile);
ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
if (ats == NULL)
{
ret = GNUNET_SYSERR;
+ end ();
return;
}
/* set up peer */
- GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p.id.hashPubKey);
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
+ &p[0].id.hashPubKey);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
+ GNUNET_i2s (&p[0].id));
+
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
+ &p[1].id.hashPubKey);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
+ GNUNET_i2s (&p[1].id));
+
+ addr[0].plugin = "test";
+ addr[0].session = NULL;
+ addr[0].addr = GNUNET_strdup ("test");
+ addr[0].addr_len = 4;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing address creation\n");
+
+ address0.peer = p[0].id;
+ address0.transport_name = addr[0].plugin;
+ address0.address = addr[0].addr;
+ address0.address_length = addr[0].addr_len;
+ GNUNET_ATS_address_update (ats, &address0, addr[0].session, NULL, 0);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info creation\n");
+
+ atsi[0].type = htonl (GNUNET_ATS_UTILIZATION_UP);
+ atsi[0].value = htonl (1024);
+
+ GNUNET_ATS_address_update (ats, &address0, addr[0].session, atsi, 1);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info update\n");
+
+ atsi[0].type = htonl (GNUNET_ATS_UTILIZATION_UP);
+ atsi[0].value = htonl (2048);
+ atsi[1].type = htonl (GNUNET_ATS_UTILIZATION_DOWN);
+ atsi[1].value = htonl (1024);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p.id));
- p.addr = &addr;
- addr.plugin = "test";
- addr.session = NULL;
- addr.addr = NULL;
- addr.addr_len = 0;
+ GNUNET_ATS_address_update (ats, &address0, addr[0].session, atsi, 2);
- GNUNET_ATS_address_update(ats, &p.id, addr.plugin, addr.addr, addr.addr_len, addr.session, NULL, 0);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing manual address deletion \n");
+ address0.peer = p[1].id; // FIXME: why? typo in old code?
+ GNUNET_ATS_address_update (ats, &address0, addr[0].session, NULL, 0);
+ GNUNET_ATS_address_destroyed (ats, &address0, addr[0].session);
- GNUNET_ATS_suggest_address(ats, &p.id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n",
+ GNUNET_i2s (&p[0].id));
+ GNUNET_ATS_suggest_address (ats, &p[0].id);
}
int