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
@@ -332,10 +332,10 @@ PREFERENCES: tuple[PrefSpec, ...] = (
|
||||
help="Wait this long for a relay of a channel message",
|
||||
group="Sending",
|
||||
value_type="int",
|
||||
# A channel message that we sent shows a spinner until a relay that is not a near
|
||||
# relay sends a copy back, or until this wait is over. Then it shows ⚠ (only near
|
||||
# relays) or ✗ (no copy). A flood goes out through the mesh in seconds, and 30 s
|
||||
# also covers a busy channel (refer to meshterm.services.heard_by).
|
||||
# A channel message that we sent shows a spinner until a repeater sends a copy
|
||||
# back, or until this wait is over. Then it shows ✗ (no copy). A repeater relays
|
||||
# in seconds, and 30 s also covers a busy channel (refer to
|
||||
# meshterm.services.heard_by).
|
||||
default=30,
|
||||
minimum=5,
|
||||
maximum=600,
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -834,17 +834,6 @@ class ChatService:
|
||||
scope=await self._sent_under(asked),
|
||||
)
|
||||
chat.row_id = self._ctx.repo.record_chat_message(chat, run_id=self._run_id)
|
||||
# The near relays of this send, so that a later change of site does not change
|
||||
# whether the message went past them (refer to meshterm.services.heard_by).
|
||||
if getattr(self._ctx, "outbound_store", None) is not None:
|
||||
try:
|
||||
from .heard_by import near_relays
|
||||
from .outbound import current_choice
|
||||
|
||||
choice = await current_choice(self._ctx)
|
||||
self._ctx.repo.set_near_hops(chat.row_id, near_relays(choice.paths))
|
||||
except Exception as exc: # noqa: BLE001 - the message went out. Only the mark is less exact
|
||||
self._ctx.log.debug("couldn't keep the near relays of a send: %s", exc)
|
||||
return chat
|
||||
|
||||
async def _sent_under(self, asked: str | None) -> str | None:
|
||||
|
||||
+40
-116
@@ -1,30 +1,23 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
"""Tell whether a channel message that we sent went past our own repeaters (issue #38).
|
||||
"""Tell whether a repeater relayed a channel message that we sent (issue #38).
|
||||
|
||||
A channel broadcast has no acknowledgement. But the device hears the relay of our
|
||||
broadcast by each repeater in range, and its RX log records each copy with the path that
|
||||
the copy went through (refer to :mod:`~meshterm.services.message_paths`). Each hop in that
|
||||
path heard the message. Thus the copies that come back are the proof that somebody heard
|
||||
it.
|
||||
path heard the message. Thus a copy that comes back is the proof that a repeater heard the
|
||||
message and sent it on.
|
||||
|
||||
A copy from a repeater next to us proves little: it shows that the message left our
|
||||
radio. The user names these repeaters already, as the first hops of the **outbound
|
||||
paths** of the active site or of a fixed device (refer to
|
||||
:mod:`~meshterm.core.outbound_store`). This module calls them the **near relays**. Each
|
||||
other hop in a copy is a relay that is not near, and it proves that the message went
|
||||
farther. A near relay is near by its identity, not by its place in a path: the path
|
||||
``UpperSalaberry → Cartierville`` has two near relays at home, and no other relay.
|
||||
Each relay counts, the repeater next to us too. A first version counted only the relays
|
||||
past the first hops of the outbound paths. In practice, nothing past them ever came back:
|
||||
each repeater relays a packet one time, and the relays farther out are too far for our
|
||||
radio to hear (JP, 2026-11-20, from 23 of 23 messages on his Public channel).
|
||||
|
||||
A managed node is not a near relay. The user can manage a repeater on the other side of
|
||||
the city, and a relay by that repeater is good proof that the message went out.
|
||||
The verdict of a message has three states, the same as the delivery of a direct message:
|
||||
|
||||
The verdict of a message has four states:
|
||||
|
||||
* :data:`WAITING`: no relay that is not near was heard yet, and the wait
|
||||
(``heard_wait_s``) is not over. The chat shows a spinner.
|
||||
* :data:`BEYOND`: one or more relays that are not near heard it. The chat shows ``✓`` and
|
||||
the number of these relays.
|
||||
* :data:`NEARBY`: after the wait, only near relays sent a copy back. The chat shows ``⚠``.
|
||||
* :data:`WAITING`: no copy came back yet, and the wait (``heard_wait_s``) is not over. The
|
||||
chat shows a spinner.
|
||||
* :data:`HEARD`: one or more relays sent a copy back. The chat shows ``✓`` and the number
|
||||
of the relays.
|
||||
* :data:`UNHEARD`: after the wait, no copy came back. The chat shows ``✗``.
|
||||
|
||||
A copy that comes back late changes the verdict, as a late acknowledgement does for a
|
||||
@@ -32,8 +25,8 @@ direct message. After the match window of the packet log
|
||||
(:data:`~meshterm.services.message_paths.CHANNEL_WINDOW`), nothing can change it, and
|
||||
MeshTerm stores the paths, so that the next visit does not decrypt the log again.
|
||||
|
||||
Two limits stay. MeshTerm sees only the relays that our radio hears, so a relay farther
|
||||
away than that never shows. And MeshTerm must be connected while the copies come back.
|
||||
Two limits stay. MeshTerm sees only the relays that our radio hears. And MeshTerm must be
|
||||
connected while the copies come back.
|
||||
|
||||
Nothing in this module transmits. It is a read-model over the repository.
|
||||
"""
|
||||
@@ -55,8 +48,7 @@ if TYPE_CHECKING:
|
||||
|
||||
#: The verdict states (refer to the module docstring).
|
||||
WAITING = "waiting"
|
||||
BEYOND = "beyond"
|
||||
NEARBY = "nearby"
|
||||
HEARD = "heard"
|
||||
UNHEARD = "unheard"
|
||||
|
||||
#: The number of messages that :meth:`HeardTracker.fill` examines before each yield to the
|
||||
@@ -72,52 +64,17 @@ class HeardBy:
|
||||
"""The verdict on one channel message that we sent.
|
||||
|
||||
Attributes:
|
||||
state: :data:`WAITING`, :data:`BEYOND`, :data:`NEARBY`, or :data:`UNHEARD`.
|
||||
beyond: The hashes of the relays that are not near, in the order first heard.
|
||||
Each one heard the message.
|
||||
via: The near relays that started the copies that went farther, in the order first
|
||||
heard. Thus the user sees which of the repeaters at home carried the message
|
||||
out.
|
||||
state: :data:`WAITING`, :data:`HEARD`, or :data:`UNHEARD`.
|
||||
relays: The hashes of the relays in the copies, in the order first heard. Each one
|
||||
heard the message.
|
||||
copies: The number of copies that came back.
|
||||
"""
|
||||
|
||||
state: str
|
||||
beyond: tuple[str, ...] = ()
|
||||
via: tuple[str, ...] = ()
|
||||
relays: tuple[str, ...] = ()
|
||||
copies: int = 0
|
||||
|
||||
|
||||
def near_relays(paths: Iterable[Sequence[str]]) -> tuple[str, ...]:
|
||||
"""The first hop of each outbound path, without duplicates, in order.
|
||||
|
||||
Args:
|
||||
paths: The outbound paths that apply
|
||||
(:attr:`~meshterm.core.outbound_store.OutboundChoice.paths`).
|
||||
|
||||
Returns:
|
||||
The near relays, as lowercase hex.
|
||||
"""
|
||||
out: list[str] = []
|
||||
for path in paths:
|
||||
if path:
|
||||
hop = str(path[0]).lower()
|
||||
if hop not in out:
|
||||
out.append(hop)
|
||||
return tuple(out)
|
||||
|
||||
|
||||
def is_near(hop: str, near: Sequence[str]) -> bool:
|
||||
"""Whether a hop of a path is one of the near relays.
|
||||
|
||||
A hop in a packet path is a hash: one to three bytes of the key. A near relay is a
|
||||
longer key prefix. The hop matches when one starts with the other. When two
|
||||
repeaters share a one-byte hash, a relay that is not near can match a near relay. Then
|
||||
the count is too low, but it never claims a relay that did not occur.
|
||||
"""
|
||||
hop = hop.lower()
|
||||
return bool(hop) and any(n.startswith(hop) or hop.startswith(n) for n in near)
|
||||
|
||||
|
||||
def relay_paths(arrivals: Iterable[Arrival]) -> list[RelayPath]:
|
||||
"""The paths of the copies that tell which relays heard the message.
|
||||
|
||||
@@ -128,49 +85,35 @@ def relay_paths(arrivals: Iterable[Arrival]) -> list[RelayPath]:
|
||||
return [a.hops for a in arrivals if a.hops and a.route_known]
|
||||
|
||||
|
||||
def judge(
|
||||
paths: Sequence[RelayPath], near: Sequence[str], *, age_s: float, wait_s: float
|
||||
) -> HeardBy:
|
||||
def judge(paths: Sequence[RelayPath], *, age_s: float, wait_s: float) -> HeardBy:
|
||||
"""The verdict on a message from the paths of its copies.
|
||||
|
||||
Args:
|
||||
paths: The relay paths of the copies that came back, in the order heard.
|
||||
near: The near relays at the time of the send.
|
||||
age_s: The time since the send, in seconds.
|
||||
wait_s: The wait before "no relay" becomes the verdict (``heard_wait_s``).
|
||||
|
||||
Returns:
|
||||
The verdict.
|
||||
"""
|
||||
beyond: list[str] = []
|
||||
via: list[str] = []
|
||||
relays: list[str] = []
|
||||
for path in paths:
|
||||
far = [hop.lower() for hop in path if not is_near(hop, near)]
|
||||
for hop in far:
|
||||
if hop not in beyond:
|
||||
beyond.append(hop)
|
||||
if far:
|
||||
for hop in path:
|
||||
if hop.lower() == far[0]:
|
||||
break
|
||||
if hop.lower() not in via:
|
||||
via.append(hop.lower())
|
||||
if beyond:
|
||||
state = BEYOND
|
||||
for hop in path:
|
||||
if hop.lower() not in relays:
|
||||
relays.append(hop.lower())
|
||||
if relays:
|
||||
state = HEARD
|
||||
elif age_s < wait_s:
|
||||
state = WAITING
|
||||
elif paths:
|
||||
state = NEARBY
|
||||
else:
|
||||
state = UNHEARD
|
||||
return HeardBy(state, tuple(beyond), tuple(via), len(paths))
|
||||
return HeardBy(state, tuple(relays), len(paths))
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class _Record:
|
||||
"""What the tracker knows about one message: its near relays, and the copies so far."""
|
||||
"""What the tracker knows about one message: the copies so far, and if more can come."""
|
||||
|
||||
near: tuple[str, ...]
|
||||
paths: list[RelayPath] = field(default_factory=list)
|
||||
settled: bool = False
|
||||
|
||||
@@ -191,7 +134,6 @@ class HeardTracker:
|
||||
*,
|
||||
channel_name: str,
|
||||
secret: bytes | None,
|
||||
near_now: tuple[str, ...],
|
||||
wait_s: Callable[[], float],
|
||||
clock: Callable[[], datetime] = utcnow,
|
||||
) -> None:
|
||||
@@ -202,15 +144,12 @@ class HeardTracker:
|
||||
channel_name: The name of the channel (for the decryption).
|
||||
secret: The key of the channel. With no key, nothing can be matched, and each
|
||||
verdict is ``None``.
|
||||
near_now: The near relays that apply now. A message sent before MeshTerm kept
|
||||
the near relays of each send uses these.
|
||||
wait_s: Gives the ``heard_wait_s`` preference, read at each verdict.
|
||||
clock: Gives the current time (a fixed clock in the tests).
|
||||
"""
|
||||
self._repo = repo
|
||||
self._channel_name = channel_name
|
||||
self._secret = secret
|
||||
self._near_now = near_now
|
||||
self._wait_s = wait_s
|
||||
self._clock = clock
|
||||
self._records: dict[int, _Record] = {}
|
||||
@@ -238,12 +177,12 @@ class HeardTracker:
|
||||
record = self._records.get(message.row_id) # type: ignore[arg-type]
|
||||
if record is None:
|
||||
return None
|
||||
return judge(record.paths, record.near, age_s=self._age_s(message), wait_s=self._wait_s())
|
||||
return judge(record.paths, age_s=self._age_s(message), wait_s=self._wait_s())
|
||||
|
||||
def note_sent(self, message: ChatMessage) -> None:
|
||||
"""Start the verdict of a message that was sent while the screen is open."""
|
||||
if self._ours(message):
|
||||
self._records[message.row_id] = _Record(near=self._near_now) # type: ignore[index]
|
||||
self._records[message.row_id] = _Record() # type: ignore[index]
|
||||
self._revision += 1
|
||||
|
||||
async def fill(self, messages: Sequence[ChatMessage]) -> None:
|
||||
@@ -258,19 +197,14 @@ class HeardTracker:
|
||||
ours = [m for m in messages if self._ours(m)]
|
||||
stored = self._repo.heard_records([m.row_id for m in ours]) # type: ignore[misc]
|
||||
for message in ours:
|
||||
near, paths = stored.get(message.row_id, (None, None)) # type: ignore[arg-type]
|
||||
paths = stored.get(message.row_id) # type: ignore[arg-type]
|
||||
if paths is not None:
|
||||
self._records[message.row_id] = _Record( # type: ignore[index]
|
||||
near=near if near is not None else self._near_now,
|
||||
paths=list(paths),
|
||||
settled=True,
|
||||
)
|
||||
self._records[message.row_id] = _Record(paths=list(paths), settled=True) # type: ignore[index]
|
||||
self._revision += 1
|
||||
todo = [m for m in reversed(ours) if m.row_id not in self._records]
|
||||
for start in range(0, len(todo), _CHUNK):
|
||||
for message in todo[start : start + _CHUNK]:
|
||||
near, _paths = stored.get(message.row_id, (None, None)) # type: ignore[arg-type]
|
||||
self._examine(message, near if near is not None else self._near_now)
|
||||
self._examine(message)
|
||||
self._revision += 1
|
||||
await asyncio.sleep(0)
|
||||
|
||||
@@ -291,7 +225,7 @@ class HeardTracker:
|
||||
if record is None or record.settled:
|
||||
continue
|
||||
before = list(record.paths)
|
||||
self._examine(message, record.near)
|
||||
self._examine(message)
|
||||
changed = changed or self._records[message.row_id].paths != before # type: ignore[index]
|
||||
if changed:
|
||||
self._revision += 1
|
||||
@@ -301,7 +235,7 @@ class HeardTracker:
|
||||
"""Whether one of the messages shows the spinner now."""
|
||||
return any((v := self.verdict(m)) is not None and v.state == WAITING for m in messages)
|
||||
|
||||
def _examine(self, message: ChatMessage, near: tuple[str, ...]) -> None:
|
||||
def _examine(self, message: ChatMessage) -> None:
|
||||
"""Match the copies of one message in the packet log, and settle it if it is old."""
|
||||
assert self._secret is not None and message.row_id is not None
|
||||
arrivals = channel_arrivals(
|
||||
@@ -309,19 +243,18 @@ class HeardTracker:
|
||||
)
|
||||
paths = relay_paths(arrivals)
|
||||
settled = self._age_s(message) > CHANNEL_WINDOW.total_seconds()
|
||||
self._records[message.row_id] = _Record(near=near, paths=paths, settled=settled)
|
||||
self._records[message.row_id] = _Record(paths=paths, settled=settled)
|
||||
if settled:
|
||||
self._repo.settle_heard(message.row_id, near, paths)
|
||||
self._repo.settle_heard(message.row_id, paths)
|
||||
|
||||
|
||||
async def make_tracker(
|
||||
def make_tracker(
|
||||
ctx: AppContext, *, channel_name: str, secret: bytes | None
|
||||
) -> HeardTracker | None:
|
||||
"""A tracker for one channel, with the near relays that apply now.
|
||||
"""A tracker for one channel.
|
||||
|
||||
Args:
|
||||
ctx: The shared application context (the repository, the outbound paths, and the
|
||||
preferences).
|
||||
ctx: The shared application context (the repository and the preferences).
|
||||
channel_name: The name of the channel.
|
||||
secret: The key of the channel. With no key, there is no tracker.
|
||||
|
||||
@@ -330,18 +263,9 @@ async def make_tracker(
|
||||
"""
|
||||
if not secret:
|
||||
return None
|
||||
from .outbound import current_choice
|
||||
|
||||
near: tuple[str, ...] = ()
|
||||
if getattr(ctx, "outbound_store", None) is not None:
|
||||
try:
|
||||
near = near_relays((await current_choice(ctx)).paths)
|
||||
except Exception: # noqa: BLE001 - with no outbound paths, each relay counts
|
||||
near = ()
|
||||
return HeardTracker(
|
||||
ctx.repo,
|
||||
channel_name=channel_name,
|
||||
secret=secret,
|
||||
near_now=near,
|
||||
wait_s=lambda: float(ctx.preferences.heard_wait_s),
|
||||
)
|
||||
+11
-14
@@ -1324,7 +1324,6 @@ def _message_columns(*, author_lane: bool = False, heard_lane: bool = False) ->
|
||||
fields.hidden("acked"),
|
||||
fields.hidden("heard"),
|
||||
fields.hidden("heard_by"),
|
||||
fields.hidden("heard_via"),
|
||||
)
|
||||
|
||||
|
||||
@@ -1373,7 +1372,7 @@ def _author_ref(author: str, name_of: NodeResolver | None) -> NodeRef:
|
||||
async def _channel_verdicts(
|
||||
ctx: AppContext, channel: int, messages: list[ChatMessage]
|
||||
) -> Callable[[ChatMessage], HeardBy | None] | None:
|
||||
"""The verdicts on our messages in a channel: did a relay past the near relays hear them?
|
||||
"""The verdicts on our messages in a channel: did a repeater send a copy back?
|
||||
|
||||
Refer to :mod:`~meshterm.services.heard_by`. With no key for the slot, there is no
|
||||
verdict, and the column is absent on each row.
|
||||
@@ -1388,7 +1387,7 @@ async def _channel_verdicts(
|
||||
name = str((payload or {}).get("channel_name") or f"#{channel}")
|
||||
except Exception: # noqa: BLE001 - no key, no verdict. The history still prints
|
||||
return None
|
||||
tracker = await make_tracker(ctx, channel_name=name, secret=secret)
|
||||
tracker = make_tracker(ctx, channel_name=name, secret=secret)
|
||||
if tracker is None:
|
||||
return None
|
||||
await tracker.fill(messages)
|
||||
@@ -1414,7 +1413,7 @@ def _transcript(
|
||||
me: Our node, the author of our own posts in a room.
|
||||
heard: Gives the verdict on each of our channel messages (refer to
|
||||
:mod:`~meshterm.services.heard_by`). With it, the plain face has a ``HEARD``
|
||||
lane. The document always has ``heard``, ``heard_by``, and ``heard_via``.
|
||||
lane. The document always has ``heard`` and ``heard_by``.
|
||||
"""
|
||||
from ..ui.report import Listing
|
||||
|
||||
@@ -1449,8 +1448,7 @@ def _transcript(
|
||||
"text": message.text,
|
||||
"acked": message.acked,
|
||||
"heard": verdict.state if verdict is not None else None,
|
||||
"heard_by": list(verdict.beyond) if verdict is not None else None,
|
||||
"heard_via": list(verdict.via) if verdict is not None else None,
|
||||
"heard_by": list(verdict.relays) if verdict is not None else None,
|
||||
"heard_cell": _heard_cell(verdict),
|
||||
}
|
||||
)
|
||||
@@ -1464,20 +1462,19 @@ def _transcript(
|
||||
|
||||
|
||||
def _heard_cell(verdict: HeardBy | None) -> str:
|
||||
"""The plain ``HEARD`` cell: the number of relays past the near relays, or a word.
|
||||
"""The plain ``HEARD`` cell: the number of relays that sent a copy back, or a word.
|
||||
|
||||
``near`` is a message that only the near relays sent back, ``none`` is one that no
|
||||
relay sent back, and ``wait`` is one that is still in its wait. A message that is not
|
||||
ours has no verdict (``-``).
|
||||
``none`` is a message that no repeater sent back, and ``wait`` is one that is still in
|
||||
its wait. A message that is not ours has no verdict (``-``).
|
||||
"""
|
||||
from ..services.heard_by import BEYOND, NEARBY, UNHEARD, WAITING
|
||||
from ..services.heard_by import HEARD, UNHEARD, WAITING
|
||||
from ..ui import script
|
||||
|
||||
if verdict is None:
|
||||
return script.NONE
|
||||
if verdict.state == BEYOND:
|
||||
return str(len(verdict.beyond))
|
||||
return {NEARBY: "near", UNHEARD: "none", WAITING: "wait"}.get(verdict.state, script.NONE)
|
||||
if verdict.state == HEARD:
|
||||
return str(len(verdict.relays))
|
||||
return {UNHEARD: "none", WAITING: "wait"}.get(verdict.state, script.NONE)
|
||||
|
||||
|
||||
def _live_messages() -> Listing:
|
||||
|
||||
+13
-51
@@ -40,7 +40,7 @@ from ..core.models import (
|
||||
)
|
||||
from ..core.regions import WILDCARD
|
||||
from ..platforms import Platform, on_platform
|
||||
from ..services.heard_by import BEYOND, NEARBY, UNHEARD, WAITING, HeardBy, HeardTracker
|
||||
from ..services.heard_by import HEARD, UNHEARD, WAITING, HeardBy, HeardTracker
|
||||
from . import pixelart
|
||||
from .compose import MentionEditor
|
||||
from .pathline import PATH_INK, PathHop
|
||||
@@ -88,9 +88,6 @@ _CORRECTED = ("?", "warn")
|
||||
#: animated spinner instead (refer to :meth:`ChatScreen._delivery_glyph`).
|
||||
_DELIVERED = ("✓", "ok")
|
||||
_FAILED = ("✗", "err")
|
||||
#: The mark of our channel message that only the near relays sent back: it left our radio,
|
||||
#: and nothing proves that it went farther (refer to :mod:`~meshterm.services.heard_by`).
|
||||
_NEAR_ONLY = ("⚠", "warn")
|
||||
#: The time that the chat waits after a channel packet before it looks for copies of our
|
||||
#: messages in the packet log. The recorder stores each packet in the background.
|
||||
_HEARD_SETTLE_S = 1.0
|
||||
@@ -337,8 +334,8 @@ class ChatScreen(Screen):
|
||||
resend_flood: Like ``resend``, but it first forgets the route that the device
|
||||
learned to the contact, so that the retry floods (direct chats only).
|
||||
With ``None``, ^R always retries on the route, as it did before.
|
||||
heard: The verdicts on our own channel messages: whether a relay that is not a
|
||||
near relay sent a copy back (refer to :mod:`~meshterm.services.heard_by`).
|
||||
heard: The verdicts on our own channel messages: whether a repeater sent a copy
|
||||
back (refer to :mod:`~meshterm.services.heard_by`).
|
||||
With ``None`` (a direct chat, or a channel with no key), our channel
|
||||
messages show no mark.
|
||||
hop_name: Gives the name of a relay from its hash, for the note under a
|
||||
@@ -1132,42 +1129,33 @@ class ChatScreen(Screen):
|
||||
heard = self._heard(message)
|
||||
return (
|
||||
message.acked,
|
||||
None if heard is None else (heard.state, heard.beyond, heard.via),
|
||||
None if heard is None else (heard.state, heard.relays),
|
||||
)
|
||||
|
||||
def _heard_mark(self, heard: HeardBy) -> Text:
|
||||
"""The mark at the end of our channel message: the marks of a direct message.
|
||||
|
||||
The spinner turns while no relay that is not near sent a copy back, until the
|
||||
``heard_wait_s`` wait is over. Then ``✓`` and the number of these relays, ``⚠`` for
|
||||
a message that only the near relays sent back, or ``✗`` for no copy at all.
|
||||
The spinner turns while no repeater sent a copy back, until the ``heard_wait_s``
|
||||
wait is over. Then ``✓`` and the number of the relays, or ``✗`` for no copy at all.
|
||||
"""
|
||||
if heard.state == WAITING:
|
||||
return self._spinner.text()
|
||||
if heard.state == BEYOND:
|
||||
if heard.state == HEARD:
|
||||
glyph, style = _DELIVERED
|
||||
return Text(f"{glyph} {len(heard.beyond)}", style=style)
|
||||
if heard.state == NEARBY:
|
||||
return Text(_NEAR_ONLY[0], style=_NEAR_ONLY[1])
|
||||
return Text(f"{glyph} {len(heard.relays)}", style=style)
|
||||
glyph, style = _FAILED
|
||||
return Text(glyph, style=style)
|
||||
|
||||
def _heard_note(self, heard: HeardBy) -> Text | None:
|
||||
"""The line under a selected channel message of ours: which relays heard it."""
|
||||
note = Text()
|
||||
if heard.state == BEYOND:
|
||||
names = ", ".join(self._hop_name(hop) for hop in heard.beyond)
|
||||
if heard.state == HEARD:
|
||||
names = ", ".join(self._hop_name(hop) for hop in heard.relays)
|
||||
note.append(f"{_DELIVERED[0]} ", style=_DELIVERED[1])
|
||||
note.append(f"heard by {names}", style="muted")
|
||||
if heard.via:
|
||||
via = ", ".join(self._hop_name(hop) for hop in heard.via)
|
||||
note.append(f" · via {via}", style="muted")
|
||||
elif heard.state == NEARBY:
|
||||
note.append(f"{_NEAR_ONLY[0]} ", style=_NEAR_ONLY[1])
|
||||
note.append("only your near relays sent it back", style="muted")
|
||||
note.append(f"relayed by {names}", style="muted")
|
||||
elif heard.state == UNHEARD:
|
||||
note.append(f"{_FAILED[0]} ", style=_FAILED[1])
|
||||
note.append("no relay sent it back", style="muted")
|
||||
note.append("no repeater sent it back", style="muted")
|
||||
else:
|
||||
return None
|
||||
return note
|
||||
@@ -2227,7 +2215,7 @@ async def _make_heard_tracker(
|
||||
from ..services.heard_by import make_tracker
|
||||
|
||||
secret = await _channel_secret(conversation, device)
|
||||
tracker = await make_tracker(ctx, channel_name=conversation.label, secret=secret)
|
||||
tracker = make_tracker(ctx, channel_name=conversation.label, secret=secret)
|
||||
if tracker is None:
|
||||
return None, None
|
||||
stored_names, _named_at = ctx.repo.node_names_with_times()
|
||||
@@ -2235,30 +2223,6 @@ async def _make_heard_tracker(
|
||||
return tracker, lambda hop: resolve(hop) or hop
|
||||
|
||||
|
||||
async def _past_near_atom(ctx: AppContext, message: ChatMessage, arrivals: list) -> str:
|
||||
"""The atom of the paths dialog that counts the relays past our near relays.
|
||||
|
||||
The near relays are the ones kept with the send, or the ones that apply now for a
|
||||
message sent before MeshTerm kept them (refer to :mod:`~meshterm.services.heard_by`).
|
||||
"""
|
||||
from ..services.heard_by import judge, near_relays, relay_paths
|
||||
from ..services.outbound import current_choice
|
||||
|
||||
near: tuple[str, ...] | None = None
|
||||
if message.row_id is not None:
|
||||
near, _paths = ctx.repo.heard_records([message.row_id]).get(message.row_id, (None, None))
|
||||
if near is None and getattr(ctx, "outbound_store", None) is not None:
|
||||
try:
|
||||
near = near_relays((await current_choice(ctx)).paths)
|
||||
except Exception: # noqa: BLE001 - with no outbound paths, each relay counts
|
||||
near = None
|
||||
heard = judge(relay_paths(arrivals), near or (), age_s=float("inf"), wait_s=0.0)
|
||||
count = len(heard.beyond)
|
||||
if not near:
|
||||
return f" · {count} relay{'s' if count != 1 else ''}"
|
||||
return f" · {count} past your near relay{'s' if len(near) != 1 else ''}"
|
||||
|
||||
|
||||
async def _with_restore(ctx: AppContext, attempt: Callable[[], Awaitable[Any]]) -> Any:
|
||||
"""Run a direct send. If the device forgot the contact, offer to restore it, then retry.
|
||||
|
||||
@@ -2552,8 +2516,6 @@ async def _make_paths_presenter(
|
||||
if arrivals
|
||||
else "no copies in the packet log"
|
||||
)
|
||||
if arrivals and message.outbound:
|
||||
summary += await _past_near_atom(ctx, message, arrivals)
|
||||
elif conversation.is_channel:
|
||||
await session.scroll(
|
||||
Text(
|
||||
|
||||
Reference in new issue
Block a user