GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
gnunet-daemon-testbed-underlay.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_transport_service.h"
#include "gnunet_transport_manipulation_service.h"
#include "gnunet_ats_service.h"
#include "gnunet_testing_lib.h"
#include <sqlite3.h>
Include dependency graph for gnunet-daemon-testbed-underlay.c:

Go to the source code of this file.

Data Structures

struct  WhiteListRow
 Whilelist entry. More...
 

Macros

#define LOG(type, ...)   GNUNET_log (type, __VA_ARGS__)
 Logging shorthand. More...
 
#define DEBUG(...)   LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
 Debug logging shorthand. More...
 
#define LOG_SQLITE(db, msg, level, cmd)
 Log an error message at log-level 'level' that indicates a failure of the command 'cmd' on file 'filename' with the message given by strerror(errno). More...
 

Functions

static int iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Iterator over hash map entries. More...
 
static void cleanup_map ()
 Cleaup and destroy the map. More...
 
static int check_access (void *cls, const struct GNUNET_PeerIdentity *pid)
 Function that decides if a connection is acceptable or not. More...
 
static int get_identity (unsigned int offset, struct GNUNET_PeerIdentity *id)
 
static int load_keys (const struct GNUNET_CONFIGURATION_Handle *c)
 Function to load keys. More...
 
static void unload_keys ()
 Function to unload keys. More...
 
static void do_shutdown (void *cls)
 Shutdown task to cleanup our resources and exit. More...
 
static int db_read_whitelist (struct sqlite3 *db, int pid, struct WhiteListRow **wl_rows)
 Function to read whitelist rows from the database. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Main function that will be run. More...
 
int main (int argc, char *const *argv)
 The main function. More...
 

Variables

static struct GNUNET_CONTAINER_MultiPeerMapmap
 The map to store the peer identities to allow/deny. More...
 
static struct sqlite3 * db
 The database connection. More...
 
static struct GNUNET_TRANSPORT_Blacklistbh
 The blacklist handle we obtain from transport when we register ourselves for access control. More...
 
struct GNUNET_DISK_FileHandlehostkeys_fd
 The hostkeys file. More...
 
static struct GNUNET_DISK_MapHandlehostkeys_map
 The hostkeys map. More...
 
static void * hostkeys_data
 The hostkeys data. More...
 
static struct GNUNET_TRANSPORT_ManipulationHandletransport
 Handle to the transport service. More...
 
static unsigned int num_hostkeys
 The number of hostkeys in the hostkeys array. More...
 

Macro Definition Documentation

◆ LOG

#define LOG (   type,
  ... 
)    GNUNET_log (type, __VA_ARGS__)

Logging shorthand.

Definition at line 40 of file gnunet-daemon-testbed-underlay.c.

Referenced by load_keys(), and run().

◆ DEBUG

#define DEBUG (   ...)    LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)

Debug logging shorthand.

Definition at line 46 of file gnunet-daemon-testbed-underlay.c.

Referenced by check_access(), and run().

◆ LOG_SQLITE

#define LOG_SQLITE (   db,
  msg,
  level,
  cmd 
)
Value:
do { \
GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), \
cmd, __FILE__,__LINE__, sqlite3_errmsg(db)); \
if (msg != NULL) \
GNUNET_asprintf(msg, _("`%s' failed at %s:%u with error: %s"), cmd, \
__FILE__, __LINE__, sqlite3_errmsg(db)); \
} while(0)
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static struct sqlite3 * db
The database connection.

Log an error message at log-level 'level' that indicates a failure of the command 'cmd' on file 'filename' with the message given by strerror(errno).

Definition at line 54 of file gnunet-daemon-testbed-underlay.c.

Referenced by db_read_whitelist(), and run().

Function Documentation

◆ cleanup_map()

static void cleanup_map ( )
static

Cleaup and destroy the map.

Definition at line 130 of file gnunet-daemon-testbed-underlay.c.

References GNUNET_assert, GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_SYSERR, and iterator().

Referenced by do_shutdown().

131 {
132  if (NULL != map)
133  {
135  &iterator,
136  NULL));
138  map = NULL;
139  }
140 }
static int iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator over hash map entries.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CONTAINER_MultiPeerMap * map
The map to store the peer identities to allow/deny.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_access()

static int check_access ( void *  cls,
const struct GNUNET_PeerIdentity pid 
)
static

Function that decides if a connection is acceptable or not.

Parameters
clsclosure
pidpeer to approve or disapproave
Returns
GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not

Definition at line 151 of file gnunet-daemon-testbed-underlay.c.

References DEBUG, GNUNET_assert, GNUNET_CONTAINER_multipeermap_contains(), GNUNET_i2s(), GNUNET_OK, GNUNET_SYSERR, and GNUNET_YES.

Referenced by run().

152 {
153  int contains;
154 
155  GNUNET_assert (NULL != map);
157  if (GNUNET_YES == contains)
158  {
159  DEBUG ("Permitting `%s'\n", GNUNET_i2s (pid));
160  return GNUNET_OK;
161  }
162  DEBUG ("Not permitting `%s'\n", GNUNET_i2s (pid));
163  return GNUNET_SYSERR;
164 }
#define DEBUG(...)
Debug logging shorthand.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CONTAINER_MultiPeerMap * map
The map to store the peer identities to allow/deny.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_YES
Definition: gnunet_common.h:80
int GNUNET_CONTAINER_multipeermap_contains(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Check if the map contains any value under the given key (including values that are NULL)...
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_identity()

static int get_identity ( unsigned int  offset,
struct GNUNET_PeerIdentity id 
)
static

Definition at line 168 of file gnunet-daemon-testbed-underlay.c.

References GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, GNUNET_TESTING_HOSTKEYFILESIZE, hostkeys_data, num_hostkeys, and GNUNET_PeerIdentity::public_key.

Referenced by run().

170 {
171  struct GNUNET_CRYPTO_EddsaPrivateKey private_key;
172 
173  if (offset >= num_hostkeys)
174  return GNUNET_SYSERR;
175  GNUNET_memcpy (&private_key,
177  GNUNET_TESTING_HOSTKEYFILESIZE);
179  &id->public_key);
180  return GNUNET_OK;
181 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_TESTING_HOSTKEYFILESIZE
Size of each hostkey in the hostkey file (in BYTES).
static void * hostkeys_data
The hostkeys data.
#define GNUNET_memcpy(dst, src, n)
static unsigned int num_hostkeys
The number of hostkeys in the hostkeys array.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:272
Private ECC key encoded for transmission.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_keys()

static int load_keys ( const struct GNUNET_CONFIGURATION_Handle c)
static

Function to load keys.

Definition at line 211 of file gnunet-daemon-testbed-underlay.c.

References _, GNUNET_asprintf(), GNUNET_DISK_file_map(), GNUNET_DISK_file_open(), GNUNET_DISK_file_size(), GNUNET_DISK_MAP_TYPE_READ, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_strerror, GNUNET_log_strerror_file, GNUNET_OK, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_DATADIR, GNUNET_SYSERR, GNUNET_TESTING_HOSTKEYFILESIZE, GNUNET_YES, hostkeys_data, LOG, and num_hostkeys.

Referenced by run().

212 {
213  char *data_dir;
214  char *idfile;
215  uint64_t fsize;
216 
217  data_dir = NULL;
218  idfile = NULL;
219  fsize = 0;
221  GNUNET_asprintf (&idfile, "%s/testing_hostkeys.ecc", data_dir);
222  GNUNET_free (data_dir);
223  data_dir = NULL;
224  if (GNUNET_OK !=
225  GNUNET_DISK_file_size (idfile, &fsize, GNUNET_YES, GNUNET_YES))
226  {
227  GNUNET_free (idfile);
228  return GNUNET_SYSERR;
229  }
230  if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE))
231  {
233  _("Incorrect hostkey file format: %s\n"), idfile);
234  GNUNET_free (idfile);
235  return GNUNET_SYSERR;
236  }
239  if (NULL == hostkeys_fd)
240  {
242  GNUNET_free (idfile);
243  return GNUNET_SYSERR;
244  }
245  GNUNET_free (idfile);
246  idfile = NULL;
248  &hostkeys_map,
250  fsize);
251  if (NULL == hostkeys_data)
252  {
253 
255  return GNUNET_SYSERR;
256  }
258  return GNUNET_OK;
259 }
Open the file for reading.
void * GNUNET_DISK_file_map(const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK_MapHandle **m, enum GNUNET_DISK_MapType access, size_t len)
Map a file into memory.
Definition: disk.c:2020
Nobody is allowed to do anything to the file.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define LOG(type,...)
Logging shorthand.
static struct GNUNET_DISK_MapHandle * hostkeys_map
The hostkeys map.
#define GNUNET_TESTING_HOSTKEYFILESIZE
Size of each hostkey in the hostkey file (in BYTES).
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static void * hostkeys_data
The hostkeys data.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
char * GNUNET_OS_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX, the current running apps installation directory.
Read-only memory map.
static unsigned int num_hostkeys
The number of hostkeys in the hostkeys array.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
int GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:289
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1673
Return the directory where data is installed (share/gnunet/)
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_DISK_FileHandle * hostkeys_fd
The hostkeys file.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unload_keys()

static void unload_keys ( )
static

Function to unload keys.

Definition at line 266 of file gnunet-daemon-testbed-underlay.c.

References GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_unmap(), and hostkeys_data.

Referenced by do_shutdown().

267 {
268  if (NULL != hostkeys_map)
269  {
270  GNUNET_assert (NULL != hostkeys_data);
272  hostkeys_map = NULL;
273  hostkeys_data = NULL;
274  }
275  if (NULL != hostkeys_fd)
276  {
278  hostkeys_fd = NULL;
279  }
280 }
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1817
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_DISK_MapHandle * hostkeys_map
The hostkeys map.
static void * hostkeys_data
The hostkeys data.
int GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:2100
struct GNUNET_DISK_FileHandle * hostkeys_fd
The hostkeys file.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Shutdown task to cleanup our resources and exit.

Parameters
clsNULL

Definition at line 289 of file gnunet-daemon-testbed-underlay.c.

References cleanup_map(), GNUNET_TRANSPORT_blacklist_cancel(), GNUNET_TRANSPORT_manipulation_disconnect(), and unload_keys().

Referenced by run().

290 {
291  if (NULL != transport)
292  {
294  transport = NULL;
295  }
296  cleanup_map ();
297  unload_keys ();
298  if (NULL != bh)
300 }
void GNUNET_TRANSPORT_blacklist_cancel(struct GNUNET_TRANSPORT_Blacklist *br)
Abort the blacklist.
static struct GNUNET_TRANSPORT_Blacklist * bh
The blacklist handle we obtain from transport when we register ourselves for access control...
void GNUNET_TRANSPORT_manipulation_disconnect(struct GNUNET_TRANSPORT_ManipulationHandle *handle)
Disconnect from the transport service.
static void cleanup_map()
Cleaup and destroy the map.
static void unload_keys()
Function to unload keys.
static struct GNUNET_TRANSPORT_ManipulationHandle * transport
Handle to the transport service.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ db_read_whitelist()

static int db_read_whitelist ( struct sqlite3 *  db,
int  pid,
struct WhiteListRow **  wl_rows 
)
static

Function to read whitelist rows from the database.

Parameters
dbthe database connection
pidthe identity of this peer
wl_rowswhere to store the retrieved whitelist rows
Returns
GNUNET_SYSERR upon error OR the number of rows retrieved

Definition at line 312 of file gnunet-daemon-testbed-underlay.c.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_new, GNUNET_SYSERR, WhiteListRow::id, WhiteListRow::latency, LOG_SQLITE, lr, WhiteListRow::next, and ret.

Referenced by run().

313 {
314  static const char *query_wl = "SELECT oid, latency FROM whitelist WHERE (id == ?);";
315  struct sqlite3_stmt *stmt_wl;
316  struct WhiteListRow *lr;
317  int nrows;
318  int ret;
319 
320  if (SQLITE_OK != (ret = sqlite3_prepare_v2 (db, query_wl, -1, &stmt_wl, NULL)))
321  {
322  LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2");
323  return GNUNET_SYSERR;
324  }
325  if (SQLITE_OK != (ret = sqlite3_bind_int (stmt_wl, 1, pid)))
326  {
327  LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int");
328  sqlite3_finalize (stmt_wl);
329  return GNUNET_SYSERR;
330  }
331  nrows = 0;
332  do
333  {
334  ret = sqlite3_step (stmt_wl);
335  if (SQLITE_ROW != ret)
336  break;
337  nrows++;
338  lr = GNUNET_new (struct WhiteListRow);
339  lr->id = sqlite3_column_int (stmt_wl, 0);
340  lr->latency = sqlite3_column_int (stmt_wl, 1);
341  lr->next = *wl_rows;
342  *wl_rows = lr;
343  } while (1);
344  sqlite3_finalize (stmt_wl);
345  return nrows;
346 }
static struct GNUNET_GNS_LookupWithTldRequest * lr
Handle to lookup request.
Definition: gnunet-gns.c:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
static struct sqlite3 * db
The database connection.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct WhiteListRow * next
Next ptr.
#define LOG_SQLITE(db, msg, level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; on file &#39;file...
int latency
Latency to be assigned to the link.
unsigned int id
The offset where to find the hostkey for the peer.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle c 
)
static

