aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rpki/pubd.py87
-rw-r--r--rpki/publication_control.py8
-rw-r--r--rpki/relaxng.py2
-rw-r--r--rpki/sql_schemas.py36
-rw-r--r--schemas/relaxng/publication-control.rng2
-rw-r--r--schemas/sql/pubd.sql34
6 files changed, 166 insertions, 3 deletions
diff --git a/rpki/pubd.py b/rpki/pubd.py
index 5d7c4911..42e18e10 100644
--- a/rpki/pubd.py
+++ b/rpki/pubd.py
@@ -23,6 +23,7 @@ RPKI publication engine.
import os
import re
+import uuid
import time
import logging
import argparse
@@ -165,3 +166,89 @@ class main(object):
logger.exception("Unhandled exception processing client query, path %r", path)
cb(code = 500,
reason = "Could not process PDU: %s" % e)
+
+
+class session_obj(rpki.sql.sql_persistent):
+ """
+ An RRDP session.
+ """
+
+ # We probably need additional columns or an additional table to
+ # handle cleanup of old serial numbers. Not sure quite what these
+ # would look like, other than that the SQL datatypes are probably
+ # BIGINT and DATETIME. Maybe a table to track time at which we
+ # retired a particular serial number, or, to save us the arithmetic,
+ # the corresponding cleanup time?
+
+ sql_template = rpki.sql.template(
+ "session",
+ "session_id",
+ "uuid",
+ "serial")
+
+ def __repr__(self):
+ return rpki.log.log_repr(self, self.uuid, self.serial)
+
+ @classmethod
+ def fetch(cls, gctx):
+ """
+ Fetch the one and only session, creating it if necessary.
+ """
+
+ self = cls.sql_fetch(gctx, 1)
+ if self is None:
+ self = cls()
+ self.gctx = gctx
+ self.session_id = 1
+ self.uuid = uuid.uuid4()
+ self.serial = 1
+ self.sql_store()
+ return self
+
+ @property
+ @rpki.sql.cache_reference
+ def objects(self):
+ return object_obj.sql_fetch_where(self.gctx, "session_id = %s", (self.session_id))
+
+ def next_serial_number(self):
+ """
+ Bump serial number
+ """
+
+ self.serial += 1
+ self.sql_mark_dirty()
+ return self.serial
+
+ # More methods when I know what they look like
+
+
+class object_obj(rpki.sql.sql_persistent):
+ """
+ A published object.
+ """
+
+ sql_template = rpki.sql.template(
+ "object",
+ "object_id",
+ "uri",
+ "hash",
+ "payload",
+ "published",
+ "withdrawn")
+
+ uri = None
+ published = None
+ withdrawn = None
+
+ def __repr__(self):
+ return rpki.log.log_repr(self, self.uri, self.published, self.withdrawn)
+
+ @property
+ @rpki.sql.cache_reference
+ def session(self):
+ return session_obj.sql_fetch(self.gctx, self.session_id)
+
+ @property
+ @rpki.sql.cache_reference
+ def client(self):
+ return rpki.publication_control.client_elt.sql_fetch(self.gctx, self.client_id)
diff --git a/rpki/publication_control.py b/rpki/publication_control.py
index 101592fe..19c7f010 100644
--- a/rpki/publication_control.py
+++ b/rpki/publication_control.py
@@ -83,6 +83,14 @@ class client_elt(rpki.xml_utils.data_elt, rpki.sql.sql_persistent, publication_c
bpki_glue = None
last_cms_timestamp = None
+ def __repr__(self):
+ return rpki.log.log_repr(self, self.client_handle, self.base_uri)
+
+ @property
+ @rpki.sql.cache_reference
+ def objects(self):
+ return rpki.pubd.object_obj.sql_fetch_where(self.gctx, "client_id = %s", (self.client_id,))
+
def serve_post_save_hook(self, q_pdu, r_pdu, cb, eb):
"""
Extra server actions for client_elt.
diff --git a/rpki/relaxng.py b/rpki/relaxng.py
index 3c81a144..d01f7e28 100644
--- a/rpki/relaxng.py
+++ b/rpki/relaxng.py
@@ -1482,7 +1482,7 @@ myrpki = lxml.etree.RelaxNG(lxml.etree.fromstring(r'''<?xml version="1.0" encodi
## Parsed RelaxNG publication_control schema
publication_control = lxml.etree.RelaxNG(lxml.etree.fromstring(r'''<?xml version="1.0" encoding="UTF-8"?>
<!--
- $Id: publication-control.rnc 5881 2014-07-03 16:55:02Z sra $
+ $Id: publication-control.rnc 5883 2014-07-03 19:21:31Z sra $
RelaxNG schema for RPKI publication protocol.
diff --git a/rpki/sql_schemas.py b/rpki/sql_schemas.py
index b85c3dd9..1b9f91be 100644
--- a/rpki/sql_schemas.py
+++ b/rpki/sql_schemas.py
@@ -245,7 +245,7 @@ CREATE TABLE ee_cert (
## @var pubd
## SQL schema pubd
-pubd = '''-- $Id: pubd.sql 5881 2014-07-03 16:55:02Z sra $
+pubd = '''-- $Id: pubd.sql 5883 2014-07-03 19:21:31Z sra $
-- Copyright (C) 2012--2014 Dragon Research Labs ("DRL")
-- Portions copyright (C) 2009--2010 Internet Systems Consortium ("ISC")
@@ -266,7 +266,15 @@ pubd = '''-- $Id: pubd.sql 5881 2014-07-03 16:55:02Z sra $
-- SQL objects needed by pubd.py.
+-- DROP TABLE commands must be in correct (reverse dependency) order
+-- to satisfy FOREIGN KEY constraints.
+
+DROP TABLE IF EXISTS object;
DROP TABLE IF EXISTS client;
+DROP TABLE IF EXISTS session;
+
+-- An old table that should just be flushed if present at all.
+
DROP TABLE IF EXISTS config;
CREATE TABLE client (
@@ -280,6 +288,32 @@ CREATE TABLE client (
UNIQUE (client_handle)
) ENGINE=InnoDB;
+CREATE TABLE session (
+ session_id SERIAL NOT NULL,
+ uuid VARCHAR(36) NOT NULL,
+ serial BIGINT UNSIGNED NOT NULL,
+ PRIMARY KEY (session_id),
+ UNIQUE (uuid)
+) ENGINE=InnoDB;
+
+CREATE TABLE object (
+ object_id SERIAL NOT NULL,
+ uri VARCHAR(255) NOT NULL,
+ hash CHAR(32) BINARY NOT NULL,
+ payload LONGBLOB NOT NULL,
+ published BIGINT UNSIGNED NOT NULL,
+ withdrawn BIGINT UNSIGNED,
+ client_id BIGINT UNSIGNED NOT NULL,
+ session_id BIGINT UNSIGNED NOT NULL,
+ PRIMARY KEY (object_id),
+ CONSTRAINT object_client_id
+ FOREIGN KEY (client_id) REFERENCES client (client_id) ON DELETE CASCADE,
+ CONSTRAINT object_session_id
+ FOREIGN KEY (session_id) REFERENCES session (session_id) ON DELETE CASCADE,
+ UNIQUE (uri),
+ UNIQUE (hash)
+) ENGINE=InnoDB;
+
-- Local Variables:
-- indent-tabs-mode: nil
-- End:
diff --git a/schemas/relaxng/publication-control.rng b/schemas/relaxng/publication-control.rng
index cf624a3c..2376f3e9 100644
--- a/schemas/relaxng/publication-control.rng
+++ b/schemas/relaxng/publication-control.rng
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- $Id: publication-control.rnc 5881 2014-07-03 16:55:02Z sra $
+ $Id: publication-control.rnc 5883 2014-07-03 19:21:31Z sra $
RelaxNG schema for RPKI publication protocol.
diff --git a/schemas/sql/pubd.sql b/schemas/sql/pubd.sql
index 87b899e3..3b9bb844 100644
--- a/schemas/sql/pubd.sql
+++ b/schemas/sql/pubd.sql
@@ -19,7 +19,15 @@
-- SQL objects needed by pubd.py.
+-- DROP TABLE commands must be in correct (reverse dependency) order
+-- to satisfy FOREIGN KEY constraints.
+
+DROP TABLE IF EXISTS object;
DROP TABLE IF EXISTS client;
+DROP TABLE IF EXISTS session;
+
+-- An old table that should just be flushed if present at all.
+
DROP TABLE IF EXISTS config;
CREATE TABLE client (
@@ -33,6 +41,32 @@ CREATE TABLE client (
UNIQUE (client_handle)
) ENGINE=InnoDB;
+CREATE TABLE session (
+ session_id SERIAL NOT NULL,
+ uuid VARCHAR(36) NOT NULL,
+ serial BIGINT UNSIGNED NOT NULL,
+ PRIMARY KEY (session_id),
+ UNIQUE (uuid)
+) ENGINE=InnoDB;
+
+CREATE TABLE object (
+ object_id SERIAL NOT NULL,
+ uri VARCHAR(255) NOT NULL,
+ hash CHAR(32) BINARY NOT NULL,
+ payload LONGBLOB NOT NULL,
+ published BIGINT UNSIGNED NOT NULL,
+ withdrawn BIGINT UNSIGNED,
+ client_id BIGINT UNSIGNED NOT NULL,
+ session_id BIGINT UNSIGNED NOT NULL,
+ PRIMARY KEY (object_id),
+ CONSTRAINT object_client_id
+ FOREIGN KEY (client_id) REFERENCES client (client_id) ON DELETE CASCADE,
+ CONSTRAINT object_session_id
+ FOREIGN KEY (session_id) REFERENCES session (session_id) ON DELETE CASCADE,
+ UNIQUE (uri),
+ UNIQUE (hash)
+) ENGINE=InnoDB;
+
-- Local Variables:
-- indent-tabs-mode: nil
-- End: