From fcc5bf1e6695c9bfa0aff8d69ebe005043397967 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 29 Jul 2015 15:09:23 -0700 Subject: [PATCH] Go ahead and spec out controller DB support for AuthToken -- GitHub issue #211 -- even though full implementation won't make it into 1.0.4. --- controller/SqliteNetworkController.cpp | 5 +++-- controller/schema.sql | 13 +++++++++++++ controller/schema.sql.c | 13 +++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/controller/SqliteNetworkController.cpp b/controller/SqliteNetworkController.cpp index 50be5b344..c95d3b74b 100644 --- a/controller/SqliteNetworkController.cpp +++ b/controller/SqliteNetworkController.cpp @@ -146,9 +146,10 @@ SqliteNetworkController::SqliteNetworkController(const char *dbPath) : // Prepare statement will fail if Config table doesn't exist, which means our DB // needs to be initialized. if (sqlite3_exec(_db,ZT_NETCONF_SCHEMA_SQL"INSERT INTO Config (k,v) VALUES ('schemaVersion',"ZT_NETCONF_SQLITE_SCHEMA_VERSION_STR");",0,0,0) != SQLITE_OK) { - //printf("%s\n",sqlite3_errmsg(_db)); + char err[1024]; + Utils::snprintf(err,sizeof(err),"SqliteNetworkController cannot initialize database and/or insert schemaVersion into Config table: %s",sqlite3_errmsg(_db)); sqlite3_close(_db); - throw std::runtime_error("SqliteNetworkController cannot initialize database and/or insert schemaVersion into Config table"); + throw std::runtime_error(err); } } diff --git a/controller/schema.sql b/controller/schema.sql index 398d63ac3..48d5607cd 100644 --- a/controller/schema.sql +++ b/controller/schema.sql @@ -17,6 +17,18 @@ CREATE TABLE Network ( memberRevisionCounter integer NOT NULL DEFAULT(1) ); +CREATE TABLE AuthToken ( + id integer PRIMARY KEY NOT NULL, + networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE, + authMode integer NOT NULL DEFAULT(1), + useCount integer NOT NULL DEFAULT(0), + maxUses integer NOT NULL DEFAULT(0), + expiresAt integer NOT NULL DEFAULT(0), + token varchar(256) NOT NULL +); + +CREATE INDEX AuthToken_networkId_token ON AuthToken(networkId,token); + CREATE TABLE Node ( id char(10) PRIMARY KEY NOT NULL, identity varchar(4096) NOT NULL @@ -70,6 +82,7 @@ CREATE TABLE Log ( nodeId char(10) NOT NULL, ts integer NOT NULL, authorized integer NOT NULL, + authTokenId integer, version varchar(16), fromAddr varchar(64) ); diff --git a/controller/schema.sql.c b/controller/schema.sql.c index fa83f880a..49c445486 100644 --- a/controller/schema.sql.c +++ b/controller/schema.sql.c @@ -18,6 +18,18 @@ " memberRevisionCounter integer NOT NULL DEFAULT(1)\n"\ ");\n"\ "\n"\ +"CREATE TABLE AuthToken (\n"\ +" id integer PRIMARY KEY NOT NULL,\n"\ +" networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,\n"\ +" authMode integer NOT NULL DEFAULT(1),\n"\ +" useCount integer NOT NULL DEFAULT(0),\n"\ +" maxUses integer NOT NULL DEFAULT(0),\n"\ +" expiresAt integer NOT NULL DEFAULT(0),\n"\ +" token varchar(256) NOT NULL\n"\ +");\n"\ +"\n"\ +"CREATE INDEX AuthToken_networkId_token ON AuthToken(networkId,token);\n"\ +"\n"\ "CREATE TABLE Node (\n"\ " id char(10) PRIMARY KEY NOT NULL,\n"\ " identity varchar(4096) NOT NULL\n"\ @@ -71,6 +83,7 @@ " nodeId char(10) NOT NULL,\n"\ " ts integer NOT NULL,\n"\ " authorized integer NOT NULL,\n"\ +" authTokenId integer,\n"\ " version varchar(16),\n"\ " fromAddr varchar(64)\n"\ ");\n"\