/*
This file is part of GNUnet
- (C) 2008--2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2008--2013 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
/**
* The hostkeys data
*/
-static char *hostkeys_data;
+static void *hostkeys_data;
/**
* Handle to the transport service. This is used for setting link metrics
/**
* Task for shutdown
*/
-static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
+static struct GNUNET_SCHEDULER_Task * shutdown_task;
/**
GNUNET_assert (NULL != map);
contains = GNUNET_CONTAINER_multipeermap_contains (map, pid);
- return (contains) ? GNUNET_OK : GNUNET_SYSERR;
+ if (GNUNET_YES == contains)
+ {
+ DEBUG ("Permitting `%s'\n", GNUNET_i2s (pid));
+ return GNUNET_OK;
+ }
+ DEBUG ("Not permitting `%s'\n", GNUNET_i2s (pid));
+ return GNUNET_SYSERR;
}
* Next ptr
*/
struct WhiteListRow *next;
-
+
/**
* The offset where to find the hostkey for the peer
*/
unsigned int id;
-
- /**
- * Bandwidth to be assigned to the link
- */
- int bandwidth;
/**
* Latency to be assigned to the link
*/
int latency;
- /**
- * Loss to be assigned to the link
- */
- int loss;
};
static void
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ if (NULL != transport)
+ {
+ GNUNET_TRANSPORT_disconnect (transport);
+ transport = NULL;
+ }
cleanup_map ();
unload_keys ();
if (NULL != bh)
* @return GNUNET_SYSERR upon error OR the number of rows retrieved
*/
static int
-db_read_whitelist (struct sqlite3 *db, unsigned int pid, struct WhiteListRow **wl_rows)
+db_read_whitelist (struct sqlite3 *db, int pid, struct WhiteListRow **wl_rows)
{
- static const char *query_wl = "SELECT (oid, bandwidth, latency, loss) FROM whitelist WHERE (id == ?);";
+ static const char *query_wl = "SELECT oid, latency FROM whitelist WHERE (id == ?);";
struct sqlite3_stmt *stmt_wl;
struct WhiteListRow *lr;
int nrows;
int ret;
-
+
if (SQLITE_OK != (ret = sqlite3_prepare_v2 (db, query_wl, -1, &stmt_wl, NULL)))
{
LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2");
break;
nrows++;
lr = GNUNET_new (struct WhiteListRow);
- lr->id = sqlite3_column_int (stmt_wl, 1);
- lr->bandwidth = sqlite3_column_int (stmt_wl, 2);
- lr->latency = sqlite3_column_int (stmt_wl, 3);
- lr->loss = sqlite3_column_int (stmt_wl, 4);
+ lr->id = sqlite3_column_int (stmt_wl, 0);
+ lr->latency = sqlite3_column_int (stmt_wl, 1);
lr->next = *wl_rows;
*wl_rows = lr;
} while (1);
struct WhiteListRow *wl_head;
struct WhiteListRow *wl_entry;
struct GNUNET_PeerIdentity identity;
- struct GNUNET_ATS_Information params[1];
+ struct GNUNET_ATS_Properties prop;
+ struct GNUNET_TIME_Relative delay;
unsigned long long pid;
unsigned int nrows;
int ret;
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c, "TESTBED",
- "PEERID", &pid))
- {
- GNUNET_break (0);
- return;
- }
- transport = GNUNET_TRANSPORT_connect (c, NULL, NULL, NULL, NULL, NULL);
- if (NULL == transport)
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (c, "TESTBED",
+ "PEERID", &pid))
{
GNUNET_break (0);
return;
if (NULL != db)
{
LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_open_v2");
- sqlite3_close (db);
+ GNUNET_break (SQLITE_OK == sqlite3_close (db));
}
else
LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot open sqlite file %s\n", dbfile);
wl_head = NULL;
if (GNUNET_OK != load_keys (c))
goto close_db;
+
+ transport = GNUNET_TRANSPORT_connect (c, NULL, NULL, NULL, NULL, NULL);
+ if (NULL == transport)
+ {
+ GNUNET_break (0);
+ return;
+ }
/* read and process whitelist */
nrows = 0;
wl_head = NULL;
nrows = db_read_whitelist (db, pid, &wl_head);
if ((GNUNET_SYSERR == nrows) || (0 == nrows))
+ {
+ GNUNET_TRANSPORT_disconnect (transport);
goto close_db;
- map = GNUNET_CONTAINER_multipeermap_create (nrows, GNUNET_YES);
- params[0].type = GNUNET_ATS_QUALITY_NET_DELAY;
+ }
+ map = GNUNET_CONTAINER_multipeermap_create (nrows, GNUNET_NO);
while (NULL != (wl_entry = wl_head))
{
wl_head = wl_entry->next;
- params[0].value = wl_entry->latency;
+ delay.rel_value_us = wl_entry->latency;
+ memset (&prop, 0, sizeof (prop));
GNUNET_assert (GNUNET_OK == get_identity (wl_entry->id, &identity));
GNUNET_break (GNUNET_OK ==
GNUNET_CONTAINER_multipeermap_put (map, &identity, &identity,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+ DEBUG ("Setting %u ms latency to peer `%s'\n",
+ wl_entry->latency,
+ GNUNET_i2s (&identity));
GNUNET_TRANSPORT_set_traffic_metric (transport,
&identity,
- GNUNET_YES,
- GNUNET_YES, /* FIXME: Separate inbound, outboud metrics */
- params, 3);
+ &prop,
+ delay,
+ delay);
GNUNET_free (wl_entry);
}
bh = GNUNET_TRANSPORT_blacklist (c, &check_access, NULL);
&do_shutdown, NULL);
close_db:
- GNUNET_break (GNUNET_OK == sqlite3_close (db));
+ GNUNET_break (SQLITE_OK == sqlite3_close (db));
return;
}
#endif
ret =
(GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-testbed-underlay",
+ GNUNET_PROGRAM_run (argc, argv, "testbed-underlay",
_
("Daemon to restrict underlay network in testbed deployments"),
options, &run, NULL)) ? 0 : 1;