labeler

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package labeler provides a labeler subscription client for the hold service.

The hold subscribes to one labeler and mirrors active takedowns into a local cache (in-memory + SQLite). On takedown receipt the hold purges layer, scan, and image-config records for the affected manifest. The cache is consulted by the GC to gate blob deletion: while a takedown is within its grace window, the manifest's blob digests stay in the GC's referenced set so reversal can still restore them.

Index

Constants

View Source
const TakedownLabelValue = "!takedown"

TakedownLabelValue is the label value the hold treats as a takedown trigger. Mirrors what pkg/labeler/takedown.go emits.

Variables

This section is empty.

Functions

func IsExpired

func IsExpired(cts time.Time, graceWindow time.Duration) bool

IsExpired returns true if cts is older than the grace window.

Types

type Cache

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

Cache holds active takedown URIs and their creation timestamps. It is thread-safe and persists state to SQLite so the hold can answer takedown queries before the labeler subscription has caught up after a restart.

func NewCache

func NewCache(db *sql.DB) (*Cache, error)

NewCache opens (or creates) the takedown_cache and labeler_cursor tables on the given DB and loads any existing entries into memory.

func (*Cache) GetCursor

func (c *Cache) GetCursor(labelerDID string) (int64, error)

GetCursor returns the last persisted cursor for a labeler DID (0 if none).

func (*Cache) IsTakenDown

func (c *Cache) IsTakenDown(manifestURI string) (cts time.Time, ok bool)

IsTakenDown reports whether a manifest URI is taken down, either directly (per-manifest takedown) or via a user-level takedown on its DID. The returned timestamp is the earliest cts that applies (i.e. the longest-standing takedown), which is what the grace check should compare against.

func (*Cache) Negate

func (c *Cache) Negate(uri string) error

Negate removes a takedown entry. Idempotent.

func (*Cache) Set

func (c *Cache) Set(uri, src string, cts time.Time) error

Set records a positive takedown for uri at cts. Idempotent: re-applying updates the timestamp (newer takedowns win).

func (*Cache) SetCursor

func (c *Cache) SetCursor(labelerDID string, cursor int64) error

SetCursor persists the cursor for a labeler DID.

type PurgeOutcome

type PurgeOutcome struct {
	LayersDeleted      int
	ScanDeleted        bool
	ImageConfigDeleted bool
}

PurgeOutcome mirrors pds.PurgeResult without creating an import cycle.

type Purger

type Purger interface {
	PurgeManifestRecords(ctx context.Context, manifestURI string) (PurgeOutcome, error)
	PurgeUserManifests(ctx context.Context, userDID string) (PurgeOutcome, error)
}

Purger is the subset of HoldPDS the subscriber needs to act on takedowns. Defined as an interface so tests can substitute a stub without standing up a full PDS, and to avoid an import cycle with pkg/hold/pds.

type Subscriber

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

Subscriber connects to a labeler's subscribeLabels endpoint, mirrors takedowns into the local cache, and triggers record purges on the hold.

func NewSubscriber

func NewSubscriber(labelerDID string, cache *Cache, purger Purger) *Subscriber

NewSubscriber builds a subscriber for the given labeler DID (did:plc or did:web). The websocket endpoint is resolved on each (re)connect through the shared identity directory's #atproto_labeler service entry, so the labeler can move (or fix a misconfigured endpoint) without clients redeploying.

func (*Subscriber) LabelerDID

func (s *Subscriber) LabelerDID() string

LabelerDID returns the DID derived from the labeler URL. Useful for the caller to log the trusted source.

func (*Subscriber) Start

func (s *Subscriber) Start()

Start runs the subscription loop in a goroutine.

func (*Subscriber) Stop

func (s *Subscriber) Stop()

Stop signals the subscriber to shut down. Safe to call once.

Jump to

Keyboard shortcuts

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