/*
This file is part of GNUnet
- (C) 2008--2014 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2008--2014 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
* @file testbed/generate-underlay-topology.c
* @brief Program to generate a database file containing given underlay topology
- * @author Sree Harsha Totakura <sreeharsha@totakura.in>
+ * @author Sree Harsha Totakura <sreeharsha@totakura.in>
*/
#include "platform.h"
FPRINTF (stdout, "%u -> %u\n", A, B);
GNUNET_break (SQLITE_OK == sqlite3_reset (stmt_insert));
//GNUNET_break (SQLITE_OK == sqlite3_clear_bindings (stmt_insert));
+ if ( (SQLITE_OK != sqlite3_bind_int (stmt_insert, 1, B)) ||
+ (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, A)) )
+ {
+ LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_int");
+ return GNUNET_SYSERR;
+ }
+ if (SQLITE_DONE != sqlite3_step (stmt_insert))
+ {
+ LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step");
+ return GNUNET_SYSERR;
+ }
+ FPRINTF (stdout, "%u -> %u\n", B, A);
+ GNUNET_break (SQLITE_OK == sqlite3_reset (stmt_insert));
return GNUNET_OK;
}
"oid INTEGER,"
"bandwidth INTEGER DEFAULT NULL,"
"latency INTEGER DEFAULT NULL,"
- "loss INTEGER DEFAULT NULL);";
+ "loss INTEGER DEFAULT NULL,"
+ " UNIQUE ("
+ " id,"
+ " oid"
+ " ) ON CONFLICT IGNORE"
+ ");";
const char *query_insert =
"INSERT INTO whitelist("
" id,"
" ?1,"
" ?2,"
" ?3,"
- " ?4,"
+ " ?4,"
" ?5);";
int ret;
-
- if (SQLITE_OK != (ret = sqlite3_open (dbfile, &db)))
+
+ ret = GNUNET_SYSERR;
+ if (SQLITE_OK != sqlite3_open (dbfile, &db))
{
LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_open");
goto err_ret;
if (0 != sqlite3_exec (db, query_create, NULL, NULL, NULL))
{
LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
+ FPRINTF (stderr, "Error: %d. Perhaps the database `%s' already exits.\n",
+ sqlite3_errcode (db),
+ dbfile);
goto err_ret;
}
- if (0 != sqlite3_exec (db, "PRAGMA synchronous = 0;", NULL, NULL, NULL))
- {
- LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
- goto err_ret;
- }
- if (SQLITE_OK != (ret = sqlite3_prepare_v2 (db, query_insert, -1,
- &stmt_insert, NULL)))
+ GNUNET_break (0 == sqlite3_exec (db, "PRAGMA synchronous = 0;", NULL, NULL, NULL));
+ if (SQLITE_OK != sqlite3_prepare_v2 (db, query_insert, -1,
+ &stmt_insert, NULL))
{
LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2");
goto err_ret;
}
-
+ ret = GNUNET_OK;
+
err_ret:
- return (SQLITE_OK != ret) ? GNUNET_SYSERR : GNUNET_OK;
+ return ret;
}
unsigned int argc;
argc = 0;
+ arg_uint1 = 0; /* make compilers happy */
+ arg_uint2 = 0; /* make compilers happy */
if (NULL == args)
{
- LOG_ERROR (_("Need atleast 2 arguments\n"));
+ LOG_ERROR (_("Need at least 2 arguments\n"));
return;
}
if (NULL == (dbfile = args[argc++]))
LOG_ERROR (_("Invalid topology: %s\n"), topology_string);
return;
}
+ arg_str1 = NULL;
/* parse for first TOPOOPT. This can either be arg_uint1 or arg_str1 */
switch (topology)
{
}
break;
default:
- GNUNET_assert (0);
+ break;
}
/* parse for second TOPOOPT. Only required for SCALE_FREE topology */
switch (topology)
GNUNET_GETOPT_OPTION_END
};
int ret;
-
+
exit_result = GNUNET_SYSERR;
ret =
GNUNET_PROGRAM_run (argc, argv, "gnunet-underlay-topology",
if (NULL != stmt_insert)
sqlite3_finalize (stmt_insert);
if (NULL != db)
- sqlite3_close (db);
+ GNUNET_break (SQLITE_OK == sqlite3_close (db));
if ((GNUNET_OK != ret) || (GNUNET_OK != exit_result))
return 1;
return 0;