mirrors

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2025 License: MIT Imports: 17 Imported by: 63

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableMirror

func DisableMirror(r *database.Redis, id int) error

DisableMirror disables the given mirror

func EnableMirror

func EnableMirror(r *database.Redis, id int) error

EnableMirror enables the given mirror

func MarkMirrorDown

func MarkMirrorDown(r *database.Redis, id int, proto Protocol, reason string) error

MarkMirrorDown marks the given mirror as down

func MarkMirrorUp

func MarkMirrorUp(r *database.Redis, id int, proto Protocol) error

MarkMirrorUp marks the given mirror as up

func PushLog added in v0.6.1

func PushLog(r *database.Redis, logAction LogAction) error

func ReadLogs added in v0.6.1

func ReadLogs(r *database.Redis, mirrorid, max int) ([]string, error)

func SetMirrorEnabled

func SetMirrorEnabled(r *database.Redis, id int, state bool) error

SetMirrorEnabled marks a mirror as enabled or disabled

func SetMirrorState

func SetMirrorState(r *database.Redis, id int, proto Protocol, state bool, reason string) error

SetMirrorState sets the state of a mirror to up or down, over HTTP or HTTPS, with an optional reason

Types

type ByComputedScore

type ByComputedScore struct {
	Mirrors
}

ByComputedScore is used to sort a slice of Mirror by their score

func (ByComputedScore) Less

func (b ByComputedScore) Less(i, j int) bool

Less compares two mirrors based on their score

type ByExcludeReason

type ByExcludeReason struct {
	Mirrors
}

ByExcludeReason is used to sort a slice of Mirror alphabetically by their exclude reason

func (ByExcludeReason) Less

func (b ByExcludeReason) Less(i, j int) bool

Less compares two mirrors based on their exclude reason

type ByRank

type ByRank struct {
	Mirrors
	ClientInfo network.GeoIPRecord
}

ByRank is used to sort a slice of Mirror by their rank

func (ByRank) Less

func (m ByRank) Less(i, j int) bool

Less compares two mirrors based on their rank

type Cache

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

Cache implements a local caching mechanism of type LRU for content available in the redis database that is automatically invalidated if the object is updated in Redis.

func NewCache

func NewCache(r *database.Redis) *Cache

NewCache constructs a new instance of Cache

func (*Cache) Clear

func (c *Cache) Clear()

Clear clears the local cache

func (*Cache) GetFileInfo

func (c *Cache) GetFileInfo(path string) (f filesystem.FileInfo, err error)

GetFileInfo returns file information for a given file either from the cache or directly from the database if the object is not yet stored in the cache.

func (*Cache) GetFileInfoMirror added in v0.6.1

func (c *Cache) GetFileInfoMirror(mirrorID int, path string) (f filesystem.FileInfo, err error)

func (*Cache) GetMirror

func (c *Cache) GetMirror(id int) (mirror Mirror, err error)

GetMirror returns all information about a given mirror either from the cache or directly from the database if the object is not yet stored in the cache.

func (*Cache) GetMirrorInvalidationEvent

func (c *Cache) GetMirrorInvalidationEvent() <-chan string

GetMirrorInvalidationEvent returns a channel that contains ID of mirrors that have just been invalidated. This function is supposed to have only ONE reader and is made to avoid a race for MIRROR_UPDATE events between a mirror invalidation and a mirror being fetched from the cache.

func (*Cache) GetMirrors

func (c *Cache) GetMirrors(path string, clientInfo network.GeoIPRecord) (mirrors []Mirror, err error)

GetMirrors returns all the mirrors serving a given file either from the cache or directly from the database if the object is not yet stored in the cache.

type Item

type Item struct {
	Key   string
	Value Value
}

Item contains the key and value that goes into the cache

type LRUCache

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

LRUCache is the internal structure of the cache

func NewLRUCache

func NewLRUCache(capacity uint64) *LRUCache

NewLRUCache return a new instance of the cache

