CREATE TABLE config (
  ConfigID    INTEGER NOT NULL PRIMARY KEY, -- Always 1.
  HubAddress  TEXT    NOT NULL, -- https://for.example.com
  VPNNetwork  BLOB    NOT NULL, -- Network (/24), example 10.51.50.0
  Password    BLOB    NOT NULL  -- bcrypt password for web interface
) WITHOUT ROWID;

CREATE TABLE sessions (
  SessionID  TEXT    NOT NULL PRIMARY KEY,
  CSRF       TEXT    NOT NULL,
  SignedIn   INTEGER NOT NULL,
  CreatedAt  INTEGER NOT NULL,
  LastSeenAt INTEGER NOT NULL
) WITHOUT ROWID;

CREATE INDEX sessions_last_seen_index ON sessions(LastSeenAt);

CREATE TABLE peers (
  PeerIP     INTEGER NOT NULL PRIMARY KEY, -- Final byte.
  Version    INTEGER NOT NULL,
  APIKey     TEXT    NOT NULL UNIQUE,
  Name       TEXT    NOT NULL UNIQUE,      -- For humans.
  PublicIP   BLOB    NOT NULL,
  Port       INTEGER NOT NULL,
  Mediator   INTEGER NOT NULL DEFAULT 0,   -- Boolean if peer will forward packets. Must also have public address.
  EncPubKey  BLOB    NOT NULL,
  SignPubKey BLOB    NOT NULL
) WITHOUT ROWID;
