Documentation
¶
Index ¶
- func GetRegions(peers []*Peer) []string
- type Cache
- type FilterOptions
- type Manager
- func (m *Manager) CheckPeer(ctx context.Context, peer *Peer) error
- func (m *Manager) CheckPeers(ctx context.Context, peers []*Peer, concurrency int) error
- func (m *Manager) ClearCache()
- func (m *Manager) FilterPeers(peers []*Peer, filter *FilterOptions, sortBy SortBy) []*Peer
- func (m *Manager) GetAvailablePeers(ctx context.Context, filter *FilterOptions) ([]*Peer, error)
- func (m *Manager) GetBestPeers(ctx context.Context, count int, filter *FilterOptions) ([]*Peer, error)
- func (m *Manager) GetPeers(ctx context.Context) ([]*Peer, error)
- func (m *Manager) RefreshCache(ctx context.Context) error
- type Peer
- type Protocol
- type RawPeersJSON
- type SetupOption
- type SortBy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetRegions ¶
GetRegions returns a list of all unique regions
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache stores cached peers with TTL
type FilterOptions ¶
type FilterOptions struct {
Protocols []Protocol // Filter by protocols
Regions []string // Filter by regions
MinRTT time.Duration // Minimum RTT
MaxRTT time.Duration // Maximum RTT
OnlyUp bool // Only "up" peers from JSON
OnlyAvailable bool // Only checked available peers
}
FilterOptions defines filtering criteria
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages the list of peers and cache
func NewManager ¶
func NewManager(opts ...SetupOption) *Manager
NewManager creates a new peers manager
func (*Manager) CheckPeers ¶
CheckPeers checks multiple peers in parallel
func (*Manager) FilterPeers ¶
func (m *Manager) FilterPeers(peers []*Peer, filter *FilterOptions, sortBy SortBy) []*Peer
FilterPeers filters and sorts peers
func (*Manager) GetAvailablePeers ¶
GetAvailablePeers returns checked available peers
func (*Manager) GetBestPeers ¶
func (m *Manager) GetBestPeers(ctx context.Context, count int, filter *FilterOptions) ([]*Peer, error)
GetBestPeers returns N best peers by RTT
type Peer ¶
type Peer struct {
Address string // Full address: "tcp://host:port"
Protocol Protocol // Extracted protocol
Host string // Host without protocol
Port string // Port
Region string // Region from JSON key: "germany.md" -> "germany"
// Fields from JSON
Up bool `json:"up"`
Key string `json:"key"`
ResponseMS int `json:"response_ms"`
LastSeen int64 `json:"last_seen"`
Updated int64 `json:"updated"`
Imported int64 `json:"imported"`
ProtoMinor int `json:"proto_minor"`
Priority *int `json:"priority,omitempty"`
// Check results
Available bool // Is the peer available now
RTT time.Duration // Measured RTT
CheckedAt time.Time // Time of check
CheckError error // Check error if any
}
Peer represents information about a Yggdrasil peer from the public list
type RawPeersJSON ¶
type RawPeersJSON map[string]map[string]struct { Up bool `json:"up"` Key string `json:"key"` ResponseMS int `json:"response_ms"` LastSeen int64 `json:"last_seen"` Updated int64 `json:"updated"` Imported int64 `json:"imported"` ProtoMinor int `json:"proto_minor"` Priority *int `json:"priority,omitempty"` }
RawPeersJSON represents the structure of JSON from publicnodes.json Format: map["country.md"]map["address"]{up, key, response_ms, ...}
type SetupOption ¶
type SetupOption func(*Manager)
SetupOption is a functional option for Manager
func WithCacheTTL ¶
func WithCacheTTL(ttl time.Duration) SetupOption
WithCacheTTL sets the cache TTL
func WithCustomURLs ¶
func WithCustomURLs(primary, fallback string) SetupOption
WithCustomURLs sets custom primary and fallback URLs
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) SetupOption
WithHTTPClient sets a custom HTTP client
func WithTimeout ¶
func WithTimeout(timeout time.Duration) SetupOption
WithTimeout sets the timeout for availability checks