Files
MrAlders0n f9a204e35e fix(polling): close the gaps review found in foreign claims
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.
2026-11-28 20:49:32 -05:00

44 lines
1.7 KiB
Go

// Copyright 2026 Beacon Contributors
// SPDX-License-Identifier: AGPL-3.0-or-later
package polling
import "time"
// StoredClaim is what the store holds of an observer's claim, of this server's own or foreign.
type StoredClaim struct {
Foreign bool
ClaimedAt time.Time
ReceivedAt time.Time
Signed bool
}
// AdmitClaim decides whether a claim may replace what the observer has stored, own and foreign together. The
// store calls it under the observer's seat lock, so two claims arriving at once are judged one after the other.
//
// - A claim must be newer than the stored one of its own kind, and than a stored one of the other kind. The one
// exception is a claim of this server's own with the same timestamp as the stored foreign one: the same claim
// arrived by two routes, and the route that makes it this server's own wins.
// - A claim that follows a different one within ClaimMinInterval is refused whichever kind either is, so
// changing sides does not get an observer past the spacing.
// - With c.SignedSince set, an unsigned claim is refused while a signed one received after it is stored: an
// observer that signs does not stop, so the signature was taken off on the way.
func AdmitClaim(c Claim, own bool, receivedAt time.Time, stored []StoredClaim) bool {
for _, r := range stored {
if !c.SignedSince.IsZero() && !c.Signed && r.Signed && r.ReceivedAt.After(c.SignedSince) {
return false
}
sameClaimOtherRoute := own && r.Foreign && c.Timestamp.Equal(r.ClaimedAt)
if sameClaimOtherRoute {
continue
}
if !c.Timestamp.After(r.ClaimedAt) {
return false
}
if r.ReceivedAt.After(receivedAt.Add(-ClaimMinInterval)) {
return false
}
}
return true
}