func (*LRUCache) Clear

func (lru *LRUCache) Clear()

Clear the cache

func (*LRUCache) Delete

func (lru *LRUCache) Delete(key string) bool

Delete the key and associated value from the cache

func (*LRUCache) Get

func (lru *LRUCache) Get(key string) (v Value, ok bool)

Get a value from cache

func (*LRUCache) Items

func (lru *LRUCache) Items() []Item

Items returns all the items available in the cache

func (*LRUCache) Keys

func (lru *LRUCache) Keys() []string

Keys returns all the keys available in the cache

func (*LRUCache) Set

func (lru *LRUCache) Set(key string, value Value)

Set a key and associated value into the cache

func (*LRUCache) SetCapacity

func (lru *LRUCache) SetCapacity(capacity uint64)

SetCapacity sets the capacity of the cache

func (*LRUCache) SetIfAbsent

func (lru *LRUCache) SetIfAbsent(key string, value Value)

SetIfAbsent sets a key into the cache only if it doesn't exist yet

func (*LRUCache) Stats

func (lru *LRUCache) Stats() (length, size, capacity uint64, oldest time.Time)

Stats return stats about the caching structure

func (*LRUCache) StatsJSON

func (lru *LRUCache) StatsJSON() string

StatsJSON returns the stats as JSON

type LogAction added in v0.6.1

type LogAction interface {
	GetType() LogType
	GetMirrorID() int
	GetTimestamp() time.Time
	GetOutput() string
}

func NewLogAdded added in v0.6.1

func NewLogAdded(id int) LogAction

func NewLogDisabled added in v0.6.1

func NewLogDisabled(id int) LogAction

func NewLogEdited added in v0.6.1

func NewLogEdited(id int) LogAction

func NewLogEnabled added in v0.6.1

func NewLogEnabled(id int) LogAction

func NewLogError added in v0.6.1

func NewLogError(id int, err error) LogAction

func NewLogScanCompleted added in v0.6.1

func NewLogScanCompleted(id int, files, known, removed, tzoffset int64) LogAction

func NewLogScanStarted added in v0.6.1

func NewLogScanStarted(id int, typ core.ScannerType) LogAction

func NewLogStateChanged added in v0.6.1

func NewLogStateChanged(id int, proto Protocol, up bool, reason string) LogAction

type LogAdded added in v0.6.1

type LogAdded struct {
	LogCommonAction
}

func (*LogAdded) GetOutput added in v0.6.1

func (l *LogAdded) GetOutput() string

type LogCommonAction added in v0.6.1

type LogCommonAction struct {
	Type      LogType
	MirrorID  int
	Timestamp time.Time
}

func (LogCommonAction) GetMirrorID added in v0.6.1

func (l LogCommonAction) GetMirrorID() int

func (LogCommonAction) GetTimestamp added in v0.6.1

func (l LogCommonAction) GetTimestamp() time.Time

func (LogCommonAction) GetType added in v0.6.1

func (l LogCommonAction) GetType() LogType

type LogDisabled added in v0.6.1

type LogDisabled struct {
	LogCommonAction
}

func (*LogDisabled) GetOutput added in v0.6.1

func (l *LogDisabled) GetOutput() string

type LogEdited added in v0.6.1

type LogEdited struct {
	LogCommonAction
}

func (*LogEdited) GetOutput added in v0.6.1

func (l *LogEdited) GetOutput() string

type LogEnabled added in v0.6.1

type LogEnabled struct {
	LogCommonAction
}

func (*LogEnabled) GetOutput added in v0.6.1

func (l *LogEnabled) GetOutput() string

type LogError added in v0.6.1

type LogError struct {
	LogCommonAction
	Err string
}

func (*LogError) GetOutput added in v0.6.1

func (l *LogError) GetOutput() string

type LogScanCompleted added in v0.6.1

type LogScanCompleted struct {
	LogCommonAction
	FilesIndexed int64
	KnownIndexed int64
	Removed      int64
	TZOffset     int64
}

