peerstore

package
v0.2403.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PeerRegistrationTTL is a deadline for the next registration.
	PeerRegistrationTTL = time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store is an in-memory data structure for storing peers' data.

func NewStore

func NewStore(b backup.Backend, opts ...StoreOption) *Store

NewStore creates a new peer store.

func (*Store) Add

func (s *Store) Add(ns string, info peer.AddrInfo) (time.Duration, error)

Add inserts the given peer address into the store under the given namespace.

func (*Store) Backup

func (s *Store) Backup(ctx context.Context) error

Backup persists peers to the backup.

func (*Store) NamespacePeers

func (s *Store) NamespacePeers(ns string, limit int) []peer.AddrInfo

NamespacePeers returns a random selection of peers from the given namespace.

func (*Store) Peers

func (s *Store) Peers() []peer.AddrInfo

Peers returns peers from all namespaces without duplicates.

func (*Store) Remove

func (s *Store) Remove(ns string, pid peer.ID)

Remove removes the peer from the given namespace.

func (*Store) Restore

func (s *Store) Restore(ctx context.Context) error

Restore loads peers from the backup.

func (*Store) Start

func (s *Store) Start()

Start starts background services which periodically backup and clean the store.

func (*Store) Stop

func (s *Store) Stop()

Stop stops all background services. This method blocks until all services are stopped.

type StoreOption

type StoreOption func(opts *StoreOptions)

StoreOption is a store option setter.

func WithMaxNamespacePeers

func WithMaxNamespacePeers(max int) StoreOption

WithMaxNamespacePeers configures maximum number of peers in a namespace.

func WithMaxPeerNamespaces

func WithMaxPeerNamespaces(max int) StoreOption

WithMaxPeerNamespaces configures maximum number of peer's namespaces.

func WithMaxPeers

func WithMaxPeers(max int) StoreOption

WithMaxPeers configures maximum number of peers.

type StoreOptions

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

StoreOptions are store options.

func DefaultStoreOptions

func DefaultStoreOptions() *StoreOptions

DefaultStoreOptions returns the default store options.

Jump to

Keyboard shortcuts

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