peer

package
v0.0.51 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPeerNotFound = errors.New("peer not found")

Functions

func IDFromPublicKey added in v0.0.51

func IDFromPublicKey(publicKey ed25519.PublicKey) uint64

Returns the first 8 bytes of the public key

Types

type PeerCopy added in v0.0.51

type PeerCopy struct {
	ID                  uint64
	AddrPort            netip.AddrPort
	PublicKey           ed25519.PublicKey
	AuthChallengeSolved time.Time
}

type PeerDistance added in v0.0.51

type PeerDistance struct {
	Peer     PeerCopy
	Distance uint64
}

func SortPeersByDistance added in v0.0.51

func SortPeersByDistance(target uint64, peers []PeerCopy) []PeerDistance

type Store

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

func NewStore

func NewStore(cfg *StoreCfg) *Store

func (*Store) AddPeer added in v0.0.51

func (s *Store) AddPeer(addrPort netip.AddrPort, isEdge bool) error

Peer is added if not found.

func (*Store) AuthChallengeSolved added in v0.0.51

func (s *Store) AuthChallengeSolved(addrPort netip.AddrPort)

func (*Store) CountActive added in v0.0.51

func (s *Store) CountActive() int

func (*Store) CreateAuthChallenge added in v0.0.51

func (s *Store) CreateAuthChallenge(addrPort netip.AddrPort) (auth.AuthChallenge, error)

func (*Store) CurrentAuthChallengeAndPubKey added in v0.0.51

func (s *Store) CurrentAuthChallengeAndPubKey(addrPort netip.AddrPort) (auth.AuthChallenge, ed25519.PublicKey, error)

func (*Store) Edges added in v0.0.51

func (s *Store) Edges() []PeerCopy

func (*Store) IsEdge added in v0.0.51

func (s *Store) IsEdge(addrPort netip.AddrPort) bool

func (*Store) ListActive added in v0.0.51

func (s *Store) ListActive(exclude *netip.AddrPort) []PeerCopy

func (*Store) ListAll added in v0.0.51

func (s *Store) ListAll() []PeerCopy

func (*Store) RandPeers

func (s *Store) RandPeers(limit int, exclude *netip.AddrPort) []PeerCopy

For such a simple problem, I found it surprisingly tough to make an efficient implementation.

func (*Store) SetPeerUsedSpaceAndCapacity added in v0.0.51

func (s *Store) SetPeerUsedSpaceAndCapacity(addrPort netip.AddrPort, usedSpace, capacity int64) error

func (*Store) SetPublicKeyAndID added in v0.0.51

func (s *Store) SetPublicKeyAndID(addrPort netip.AddrPort, publicKey ed25519.PublicKey) error

func (*Store) TotalUsedSpaceAndCapacity added in v0.0.51

func (s *Store) TotalUsedSpaceAndCapacity() (usedSpace, capacity uint64)

Currently this is flawed, as a peer can lie about their resources. Maybe remove this entirely, or set bounds for acceptable figures. The larger the network, the more accurate this becomes.

type StoreCfg

type StoreCfg struct {
	SubSvc *sub.SubscriptionService
	Logger logger.Logger
}

Jump to

Keyboard shortcuts

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