func (*LogScanCompleted) GetOutput added in v0.6.1

func (l *LogScanCompleted) GetOutput() string

type LogScanStarted added in v0.6.1

type LogScanStarted struct {
	LogCommonAction
	Typ core.ScannerType
}

func (*LogScanStarted) GetOutput added in v0.6.1

func (l *LogScanStarted) GetOutput() string

type LogStateChanged added in v0.6.1

type LogStateChanged struct {
	LogCommonAction
	Proto  Protocol
	Up     bool
	Reason string
}

func (*LogStateChanged) GetOutput added in v0.6.1

func (l *LogStateChanged) GetOutput() string

type LogType added in v0.6.1

type LogType uint
const (
	LOGTYPE_ERROR LogType
	LOGTYPE_ADDED
	LOGTYPE_EDITED
	LOGTYPE_ENABLED
	LOGTYPE_DISABLED
	LOGTYPE_STATECHANGED
	LOGTYPE_SCANSTARTED
	LOGTYPE_SCANCOMPLETED
)

type Mirror

type Mirror struct {
	ID                          int              `redis:"ID" yaml:"-"`
	Name                        string           `redis:"name" yaml:"Name"`
	HttpURL                     string           `redis:"http" yaml:"HttpURL"`
	RsyncURL                    string           `redis:"rsync" yaml:"RsyncURL"`
	FtpURL                      string           `redis:"ftp" yaml:"FtpURL"`
	SponsorName                 string           `redis:"sponsorName" yaml:"SponsorName"`
	SponsorURL                  string           `redis:"sponsorURL" yaml:"SponsorURL"`
	SponsorLogoURL              string           `redis:"sponsorLogo" yaml:"SponsorLogoURL"`
	AdminName                   string           `redis:"adminName" yaml:"AdminName"`
	AdminEmail                  string           `redis:"adminEmail" yaml:"AdminEmail"`
	CustomData                  string           `redis:"customData" yaml:"CustomData"`
	ContinentOnly               bool             `redis:"continentOnly" yaml:"ContinentOnly"`
	CountryOnly                 bool             `redis:"countryOnly" yaml:"CountryOnly"`
	ASOnly                      bool             `redis:"asOnly" yaml:"ASOnly"`
	Score                       int              `redis:"score" yaml:"Score"`
	Latitude                    float32          `redis:"latitude" yaml:"Latitude"`
	Longitude                   float32          `redis:"longitude" yaml:"Longitude"`
	ContinentCode               string           `redis:"continentCode" yaml:"ContinentCode"`
	CountryCodes                string           `redis:"countryCodes" yaml:"CountryCodes"`
	ExcludedCountryCodes        string           `redis:"excludedCountryCodes" yaml:"ExcludedCountryCodes"`
	Asnum                       uint             `redis:"asnum" yaml:"ASNum"`
	Comment                     string           `redis:"comment" yaml:"-"`
	Enabled                     bool             `redis:"enabled" yaml:"Enabled"`
	HttpUp                      bool             `redis:"httpUp" json:"-" yaml:"-"`
	HttpsUp                     bool             `redis:"httpsUp" json:"-" yaml:"-"`
	HttpDownReason              string           `redis:"httpDownReason" json:",omitempty" yaml:"-"`
	HttpsDownReason             string           `redis:"httpsDownReason" json:",omitempty" yaml:"-"`
	StateSince                  Time             `redis:"stateSince" json:",omitempty" yaml:"-"`
	AllowRedirects              Redirects        `redis:"allowredirects" json:",omitempty" yaml:"AllowRedirects"`
	TZOffset                    int64            `redis:"tzoffset" json:"-" yaml:"-"` // timezone offset in ms
	Distance                    float32          `redis:"-" yaml:"-"`
	CountryFields               []string         `redis:"-" json:"-" yaml:"-"`
	ExcludedCountryFields       []string         `redis:"-" json:"-" yaml:"-"`
	Filepath                    string           `redis:"-" json:"-" yaml:"-"`
	Weight                      float32          `redis:"-" json:"-" yaml:"-"`
	ComputedScore               int              `redis:"-" yaml:"-"`
	LastSync                    Time             `redis:"lastSync" yaml:"-"`
	LastSuccessfulSync          Time             `redis:"lastSuccessfulSync" yaml:"-"`
	LastSuccessfulSyncProtocol  core.ScannerType `redis:"lastSuccessfulSyncProtocol" yaml:"-"`
	LastSuccessfulSyncPrecision core.Precision   `redis:"lastSuccessfulSyncPrecision" yaml:"-"`
	LastModTime                 Time             `redis:"lastModTime" yaml:"-"`

	FileInfo      *filesystem.FileInfo `redis:"-" json:"-" yaml:"-"`          // Details of the requested file on this specific mirror
	AbsoluteURL   string               `redis:"-" yaml:"-"`                   // Absolute HttpURL, guaranteed to start with a scheme
	ExcludeReason string               `redis:"-" json:",omitempty" yaml:"-"` // Reason why the mirror was excluded
}

