CREATE TABLE config (
  ConfigID    INTEGER NOT NULL PRIMARY KEY, -- Always 1.
  Password    BLOB    NOT NULL  -- bcrypt password for web interface
) WITHOUT ROWID;

CREATE TABLE networks (
  NetworkID   INTEGER NOT NULL PRIMARY KEY,
  LocalDomain TEXT    NOT NULL UNIQUE, -- Network/interface name.
  Network     BLOB    NOT NULL UNIQUE  -- Network (/24), example 10.51.50.0
) WITHOUT ROWID;

CREATE TABLE peers (
  NetworkID  INTEGER NOT NULL,
  PeerIP     INTEGER NOT NULL,           -- Final byte of IP.
  Version    INTEGER NOT NULL,           -- Changes when updated.
  APIKey     TEXT    NOT NULL UNIQUE,    -- Peer's secret API key.
  Name       TEXT    NOT NULL,           -- For humans.
  Addr4      BLOB    NOT NULL,
  Addr6      BLOB    NOT NULL,
  Port       INTEGER NOT NULL,
  Relay      INTEGER NOT NULL DEFAULT 0, -- Boolean if peer will forward packets.
  WGPubKey   BLOB    NOT NULL,
  SignPubKey BLOB    NOT NULL,
  UNIQUE(NetworkID, Name),
  PRIMARY KEY(NetworkID, PeerIP)
) WITHOUT ROWID;
