mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-12-06 07:24:19 +00:00
Whether a claim may replace what an observer has stored, own or foreign, is now decided in one place under the observer's seat lock: an older claim never undoes a newer one, the claim spacing holds across both kinds, and an unsigned claim is refused while a signed one is live. An observer that turns foreign loses every assignment in the same transaction, requested ones its claim does not name included. A server that starts checking drops the claims that were not placed under its current host and broker list. A foreign reading never counts as a repeater's newest; one from an observer this server assigned the target stays its own; with authority approved it needs approval to be trusted. A null sig or poll_url is refused. A packet's broker set only grows. The foreign reading lookups get a partial index (093), the MQTT 5 connected flag follows the current connection only, and queued messages are charged for their source.
36 lines
2.1 KiB
SQL
36 lines
2.1 KiB
SQL
-- Copyright 2026 Beacon Contributors
|
|
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
-- What a claim says about where its observer reports: the host of its poll_url ('' when the firmware sends none)
|
|
-- and whether its signature was checked.
|
|
ALTER TABLE polling_claims ADD COLUMN IF NOT EXISTS poll_host text NOT NULL DEFAULT '';
|
|
ALTER TABLE polling_claims ADD COLUMN IF NOT EXISTS signed boolean NOT NULL DEFAULT false;
|
|
-- Which check-mode settings the claim was taken as this server's own under, '' when none were in force. A server
|
|
-- that starts checking drops the claims that were not placed under its current settings.
|
|
ALTER TABLE polling_claims ADD COLUMN IF NOT EXISTS claim_policy text NOT NULL DEFAULT '';
|
|
|
|
-- Claims from observers this server does not manage (polling.foreign_claims: check). They are kept apart from
|
|
-- polling_claims so no election, owners answer or request ever sees them.
|
|
CREATE TABLE IF NOT EXISTS polling_foreign_claims (
|
|
observer_public_key bytea PRIMARY KEY CHECK (octet_length(observer_public_key) = 32),
|
|
observer_id uuid NOT NULL REFERENCES observers(id) ON DELETE CASCADE,
|
|
client text NOT NULL DEFAULT '',
|
|
poll_host text NOT NULL DEFAULT '',
|
|
signed boolean NOT NULL DEFAULT false,
|
|
claimed_at timestamp with time zone NOT NULL,
|
|
received_at timestamp with time zone NOT NULL
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_polling_foreign_claims_observer ON polling_foreign_claims USING btree (observer_id);
|
|
|
|
CREATE TABLE IF NOT EXISTS polling_foreign_targets (
|
|
observer_public_key bytea NOT NULL REFERENCES polling_foreign_claims(observer_public_key) ON DELETE CASCADE,
|
|
target_public_key bytea NOT NULL,
|
|
state text NOT NULL DEFAULT '',
|
|
misses smallint NOT NULL DEFAULT 0,
|
|
PRIMARY KEY (observer_public_key, target_public_key)
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_polling_foreign_targets_target ON polling_foreign_targets USING btree (target_public_key);
|
|
|
|
-- True for a reading taken by an observer this server does not manage, set when the reading is stored.
|
|
ALTER TABLE repeater_readings ADD COLUMN IF NOT EXISTS foreign_source boolean NOT NULL DEFAULT false;
|