Mirror is the structure representing all the information about a mirror

func (*Mirror) IsHTTPOnly added in v0.6.1

func (m *Mirror) IsHTTPOnly() bool

IsHTTPOnly returns true if the mirror has an HTTP address

func (*Mirror) IsHTTPSOnly added in v0.6.1

func (m *Mirror) IsHTTPSOnly() bool

IsHTTPSOnly returns true if the mirror has an HTTPS address

func (*Mirror) IsUp added in v0.6.1

func (m *Mirror) IsUp() bool

IsUp returns true if the mirror is up (for a mirror that supports both HTTP and HTTPS, it means both are up)

func (*Mirror) Prepare

func (m *Mirror) Prepare()

Prepare must be called after retrieval from the database to reformat some values

type Mirrors

type Mirrors []Mirror

Mirrors represents a slice of Mirror

func (Mirrors) Len

func (s Mirrors) Len() int

Len return the number of Mirror in the slice

func (Mirrors) Swap

func (s Mirrors) Swap(i, j int)

Swap swaps mirrors at index i and j

type Protocol added in v0.6.1

type Protocol uint
const (
	UNDEFINED Protocol = iota
	HTTP
	HTTPS
)

func (Protocol) String added in v0.6.1

func (p Protocol) String() string

type Redirects

type Redirects int

Redirects is handling the per-mirror authorization of HTTP redirects

func (*Redirects) Allowed

func (r *Redirects) Allowed() bool

Allowed will return true if redirects are authorized for this mirror

func (Redirects) MarshalYAML

func (r Redirects) MarshalYAML() (interface{}, error)

MarshalYAML converts internal values to YAML

func (*Redirects) UnmarshalYAML

func (r *Redirects) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML converts YAML to internal values

type Results

type Results struct {
	FileInfo     filesystem.FileInfo
	IP           string
	ClientInfo   network.GeoIPRecord
	MirrorList   Mirrors
	ExcludedList Mirrors `json:",omitempty"`
	Fallback     bool    `json:",omitempty"`
	LocalJSPath  string
}

Results is the resulting struct of a request and is used by the renderers to generate the final page.

type Time

type Time struct {
	time.Time
}

Time is a structure holding a time.Time object. It is used to serialize and deserialize a time held in a redis database.

func (Time) FromTime

func (t Time) FromTime(time time.Time) Time

FromTime returns a Time from a time.Time

func (Time) RedisArg

func (t Time) RedisArg() interface{}

RedisArg serialize the time.Time object

func (*Time) RedisScan

func (t *Time) RedisScan(src interface{}) (err error)

RedisScan deserialize the time.Time object

type Value

type Value interface {
	Size() int
}

Value that go into LRUCache need to satisfy this interface.

Jump to

Keyboard shortcuts

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