discovery

package
v0.1.0-alpha.5 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package discovery provides interest-scoped service announcements over GossipSub. Providers announce routing keys (model IDs, tool names) on per-key topics only while those topics have subscribers; consumers subscribe only for keys they actively use. Cost therefore scales with interest, not mesh size. Announcements are routing hints authenticated by the pubsub layer's message signing — never authorization inputs.

Index

Constants

View Source
const (
	// DefaultAnnounceInterval is how often a provider publishes on topics
	// with subscribers; each tick is jittered ±20%.
	DefaultAnnounceInterval = 10 * time.Second
	// DefaultInterestTTL is how long a consumer stays subscribed to a key's
	// topic after the last Ensure call for it.
	DefaultInterestTTL = 5 * time.Minute
	// DefaultStaleAfter is the age beyond which a provider entry is no
	// longer returned by Providers.
	DefaultStaleAfter = 30 * time.Second
	// DefaultMaxProviders bounds the consumer-side provider table.
	DefaultMaxProviders = 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Announcement

type Announcement struct {
	Type   api.ServiceType
	Name   string
	Keys   []string
	Labels map[string]string
	Load   Load
}

Announcement is one service's advertised state, fed by the node.

type Discovery

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

Discovery is the node-facing handle: it announces local services (provider role) and maintains an interest-scoped view of remote providers (consumer role) over a shared set of gossip topics.

func New

func New(ps *pubsub.PubSub, self peer.ID, opts ...Option) *Discovery

func (*Discovery) Ensure

func (d *Discovery) Ensure(t api.ServiceType, key string)

Ensure registers interest in a routing key: it subscribes to the key's topic (if not already) and refreshes the interest TTL. Safe to call on every request for the key.

func (*Discovery) PeerLabels

func (d *Discovery) PeerLabels(peerID string) map[string]string

PeerLabels returns the labels last observed for a peer, if any. Labels are node-level claims (e.g. region), so any fresh entry of the peer suffices.

func (*Discovery) Providers

func (d *Discovery) Providers(t api.ServiceType, key string) []Provider

Providers returns the fresh, non-self providers observed for a key.

func (*Discovery) Start

func (d *Discovery) Start(ctx context.Context, src SourceFunc)

Start runs the announce and interest-janitor loops until ctx is done. src may be nil for consume-only nodes.

type Load

type Load struct {
	ActiveRequests uint32
	LatencyEWMAMs  float64
}

Load carries a provider's runtime hints. Zero values mean unknown.

type Option

type Option func(*Discovery)

Option tweaks Discovery timing/bounds (used by tests).

func WithIntervals

func WithIntervals(announce, interestTTL, staleAfter time.Duration) Option

func WithMaxProviders

func WithMaxProviders(n int) Option

type Provider

type Provider struct {
	PeerID   string
	Type     api.ServiceType
	Service  string
	Keys     []string
	Labels   map[string]string
	Load     Load
	LastSeen time.Time
}

Provider is a remote service observed via gossip.

func (Provider) ServesKey

func (p Provider) ServesKey(key string) bool

ServesKey reports whether the provider advertised the given routing key.

type SourceFunc

type SourceFunc func() []Announcement

SourceFunc supplies the current local announcements on each tick.

Jump to

Keyboard shortcuts

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