Main function that will be run.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cconfiguration

Definition at line 358 of file gnunet-daemon-testbed-underlay.c.

References check_access(), db, db_read_whitelist(), DEBUG, do_shutdown(), get_identity(), GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_multipeermap_create(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_i2s(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SYSERR, GNUNET_TRANSPORT_blacklist(), GNUNET_TRANSPORT_manipulation_connect(), GNUNET_TRANSPORT_manipulation_disconnect(), GNUNET_TRANSPORT_manipulation_set(), WhiteListRow::id, WhiteListRow::latency, load_keys(), LOG, LOG_SQLITE, WhiteListRow::next, pid, GNUNET_TIME_Relative::rel_value_us, and ret.

Referenced by main().

360 {
361  char *dbfile;
362  struct WhiteListRow *wl_head;
363  struct WhiteListRow *wl_entry;
365  struct GNUNET_ATS_Properties prop;
367  unsigned long long pid;
368  unsigned int nrows;
369  int ret;
370 
371  if (GNUNET_OK !=
373  "PEERID", &pid))
374  {
375  GNUNET_break (0);
376  return;
377  }
378  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "TESTBED-UNDERLAY",
379  "DBFILE",
380  &dbfile))
381  {
382  GNUNET_break (0);
383  return;
384  }
385  if (SQLITE_OK != (ret = sqlite3_open_v2 (dbfile, &db, SQLITE_OPEN_READONLY, NULL)))
386  {
387  if (NULL != db)
388  {
389  LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_open_v2");
390  GNUNET_break (SQLITE_OK == sqlite3_close (db));
391  }
392  else
393  LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot open sqlite file %s\n", dbfile);
394  GNUNET_free (dbfile);
395  return;
396  }
397  DEBUG ("Opened database %s\n", dbfile);
398  GNUNET_free (dbfile);
399  dbfile = NULL;
400  wl_head = NULL;
401  if (GNUNET_OK != load_keys (c))
402  goto close_db;
403 
405  if (NULL == transport)
406  {
407  GNUNET_break (0);
408  return;
409  }
410  /* read and process whitelist */
411  nrows = 0;
412  wl_head = NULL;
413  nrows = db_read_whitelist (db, pid, &wl_head);
414  if ((GNUNET_SYSERR == nrows) || (0 == nrows))
415  {
417  goto close_db;
418  }
420  while (NULL != (wl_entry = wl_head))
421  {
422  wl_head = wl_entry->next;
423  delay.rel_value_us = wl_entry->latency;
424  memset (&prop, 0, sizeof (prop));
425  GNUNET_assert (GNUNET_OK == get_identity (wl_entry->id, &identity));
429  DEBUG ("Setting %u ms latency to peer `%s'\n",
430  wl_entry->latency,
431  GNUNET_i2s (&identity));
433  &identity,
434  &prop,
435  delay,
436  delay);
437  GNUNET_free (wl_entry);
438  }
441 
442  close_db:
443  GNUNET_break (SQLITE_OK == sqlite3_close (db));
444 }
#define DEBUG(...)
Debug logging shorthand.
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
uint64_t rel_value_us
The actual value.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CONTAINER_MultiPeerMap * map
The map to store the peer identities to allow/deny.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define LOG(type,...)
Logging shorthand.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
static int ret
Final status code.
Definition: gnunet-arm.c:89
ATS performance characteristics for an address.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static int check_access(void *cls, const struct GNUNET_PeerIdentity *pid)
Function that decides if a connection is acceptable or not.
, &#39; bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
static struct GNUNET_TRANSPORT_Blacklist * bh
The blacklist handle we obtain from transport when we register ourselves for access control...
struct GNUNET_TRANSPORT_Blacklist * GNUNET_TRANSPORT_blacklist(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_TRANSPORT_BlacklistCallback cb, void *cb_cls)
Install a blacklist callback.
static int get_identity(unsigned int offset, struct GNUNET_PeerIdentity *id)
static struct sqlite3 * db
The database connection.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct WhiteListRow * next
Next ptr.
#define LOG_SQLITE(db, msg, level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; on file &#39;file...
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_TRANSPORT_ManipulationHandle * GNUNET_TRANSPORT_manipulation_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the transport service.
int latency
Latency to be assigned to the link.
void GNUNET_TRANSPORT_manipulation_disconnect(struct GNUNET_TRANSPORT_ManipulationHandle *handle)
Disconnect from the transport service.
static void do_shutdown(void *cls)
Shutdown task to cleanup our resources and exit.
int GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
unsigned int id
The offset where to find the hostkey for the peer.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
void GNUNET_TRANSPORT_manipulation_set(struct GNUNET_TRANSPORT_ManipulationHandle *handle, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Properties *prop, struct GNUNET_TIME_Relative delay_in, struct GNUNET_TIME_Relative delay_out)
Set transport metrics for a peer and a direction.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
static struct GNUNET_TRANSPORT_ManipulationHandle * transport
Handle to the transport service.
static int load_keys(const struct GNUNET_CONFIGURATION_Handle *c)
Function to load keys.
static int db_read_whitelist(struct sqlite3 *db, int pid, struct WhiteListRow **wl_rows)
Function to read whitelist rows from the database.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 455 of file gnunet-daemon-testbed-underlay.c.

References _, GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), ret, and run().

456 {
457  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
459  };
460  int ret;
461 
462  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
463  return 2;
464 #ifdef SQLITE_CONFIG_MMAP_SIZE
465  (void) sqlite3_config (SQLITE_CONFIG_MMAP_SIZE, 512000, 256000000);
466 #endif
467  ret =
468  (GNUNET_OK ==
469  GNUNET_PROGRAM_run (argc, argv, "testbed-underlay",
470  _
471  ("Daemon to restrict underlay network in testbed deployments"),
472  options, &run, NULL)) ? 0 : 1;
473  GNUNET_free ((void*) argv);
474  return ret;
475 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1521
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Definition of a command line option.
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run.
int GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
Definition: program.c:361
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

Variable Documentation

◆ map

struct GNUNET_CONTAINER_MultiPeerMap* map
static

The map to store the peer identities to allow/deny.

Definition at line 67 of file gnunet-daemon-testbed-underlay.c.

◆ db

struct sqlite3* db
static

The database connection.

Definition at line 72 of file gnunet-daemon-testbed-underlay.c.

Referenced by run().

◆ bh

struct GNUNET_TRANSPORT_Blacklist* bh
static

The blacklist handle we obtain from transport when we register ourselves for access control.

Definition at line 78 of file gnunet-daemon-testbed-underlay.c.

◆ hostkeys_fd

struct GNUNET_DISK_FileHandle* hostkeys_fd

The hostkeys file.

Definition at line 83 of file gnunet-daemon-testbed-underlay.c.

◆ hostkeys_map

struct GNUNET_DISK_MapHandle* hostkeys_map
static

The hostkeys map.

Definition at line 88 of file gnunet-daemon-testbed-underlay.c.

◆ hostkeys_data

void* hostkeys_data
static

The hostkeys data.

Definition at line 93 of file gnunet-daemon-testbed-underlay.c.

Referenced by get_identity(), load_keys(), print_key(), and unload_keys().

◆ transport

struct GNUNET_TRANSPORT_ManipulationHandle* transport
static

Handle to the transport service.

This is used for setting link metrics

Definition at line 98 of file gnunet-daemon-testbed-underlay.c.

◆ num_hostkeys

unsigned int num_hostkeys
static

The number of hostkeys in the hostkeys array.

Definition at line 103 of file gnunet-daemon-testbed-underlay.c.

Referenced by get_identity(), and load_keys().