Relay marks count every repeater; near relays are gone
The first build counted only the relays past the first hops of the outbound paths. On JP's Public channel, 23 of 23 sent messages came back only through the two home repeaters: each repeater relays one time, and the next hop (8 km away) is too far for the companion to hear. So every message showed the warning mark, and nothing was ever confirmed. Now each repeater that sends a copy back counts, the same as a DM ack: spinner, then a check with the number of repeaters, or a cross. The warning state, the near-relay snapshot of each send, the ^P atom, and heard_via are removed. heard_relays keeps only the paths; a database with the first build of the table gets it made again (derived data only). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f4b1d659d1
commit
5dc62cdc5b
13 files changed
+164
-379
No files matched your search
@@ -189,15 +189,12 @@ CREATE TABLE IF NOT EXISTS node_places (
|
||||
found_at TEXT NOT NULL -- UTC ISO-8601
|
||||
);
|
||||
|
||||
-- Our own channel messages: whether a relay that is not one of our near relays heard them
|
||||
-- (refer to meshterm.services.heard_by). near_hops is a JSON list of the near relays at the
|
||||
-- time of the send. paths is a JSON list of the relay paths of the copies that came back,
|
||||
-- written one time when the message is out of the match window of the packet log. NULL:
|
||||
-- not settled yet.
|
||||
-- Our own channel messages: the relays that sent a copy back (refer to
|
||||
-- meshterm.services.heard_by). paths is a JSON list of the relay paths of the copies,
|
||||
-- written one time when the message is out of the match window of the packet log.
|
||||
CREATE TABLE IF NOT EXISTS heard_relays (
|
||||
message_id INTEGER PRIMARY KEY REFERENCES messages(id) ON DELETE CASCADE,
|
||||
near_hops TEXT,
|
||||
paths TEXT
|
||||
paths TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_traces_run ON traces(run_id);
|
||||
@@ -456,6 +453,17 @@ def _migrate(conn: sqlite3.Connection) -> None:
|
||||
"WHERE sent_at IS NOT NULL"
|
||||
)
|
||||
|
||||
heard_cols = {row["name"] for row in conn.execute("PRAGMA table_info(heard_relays)")}
|
||||
if "near_hops" in heard_cols:
|
||||
# The first build of schema 24 kept the near relays of each send. They are gone
|
||||
# (refer to meshterm.services.heard_by), and the table holds only derived data,
|
||||
# so it is made again. The chat fills it again from the packet log.
|
||||
conn.execute("DROP TABLE heard_relays")
|
||||
conn.execute(
|
||||
"CREATE TABLE heard_relays (message_id INTEGER PRIMARY KEY "
|
||||
"REFERENCES messages(id) ON DELETE CASCADE, paths TEXT NOT NULL)"
|
||||
)
|
||||
|
||||
stored = conn.execute("SELECT value FROM schema_meta WHERE key = 'version'").fetchone()
|
||||
if stored is not None and int(stored["value"]) < 19:
|
||||
# v18 -> v19: no private key in the run log. `config import-key` stored its key as
|
||||
|
||||
@@ -2254,72 +2254,44 @@ class Repository:
|
||||
|
||||
# -- relays that heard our channel messages ---------------------------------------
|
||||
|
||||
def set_near_hops(self, message_id: int, near: tuple[str, ...]) -> None:
|
||||
"""Keep the near relays at the time that one of our channel messages went out.
|
||||
|
||||
Thus a change of site later does not change the verdict of the message (refer to
|
||||
:mod:`~meshterm.services.heard_by`).
|
||||
|
||||
Args:
|
||||
message_id: The ``messages`` row of the sent message.
|
||||
near: The near relays, as lowercase hex.
|
||||
"""
|
||||
self._conn.execute(
|
||||
"INSERT INTO heard_relays (message_id, near_hops) VALUES (?, ?) "
|
||||
"ON CONFLICT(message_id) DO UPDATE SET near_hops = excluded.near_hops",
|
||||
(message_id, json.dumps(list(near))),
|
||||
)
|
||||
self._conn.commit()
|
||||
|
||||
def settle_heard(
|
||||
self, message_id: int, near: tuple[str, ...], paths: list[tuple[str, ...]]
|
||||
) -> None:
|
||||
def settle_heard(self, message_id: int, paths: list[tuple[str, ...]]) -> None:
|
||||
"""Store the relay paths of the copies of one message, when no more can come.
|
||||
|
||||
Refer to :mod:`~meshterm.services.heard_by`.
|
||||
|
||||
Args:
|
||||
message_id: The ``messages`` row of the sent message.
|
||||
near: The near relays that the verdict used.
|
||||
paths: The relay paths of the copies that came back. An empty list is a stored
|
||||
"no copy came back".
|
||||
"""
|
||||
self._conn.execute(
|
||||
"INSERT INTO heard_relays (message_id, near_hops, paths) VALUES (?, ?, ?) "
|
||||
"ON CONFLICT(message_id) DO UPDATE SET near_hops = excluded.near_hops, "
|
||||
"paths = excluded.paths",
|
||||
(message_id, json.dumps(list(near)), json.dumps([list(p) for p in paths])),
|
||||
"INSERT INTO heard_relays (message_id, paths) VALUES (?, ?) "
|
||||
"ON CONFLICT(message_id) DO UPDATE SET paths = excluded.paths",
|
||||
(message_id, json.dumps([list(p) for p in paths])),
|
||||
)
|
||||
self._conn.commit()
|
||||
|
||||
def heard_records(
|
||||
self, message_ids: list[int]
|
||||
) -> dict[int, tuple[tuple[str, ...] | None, list[tuple[str, ...]] | None]]:
|
||||
"""The stored near relays and relay paths of some of our channel messages.
|
||||
def heard_records(self, message_ids: list[int]) -> dict[int, list[tuple[str, ...]]]:
|
||||
"""The stored relay paths of some of our channel messages.
|
||||
|
||||
Args:
|
||||
message_ids: The ``messages`` rows to read.
|
||||
|
||||
Returns:
|
||||
For each row that has a record: the near relays (``None`` when they were not
|
||||
kept), and the relay paths (``None`` when the message is not settled yet).
|
||||
The relay paths of each row that is settled. A row that is not settled yet is
|
||||
absent.
|
||||
"""
|
||||
out: dict[int, tuple[tuple[str, ...] | None, list[tuple[str, ...]] | None]] = {}
|
||||
out: dict[int, list[tuple[str, ...]]] = {}
|
||||
ids = [int(i) for i in message_ids if i is not None]
|
||||
for start in range(0, len(ids), 500):
|
||||
part = ids[start : start + 500]
|
||||
marks = ",".join("?" * len(part))
|
||||
rows = self._conn.execute(
|
||||
f"SELECT message_id, near_hops, paths FROM heard_relays "
|
||||
f"WHERE message_id IN ({marks})",
|
||||
f"SELECT message_id, paths FROM heard_relays WHERE message_id IN ({marks})",
|
||||
part,
|
||||
).fetchall()
|
||||
for row in rows:
|
||||
near = tuple(json.loads(row["near_hops"])) if row["near_hops"] else None
|
||||
paths = (
|
||||
[tuple(p) for p in json.loads(row["paths"])]
|
||||
if row["paths"] is not None
|
||||
else None
|
||||
)
|
||||
out[int(row["message_id"])] = (near, paths)
|
||||
out[int(row["message_id"])] = [tuple(p) for p in json.loads(row["paths"])]
|
||||
return out
|
||||
|
||||
def delete_chat_history(self, peer: str | None) -> int:
|
||||
|
||||
Reference in new issue
Block a user