Categorygithub.com/xbmc/mirrorbits
modulepackage
0.1.2
Repository: https://github.com/xbmc/mirrorbits.git
Documentation: pkg.go.dev

# README

Mirrorbits

Mirrorbits is a geographical download redirector written in Go for distributing files efficiently across a set of mirrors. It offers a simple and economic way to create a full Content Delivery Network layer using a pure software stack. It is primarily designed for the distribution of large-scale Open-Source projects with a lot of traffic.

mirrorbits_screenshot

Main Features

  • Blazing fast, can reach 8K req/s on a single laptop
  • Easy to deploy and maintain, everything is packed in a single binary
  • Automatic synchronization over rsync or FTP
  • Response can be either JSON or HTTP redirect
  • Support partial repositories
  • Complete checksum / size control
  • Realtime monitoring and reports
  • Disable misbehaving mirrors without human intervention
  • Realtime decision making based on location, AS number and defined rules
  • Smart load-balancing over multiple mirrors in the same area to avoid hotspots
  • Ability to adjust the weight of each mirror
  • Limit access to a country, region or ASN for any mirror
  • Realtime statistics per file / mirror / date
  • Realtime reconfiguration
  • Seamless binary upgrade (aka zero downtime upgrade)
  • Full IPv6 support
  • more...

Is it production ready?

Almost! Mirrorbits is already running in production at VideoLAN to distribute VLC media player since April 2014. Yet some things might change before the 1.0 release, notably the response of a JSON request and few configuration items. If you intend to deploy Mirrorbits in a production system it is strongly advised to contact the author first!

Quick start

Prerequisites

  • Redis 2.8 (or later)
  • libgeoip
  • a recent geoip database (see contrib/geoip/)

Installation

You can either get a prebuilt version or choose to build it yourself.

Manual build

$ go get github.com/etix/mirrorbits
$ go install -v github.com/etix/mirrorbits

The resulting executable should now be in your $GOPATH/bin directory.

If you plan to use the web UI be sure to copy the templates into your system (usually in /usr/share/mirrorbits).

Configuration

A sample configuration file can be found here.

Optiondescription
RepositoryPath to your own copy of the repository
TemplatesPath containing the templates
OutputModeauto: based on the Accept header content
redirect: do an HTTP redirect to the destination
json: return a JSON formatted document (also known as API mode)
ListenAddressLocal address and port to bind
GzipUse gzip compression for the JSON responses
RedisAddressAddress and port of the Redis database
RedisPasswordPassword to access the Redis database
LogDirPath to the directory where to save log files
GeoipDatabasePathPath to the geoip databases
ConcurrentSyncMaximum number of server sync (rsync/ftp) do to simultaneously
DisallowRedirectsDisable any mirror trying to do an HTTP redirect
WeightDistributionRangeMultiplier of the distance to the first mirror to find other possible mirrors in order to distribute the load
DisableOnMissingFileDisable a mirror if an advertised file on rsync/ftp appears to be missing on HTTP
FallbacksA list of possible mirrors to use as fallback if a request fails or if the database is unreachable. These mirrors are not tracked by mirrorbits. It is assumed they have all the files available in the local repository.

Running

Mirrorbits is a self-contained application and act, at the same time, as the server and the cli.

To run the server:

mirrorbits -D

Additionnal options can be found with mirrobits -help.

To run the cli:

mirrorbits help

Upgrading

Mirrorbits has a mode called seamless binary upgrade to upgrade the server executable at runtime without service disruption. Once the binary has been replaced on the filesystem just issue the following command in the cli:

mirrorbits upgrade

Considerations

  • When configured in redirect mode, Mirrorbits can easily serve client requests directly but it is usually recommended to set it behind a reverse proxy like nginx. In this case take care to pass the IP address of the client within a X-Forwarded-For header:
proxy_set_header X-Forwarded-For $remote_addr;
  • It is advised to never cache requests intended for Mirrorbits since each request is supposed to be unique, caching the result might have unexpected consequences.
  • Having multiple instances of Mirrorbits sharing the same database is not yet (officially) supported, therefore don't do it in production.

We're social!

The best place to discuss about mirrorbits is to join the #VideoLAN IRC channel on Freenode.
For the latest news, you can follow @mirrorbits on Twitter.

License MIT

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# Functions

GetConfig returns a pointer to a configuration object FIXME reading from the pointer could cause a race!.
HTTPServer is the constructor of the HTTP server.
Make the parent exit gracefully with SIGQUIT.
LoadConfig loads the configuration file if it has not yet been loaded.
NewCache constructs a new instance of Cache.
NewContext returns a new instance of Context.
NewGeoIP instanciates a new instance of GeoIP.
NewGzipHandler is an HTTP handler used to compress responses if supported by the client.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ParseCommands parses the command line and call the appropriate functions.
Recover from a seamless binary upgrade and use an already existing listener to take over the connections.
Launch {self} as a child process passing listener details to provide a seamless binary upgrade.
ReloadConfig reloads the configuration file and update it globally.
No description provided by the author
ReloadLogs will reopen the logs to allow rotations.
No description provided by the author
No description provided by the author
SubCmd prints the usage of a subcommand.

# Constants

N[Pi/180, 50].
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
N[180/Pi, 50].
No description provided by the author

# Variables

NoSyncMethod is returned when no sync protocol is available.
No description provided by the author
No description provided by the author

# Structs

ByComputedScore is used to sort a slice of Mirror by their rank.
No description provided by the author
ByExcludeReason is used to sort a slice of Mirror alphabetically by their exclude reason.
ByRank is used to sort a slice of Mirror by their rank.
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.
Context represents the context of a request.
No description provided by the author
DefaultEngine is the default algorithm used for mirror selection.
No description provided by the author
FileInfo is a struct embedding details about a file served by the redirector.
GeoIP contains methods to query the GeoIP database.
GeoIPRec defines a GeoIP record for a given IP address.
HTTP represents an instance of the HTTP webserver.
No description provided by the author
JsonRenderer is used to render JSON formatted details about the current request.
No description provided by the author
Mirror is the structure representing all the informations about a mirror.
MirrorlistPage is the resulting struct of a request and is used by the renderers to generate the final page.
MirrorListRenderer is used to render the mirrorlist page using the HTML templates.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RedirectRenderer is a basic renderer that redirects the user to the first mirror in the list.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Templates is a struct embedding instances of the precompiled templates.

# Interfaces

No description provided by the author
No description provided by the author
Values that go into LRUCache need to satisfy this interface.

# Type aliases

Mirrors represents a slice of Mirror.
No description provided by the author
RequestType defines the type of the request.