mirrors

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2018 License: MIT Imports: 14 Imported by: 35

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, reason string) error

MarkMirrorDown marks the given mirror as down

func MarkMirrorUp

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

MarkMirrorUp marks the given mirror as up

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, state bool, reason string) error

SetMirrorState sets the state of a mirror to up or down 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) 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 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"`
	Up                    bool      `redis:"up" json:"-" yaml:"-"`
	ExcludeReason         string    `redis:"excludeReason" json:",omitempty" yaml:"-"`
	StateSince            Time      `redis:"stateSince" json:",omitempty" yaml:"-"`
	AllowRedirects        Redirects `redis:"allowredirects" json:",omitempty" yaml:"AllowRedirects"`
	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:"-"`
	LastModTime           Time      `redis:"lastModTime" yaml:"-"`

	FileInfo *filesystem.FileInfo `redis:"-" json:"-" yaml:"-"` // Details of the requested file on this specific mirror
}

Mirror is the structure representing all the information about a mirror

func (*Mirror) IsHTTPS

func (m *Mirror) IsHTTPS() bool

IsHTTPS returns true if the mirror has an HTTPS address

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 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