CultNet: refuse hop edges whose citer is a variant; withdraw a refused hop subscription
An edge carries the reference payload of its citer's resolved document, and the citer is never a selected row under `cited`, so a variant citer slipped past the selected-row refusal. Edges are now checked by the same rule (typed NotSupportedException naming the variant), on the paged and the whole-set paths. Reconcile refused a hop subscriber whose selection selected a variant without withdrawing it, so it was told again on every store change. It withdraws as the subscribe path does. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
282e337c2c
commit
a0baa542d0
3 changed files with 113 additions and 13 deletions
|
|
@ -358,8 +358,10 @@ namespace GameCult.Networking
|
|||
}
|
||||
catch (NotSupportedException refusal)
|
||||
{
|
||||
// Q6: the selection selects a variant, which CultNet cannot carry. This subscriber is told, by key, and keeps what
|
||||
// it was delivered; a change never throws out of the change handler.
|
||||
// Q6: the selection selects a variant, which CultNet cannot carry. Refused as the subscribe path refuses it: the
|
||||
// subscription is withdrawn, so the peer is told once, not once per store change; a change never throws out of
|
||||
// the change handler.
|
||||
Withdraw(key, sendRemovals: false, forgetRequest: true);
|
||||
key.Peer.SendCultNet(new CultNetErrorMessage { Error = refusal.Message });
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -397,7 +397,7 @@ namespace GameCult.Networking
|
|||
entry.Descriptor, entry.Key, entry.Document, ordinalOf(entry.Descriptor.SchemaId, entry.Key), entry.StoredAt))
|
||||
.ToArray();
|
||||
var full = CultNetSelectionEvaluator.EvaluateAll(_documents, rows, selection);
|
||||
RefuseSelectedVariants(entries, full.Ordered);
|
||||
RefuseVariants(entries, full.Ordered.Select(row => row.Key));
|
||||
// R-Q: a page's asOf is exact only when every matched row is committed through one shard's
|
||||
// log - a caller that knows about shards (CultNetDatabaseServer) supplies shardIdOf; one
|
||||
// that does not (the raw v0/shard-scoped rowFilter paths, which are already bounded to a
|
||||
|
|
@ -417,6 +417,7 @@ namespace GameCult.Networking
|
|||
}
|
||||
|
||||
var evaluation = CultNetSelectionEvaluator.Page(full, selection, asOf, cursorKey);
|
||||
RefuseVariants(entries, evaluation.Edges.Select(edge => edge.From.Key));
|
||||
var records = evaluation.Rows.Select(row => ToRawRecord(row, options)).ToArray();
|
||||
var wantDocument = selection.Projection == CultNetSelectionProjections.Document;
|
||||
|
||||
|
|
@ -494,12 +495,13 @@ namespace GameCult.Networking
|
|||
.ToArray();
|
||||
|
||||
var full = CultNetSelectionEvaluator.EvaluateAll(_documents, rows, selection);
|
||||
RefuseSelectedVariants(entries, full.Ordered);
|
||||
RefuseVariants(entries, full.Ordered.Select(row => row.Key));
|
||||
var records = full.Ordered.Select(row => ToRawRecord(row, options)).ToArray();
|
||||
var wantDocument = selection.Projection == CultNetSelectionProjections.Document;
|
||||
var edges = selection.HasHop
|
||||
? CultNetSelectionEvaluator.EdgesFor(full.Ordered, full).Select(edge => ToEdge(edge, wantDocument)).ToArray()
|
||||
: null;
|
||||
var hopEdges = selection.HasHop ? CultNetSelectionEvaluator.EdgesFor(full.Ordered, full) : null;
|
||||
if (hopEdges != null)
|
||||
RefuseVariants(entries, hopEdges.Select(edge => edge.From.Key));
|
||||
var edges = hopEdges?.Select(edge => ToEdge(edge, wantDocument)).ToArray();
|
||||
|
||||
return new CultNetSelectionPage
|
||||
{
|
||||
|
|
@ -554,15 +556,17 @@ namespace GameCult.Networking
|
|||
}
|
||||
|
||||
// CultNet carries no variant deltas yet, and a resolved view sent as a plain record would be a lie about the store.
|
||||
// The refusal follows the selection: a variant is refused only when the selection selects it, never for existing.
|
||||
private static void RefuseSelectedVariants(IReadOnlyList<CultStoredDocument> entries, IReadOnlyList<CultNetSelectionEvaluator.Row> selected)
|
||||
// The refusal follows the selection: a variant is refused only when the selection selects it, never for existing. An
|
||||
// edge carries its citer's reference payload, read from the citer's resolved document, so a variant citing is selected
|
||||
// by the selection's hop exactly as a variant row is.
|
||||
private static void RefuseVariants(IReadOnlyList<CultStoredDocument> entries, IEnumerable<CultRecordKey> selected)
|
||||
{
|
||||
if (selected.Count == 0 || !entries.Any(entry => entry.Variant != null))
|
||||
if (!entries.Any(entry => entry.Variant != null))
|
||||
return;
|
||||
var variants = entries.Where(entry => entry.Variant != null).ToDictionary(entry => entry.Key.Value, StringComparer.Ordinal);
|
||||
foreach (var row in selected)
|
||||
foreach (var key in selected)
|
||||
{
|
||||
if (variants.TryGetValue(row.Key.Value, out var variant))
|
||||
if (variants.TryGetValue(key.Value, out var variant))
|
||||
throw VariantRefusal(variant);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue