Documentation
¶
Index ¶
- type ContentInfo
- type IndexStats
- type Protocol
- type ProviderRecord
- type ProviderStats
- type SimpleIndex
- func (idx *SimpleIndex) Announce(record *ProviderRecord) error
- func (idx *SimpleIndex) CleanupExpired() int
- func (idx *SimpleIndex) Close() error
- func (idx *SimpleIndex) GetProviderContent(providerID peer.ID) ([]cid.Cid, error)
- func (idx *SimpleIndex) ListContent() []cid.Cid
- func (idx *SimpleIndex) ListProviders() []peer.ID
- func (idx *SimpleIndex) Query(c cid.Cid) ([]*ProviderRecord, error)
- func (idx *SimpleIndex) Remove(c cid.Cid, providerID peer.ID) error
- func (idx *SimpleIndex) RemoveProvider(providerID peer.ID) error
- func (idx *SimpleIndex) Stats() IndexStats
- type SimpleProvider
- func (p *SimpleProvider) Announce(ctx context.Context, c cid.Cid, protocols []Protocol) error
- func (p *SimpleProvider) Close() error
- func (p *SimpleProvider) GetContentInfo(c cid.Cid) (*ContentInfo, error)
- func (p *SimpleProvider) HasContent(c cid.Cid) bool
- func (p *SimpleProvider) ListContent() []cid.Cid
- func (p *SimpleProvider) Remove(ctx context.Context, c cid.Cid) error
- func (p *SimpleProvider) SetTTL(ttl time.Duration)
- func (p *SimpleProvider) Stats() ProviderStats
- type SimpleSubscriber
- func (s *SimpleSubscriber) ClearCache()
- func (s *SimpleSubscriber) ClearCacheFor(c cid.Cid)
- func (s *SimpleSubscriber) Close() error
- func (s *SimpleSubscriber) FindProviders(ctx context.Context, c cid.Cid) ([]*ProviderRecord, error)
- func (s *SimpleSubscriber) FindProvidersByProtocol(ctx context.Context, c cid.Cid, proto Protocol) ([]*ProviderRecord, error)
- func (s *SimpleSubscriber) GetBestProvider(ctx context.Context, c cid.Cid) (*ProviderRecord, error)
- func (s *SimpleSubscriber) Stats() SubscriberStats
- func (s *SimpleSubscriber) Subscribe(ctx context.Context, c cid.Cid) (<-chan *ProviderRecord, error)
- type SubscriberStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContentInfo ¶
ContentInfo stores metadata about content being provided
type IndexStats ¶
IndexStats contains index statistics
type Protocol ¶
type Protocol string
Protocol represents the transfer protocol supported by a provider
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 (*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 ¶
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) 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 ¶
Announce tells the network "I have this content" This is the main function providers call to advertise their content
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) 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