indexer

package
v0.0.0-...-904bf0a Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContentInfo

type ContentInfo struct {
	CID       cid.Cid
	Protocols []Protocol
	AddedAt   time.Time
}

ContentInfo stores metadata about content being provided

type IndexStats

type IndexStats struct {
	TotalContent   int
	TotalProviders int
	TotalRecords   int
	ExpiredRecords int
}

IndexStats contains index statistics

type Protocol

type Protocol string

Protocol represents the transfer protocol supported by a provider

const (
	ProtocolBitswap   Protocol = "bitswap"
	ProtocolHTTP      Protocol = "http"
	ProtocolGraphSync Protocol = "graphsync"
)

type ProviderRecord

type ProviderRecord struct {
	ProviderID peer.ID       // Who has the content
	ContentID  cid.Cid       // What content they have
	Protocols  []Protocol    // How to get it (bitswap, http, graphsync)
	Addresses  []string      // Where to reach the provider (multiaddrs)
	Timestamp  time.Time     // When this was announced
	TTL        time.Duration // How long this record is valid
}

ProviderRecord represents a single announcement from a provider "I (provider) have this content (CID) and you can get it via these protocols"

func (*ProviderRecord) IsExpired

func (p *ProviderRecord) IsExpired() bool

IsExpired checks if the provider record has expired

func (*ProviderRecord) SupportsProtocol

func (p *ProviderRecord) SupportsProtocol(proto Protocol) bool

SupportsProtocol checks if the provider supports a given protocol

type ProviderStats

type ProviderStats struct {
	ProviderID      peer.ID
	ContentCount    int
	Protocols       []Protocol
	AnnouncementTTL time.Duration
}

ProviderStats contains provider statistics

type SimpleIndex

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

SimpleIndex is the "phonebook" that maps content to providers "For this CID, here are all the providers who have it"

func NewSimpleIndex

func NewSimpleIndex() *SimpleIndex

NewSimpleIndex creates a new content index

func (*SimpleIndex) Announce

func (idx *SimpleIndex) Announce(record *ProviderRecord) error

Announce adds a provider announcement to the index "Provider X has content C available via protocols P"

func (*SimpleIndex) CleanupExpired

func (idx *SimpleIndex) CleanupExpired() int

CleanupExpired removes all expired provider records

func (*SimpleIndex) Close

func (idx *SimpleIndex) Close() error

Close stops the index cleanup goroutine

func (*SimpleIndex) GetProviderContent

func (idx *SimpleIndex) GetProviderContent(providerID peer.ID) ([]cid.Cid, error)

GetProviderContent returns all content announced by a specific provider

func (*SimpleIndex) ListContent

func (idx *SimpleIndex) ListContent() []cid.Cid

ListContent returns all content IDs in the index

func (*SimpleIndex) ListProviders

func (idx *SimpleIndex) ListProviders() []peer.ID

ListProviders returns all provider IDs in the index

func (*SimpleIndex) Query

func (idx *SimpleIndex) Query(c cid.Cid) ([]*ProviderRecord, error)

Query finds all providers for a specific content

func (*SimpleIndex) Remove

func (idx *SimpleIndex) Remove(c cid.Cid, providerID peer.ID) error

Remove removes a provider's announcement for specific content

func (*SimpleIndex) RemoveProvider

func (idx *SimpleIndex) RemoveProvider(providerID peer.ID) error

RemoveProvider removes all announcements from a provider

func (*SimpleIndex) Stats

func (idx *SimpleIndex) Stats() IndexStats

Stats returns index statistics

type SimpleProvider

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

SimpleProvider announces content to the network "I have this content and you can get it from me"

func NewSimpleProvider

func NewSimpleProvider(h host.Host, index *SimpleIndex) *SimpleProvider

NewSimpleProvider creates a new content provider

func (*SimpleProvider) Announce

func (p *SimpleProvider) Announce(ctx context.Context, c cid.Cid, protocols []Protocol) error

Announce tells the network "I have this content" This is the main function providers call to advertise their content

func (*SimpleProvider) Close

func (p *SimpleProvider) Close() error

Close stops the provider

func (*SimpleProvider) GetContentInfo

func (p *SimpleProvider) GetContentInfo(c cid.Cid) (*ContentInfo, error)

GetContentInfo returns info about a specific content

func (*SimpleProvider) HasContent

func (p *SimpleProvider) HasContent(c cid.Cid) bool

HasContent checks if the provider has specific content

func (*SimpleProvider) ListContent

func (p *SimpleProvider) ListContent() []cid.Cid

ListContent returns all content this provider is announcing

func (*SimpleProvider) Remove

func (p *SimpleProvider) Remove(ctx context.Context, c cid.Cid) error

Remove removes a content announcement

func (*SimpleProvider) SetTTL

func (p *SimpleProvider) SetTTL(ttl time.Duration)

SetTTL sets the default TTL for new announcements

func (*SimpleProvider) Stats

func (p *SimpleProvider) Stats() ProviderStats

Stats returns provider statistics

type SimpleSubscriber

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

SimpleSubscriber finds providers for content "Who has this content and how can I get it?"

func NewSimpleSubscriber

func NewSimpleSubscriber(h host.Host, index *SimpleIndex) *SimpleSubscriber

NewSimpleSubscriber creates a new content subscriber

func (*SimpleSubscriber) ClearCache

func (s *SimpleSubscriber) ClearCache()

ClearCache removes all cached provider records

func (*SimpleSubscriber) ClearCacheFor

func (s *SimpleSubscriber) ClearCacheFor(c cid.Cid)

ClearCacheFor removes cached records for specific content

func (*SimpleSubscriber) Close

func (s *SimpleSubscriber) Close() error

Close stops the subscriber

func (*SimpleSubscriber) FindProviders

func (s *SimpleSubscriber) FindProviders(ctx context.Context, c cid.Cid) ([]*ProviderRecord, error)

FindProviders finds all providers for a specific content This is the main function subscribers use to discover who has content

func (*SimpleSubscriber) FindProvidersByProtocol

func (s *SimpleSubscriber) FindProvidersByProtocol(ctx context.Context, c cid.Cid, proto Protocol) ([]*ProviderRecord, error)

FindProvidersByProtocol finds providers that support a specific protocol

func (*SimpleSubscriber) GetBestProvider

func (s *SimpleSubscriber) GetBestProvider(ctx context.Context, c cid.Cid) (*ProviderRecord, error)

GetBestProvider returns the "best" provider based on simple heuristics Priority: 1) Not expired, 2) Most protocols, 3) Most recent

func (*SimpleSubscriber) Stats

func (s *SimpleSubscriber) Stats() SubscriberStats

Stats returns subscriber statistics

func (*SimpleSubscriber) Subscribe

func (s *SimpleSubscriber) Subscribe(ctx context.Context, c cid.Cid) (<-chan *ProviderRecord, error)

Subscribe starts monitoring for new providers of specific content In a real implementation, this would listen to pubsub updates

type SubscriberStats

type SubscriberStats struct {
	SubscriberID   peer.ID
	CachedContent  int
	TotalProviders int
}

SubscriberStats contains subscriber statistics

Jump to

Keyboard shortcuts

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