guard

package
v0.18.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package guard keeps one publication from going round twice.

The bridge has two sides that can put the same object on the plane: the feed, which receives an object the plane delivered, and the facade, which receives a client's submission. An application that reads from the plane and submits what it read back to its own host would publish a loop. The guard is the bounded seen-set that stops it.

Both sides mark: the feed before it acts, the facade once it has published

A client publish is never delivered by the feed, so a feed-only guard cannot recognise a re-publish of a client's own object; and the object the feed delivered is exactly the one a naive application is most likely to hand straight back. So the feed marks registry.Delivered before the engine submit: marking afterwards leaves a window in which the echo arrives before the mark lands. The facade looks an inbound object up before forwarding it and marks registry.Submitted only once the up-tunnel counts the record confirmed: the ingress host's TCP acknowledged its bytes and the connection stayed up for the grace window (see the uptunnel package). That is not end-to-end delivery: a record the ingress process read and lost before emitting it is marked all the same, and its retry is dropped as a loop until the entry expires. A mark cannot be taken back, so marking on inbound would strand every object whose publish failed for the life of the entry.

Identity is the delivered bytes, and that is safe only because nothing propagates

Ruling D4 keys on the object's ContentID as delivered: SHA-256d of the payload bytes, the plane's own object identity. The guard therefore parses nothing. It holds no BEEF reader, no go-sdk transaction import, and no subject-txid extraction, which deletes a whole class of failure the earlier design had to carry.

That is sound under ruling D3, where the engine's own propagation is switched off and the plane is the propagation. It would NOT be sufficient if an HTTPS propagation posture were ever re-enabled: an engine re-serialises what it propagates, so an echo of our own object would arrive with different bytes, therefore a different ContentID, and this guard would not catch it. Re-enabling propagation is a new decision that has to re-open this one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Key

func Key(contentID, topicID [32]byte) registry.Key

Key is SHA-256(ContentID ‖ TopicID), the shape of the key the fabric's own BEEF ingress claims an object under. ContentID here is over the OBJECT bytes on both of the bridge's paths (the facade hashes what the client sent, the feed hashes what the delivery carried), which is what makes the two directions meet; the fabric hashes the whole submission record, so its key differs in value but not in shape. Two properties follow.

The TopicID stays in the key. Keying the pair, never the bare ContentID, is what keeps a later re-submission of the same object to a NEW topic from being suppressed: sibling emissions of one object to different topics share a ContentID, so a ContentID-only key would collapse them and publish only the first. Ruling D4 replaced the object's identity (a parsed subject txid, which meant parsing BEEF to find it) with the delivered bytes' ContentID; it did not change the pairing.

The bridge's two directions agree on what "the same object" is: a delivery marks the pair the facade would look up for the echoing client, and a publish marks the pair the feed would look up for the returning delivery.

Types

type Guard

type Guard struct {
	// contains filtered or unexported fields
}

Guard is a bounded, self-rotating seen-set over object identities. It is safe for concurrent use.

func New

func New(ttl time.Duration, maxEntries int) *Guard

New returns a guard holding at most maxEntries identities for roughly ttl each. An entry survives between ttl/2 and ttl: the underlying registry rotates generations rather than tracking per-entry expiry, which is what keeps the set bounded without a sweeper goroutine.

Non-positive arguments take the registry's own defaults (30 minutes, 2^20 entries) rather than disabling the guard, because a guard that silently admits everything is worse than one sized conservatively.

func (*Guard) Lookup

func (g *Guard) Lookup(contentID, topicID [32]byte) (registry.Direction, bool)

Lookup reports the recorded direction without marking.

func (*Guard) Mark

func (g *Guard) Mark(contentID, topicID [32]byte, dir registry.Direction) (prev registry.Direction, known bool)

Mark records the object in direction dir and reports whether it was already known, and in which direction. A hit refreshes the entry's age.

Callers act on known: a facade inbound that is already Delivered is a loop and must not be published; one that is already Submitted is a duplicate publish, not a second one.

func (*Guard) Stats

func (g *Guard) Stats() registry.Stats

Stats returns a snapshot for the collector.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL