mirava

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

mirava-core

CI

Go library for probing package and container mirrors: whether they respond, how fast they move bytes, whether a given package is present, and — for embedding in a website — a direct download URL.

It also resolves mirrors through multiple DNS providers (UDP, DoH, DoT, system) and flags diverging answers, a signal for poisoning, filtering or broken geo-DNS.

Quick start

package main

import (
	"context"
	"fmt"
	"log"

	mirava "github.com/MiravaOrg/mirava-core"
)

func main() {
	m := mirava.New()
	ctx := context.Background()

	// One interface for every ecosystem.
	p, err := m.Prober(mirava.TypeApt)
	if err != nil {
		log.Fatal(err)
	}

	status, err := p.Status(ctx, "https://archive.ubuntu.com/ubuntu/")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("status:", status.OK, status.WorkingPath)

	speed, err := p.Speed(ctx, "https://archive.ubuntu.com/ubuntu/", mirava.SpeedOptions{
		Duration: 5 * 1000 * 1000 * 1000, // 5s download window
		OnProgress: func(pr mirava.Progress) {
			fmt.Printf("\r%.1f MB/s", pr.SpeedMBs)
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("speed: %.2f MB/s (%s)\n", speed.SpeedMBps, speed.Rating)

	pkg, err := p.Package(ctx, "https://archive.ubuntu.com/ubuntu/", mirava.PackageQuery{Name: "curl"})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("curl:", pkg.Version, "found:", pkg.Found)

	// Direct download URL for a website client.
	dl, err := p.Resolve(ctx, "https://archive.ubuntu.com/ubuntu/", mirava.PackageQuery{Name: "curl"})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("download:", dl.URL, dl.Size, dl.SHA256)

	// DNS-provider probing: how does each resolver see this mirror?
	probe, err := m.DNSProbe(ctx, "https://archive.ubuntu.com/ubuntu/",
		mirava.DNSSystem, mirava.DNSCloudflareUDP, mirava.DNSGoogleUDP)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("dns divergence:", probe.Divergence)
}

The Prober interface

Every backend implements the same four probes. Results share a common envelope (type, mirror, checked_at, latency, ok) with ecosystem-specific detail payloads. A missing package is a result (Found == false), not an error.

Probe Role
Status Mirror is reachable and behaves like the expected ecosystem.
Speed Download throughput (SpeedOptions.Duration bounds the sample; OnProgress streams updates).
Package Whether a package exists, with version + ecosystem detail.
Resolve Direct download URL (issues any intermediate requests itself), plus size, SHA256 and required headers.

Ecosystem-specific query options ride in PackageQuery.Options, e.g. *apt.QueryOptions{Suite, Component, Arch}.

Mirror types

Type Ecosystem Backend
apt Debian/Ubuntu .deb repos internal/apt
pacman Arch Linux mirrors internal/pacman
npm npm registry mirrors internal/npm
go Go module proxies (GOPROXY) internal/gomod
cargo crates.io sparse index internal/cargo
pypi PEP 503 simple indexes internal/pypi
docker OCI / Docker registries internal/docker
composer Composer / Packagist internal/composer
yum, dnf, nuget — not implemented yet

m.Apt, m.AptDebian and m.AptUbuntu are distro-hinted variants of the apt backend.

DNS provider probing

probe, err := m.DNSProbe(ctx, mirror,
	mirava.DNSSystem,
	mirava.DNSCloudflareUDP,
	mirava.DNSCloudflareDoH,
	mirava.CustomDNS("10.0.0.53"),
)

Each provider reports its resolved IPs, resolution RTT and TCP reachability to the mirror. When providers disagree on IPs, ProbeResult.Divergence says so.

Caching

Backends share a two-tier cache: a bounded in-memory LRU over an atomic disk store in the OS cache directory (e.g. ~/Library/Caches/mirava-core). Design points:

  • Content-addressed blobs. apt indexes are stored by SHA256, so every mirror of the same distro shares one download.
  • Hash-verified downloads. A checksum mismatch is reported, not served.
  • Parse once. Each index is parsed a single time per blob; lookups afterwards are map lookups.
  • Atomic writes (temp file + rename) — safe for concurrent processes.
  • Singleflight dedup — concurrent lookups of the same index download once.
  • No TTL extension on disk→memory promotion.

Bring your own store via a cache.Store implementation to share caches across instances (Redis, S3, …).

Development

make test        # unit tests (-race)
make integration # live-mirror tests (network required)
make cover       # coverage report

Unit tests are offline (httptest fixtures). Live-mirror tests live behind the integration build tag:

go test -tags=integration ./...

Layout

Path Role
mirava.go New() — wiring, re-exported public API
internal/core Prober interface, result envelopes, shared errors, backend Config
internal/httpx URL joining, shared client, User-Agent, single speed-measure loop
internal/cache Store interface, LRU, atomic disk layer, singleflight
internal/apt InRelease-driven apt backend (reference implementation)
internal/<eco> One backend package per ecosystem
internal/dns DNS providers (UDP / DoH / DoT / system) and mirror probing

Adding a backend

  1. Create internal/<eco> implementing the four core.Prober methods.
  2. Add QueryOptions / Detail types in your package.
  3. Wire it into Mirava and Prober() in mirava.go.
  4. Add httptest fixtures under internal/backends_test.

See CONTRIBUTING.md.


Maintained by MiravaOrg.

Documentation

Overview

Package mirava is the entrypoint for mirava-core: a library for probing package and container mirrors — whether they respond, how fast they move bytes, whether a package is present, and (for the website) a direct download URL.

Construct once with New, then use Mirava.Prober for the uniform per-ecosystem interface:

m := mirava.New()
p, _ := m.Prober(mirava.TypeApt)
res, err := p.Status(ctx, "https://archive.ubuntu.com/ubuntu/")

Index

Constants

View Source
const (
	TypeApt      = core.TypeApt
	TypeYum      = core.TypeYum
	TypeDnf      = core.TypeDnf
	TypePacman   = core.TypePacman
	TypeNpm      = core.TypeNpm
	TypeGo       = core.TypeGo
	TypeCargo    = core.TypeCargo
	TypePypi     = core.TypePypi
	TypeNuget    = core.TypeNuget
	TypeDocker   = core.TypeDocker
	TypeComposer = core.TypeComposer
)

Mirror type constants.

Variables

View Source
var (
	ErrNotFound       = core.ErrNotFound
	ErrTimeout        = core.ErrTimeout
	ErrInvalidMirror  = core.ErrInvalidMirror
	ErrUnreachable    = core.ErrUnreachable
	ErrNotImplemented = core.ErrNotImplemented
)

Sentinel errors.

View Source
var (
	DNSSystem        = dns.System{}
	DNSCloudflareUDP = dns.CloudflareUDP
	DNSCloudflareDoH = dns.CloudflareDoH
	DNSCloudflareDoT = dns.CloudflareDoT
	DNSGoogleUDP     = dns.GoogleUDP
	DNSGoogleDoH     = dns.GoogleDoH
	DNSQuad9UDP      = dns.Quad9UDP
	DNSQuad9DoH      = dns.Quad9DoH
	DNSOpenDNSUDP    = dns.OpenDNSUDP
	DNSAdGuardUDP    = dns.AdGuardUDP
	DNSAdGuardDoH    = dns.AdGuardDoH
)

DNS provider shorthands for the preset public resolvers.

View Source
var SpeedRating = core.SpeedRating

SpeedRating maps MB/s to a coarse label (Slow/Average/Good/Excellent).

Functions

func CustomDNS

func CustomDNS(addr string) dns.Provider

CustomDNS builds a custom UDP provider (e.g. a self-hosted resolver).

func CustomDNSDoH

func CustomDNSDoH(url string) dns.Provider

CustomDNSDoH builds a custom DoH provider from a RFC 8484 endpoint URL.

func WithDNSProviders

func WithDNSProviders(ps ...dns.Provider) func(*options)

WithDNSProviders sets the default providers used by Mirava.DNSProbe. Nil uses the dns package defaults (System, Cloudflare, Google, Quad9).

func WithHTTPClient

func WithHTTPClient(c *http.Client) func(*options)

WithHTTPClient overrides the shared HTTP client.

func WithLogger

func WithLogger(l *slog.Logger) func(*options)

WithLogger sets the diagnostic logger; diagnostics are discarded by default.

Types

type DownloadResult

type DownloadResult = core.DownloadResult

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type Duration

type Duration = core.Duration

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type Envelope

type Envelope = core.Envelope

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type Mirava

type Mirava struct {
	Apt       *apt.Service
	AptDebian *apt.Service
	AptUbuntu *apt.Service
	Npm       *npm.Service
	PyPi      *pypi.Service
	Docker    *docker.Service
	Pacman    *pacman.Service
	Go        *gomod.Service
	Cargo     *cargo.Service
	Composer  *composer.Service
	// contains filtered or unexported fields
}

Mirava bundles the ecosystem backends behind one configuration. Create it once with New; the zero value is not usable.

func New

func New(opts ...func(*options)) *Mirava

New builds a Mirava instance with defaults (shared HTTP client, silent logger, memory+disk cache) overridden by opts.

func (*Mirava) DNSProbe

func (m *Mirava) DNSProbe(ctx context.Context, mirror string, providers ...dns.Provider) (*dns.ProbeResult, error)

DNSProbe resolves the mirror's hostname through each configured DNS provider and checks TCP reachability to the mirror via each provider's IPs. Diverging answers across providers suggest poisoning, filtering or broken geo-DNS.

Pass explicit providers to override the defaults (see WithDNSProviders).

func (*Mirava) Prober

func (m *Mirava) Prober(t MirrorType) (Prober, error)

Prober returns the backend for a mirror type. Unimplemented types return an error wrapping ErrNotImplemented.

type MirrorType

type MirrorType = core.MirrorType

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type PackageQuery

type PackageQuery = core.PackageQuery

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type PackageResult

type PackageResult = core.PackageResult

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type ParseError

type ParseError = core.ParseError

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type Prober

type Prober = core.Prober

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type Progress

type Progress = core.Progress

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type RequestError

type RequestError = core.RequestError

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type ResultDetail

type ResultDetail = core.ResultDetail

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type SpeedError

type SpeedError = core.SpeedError

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type SpeedOptions

type SpeedOptions = core.SpeedOptions

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type SpeedResult

type SpeedResult = core.SpeedResult

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type StatusError

type StatusError = core.StatusError

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type StatusResult

type StatusResult = core.StatusResult

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

type ValidationError

type ValidationError = core.ValidationError

Re-exported API. The interface, result types and errors live in internal/core and are re-exported here as the public surface.

Directories

Path Synopsis
cmd
mirrorscan command
Command mirrorscan runs mirava-core's Prober logic against a parsed mirror catalog (by ecosystem) and prints a per-mirror report.
Command mirrorscan runs mirava-core's Prober logic against a parsed mirror catalog (by ecosystem) and prints a per-mirror report.
internal
apt
Package apt implements the apt mirror backend: Debian and Ubuntu repositories.
Package apt implements the apt mirror backend: Debian and Ubuntu repositories.
cache
Package cache provides the storage layer behind mirava-core probes: a small interface implemented by a bounded in-memory LRU and an atomic-write disk layer, plus a singleflight guard so concurrent lookups share one upstream fetch.
Package cache provides the storage layer behind mirava-core probes: a small interface implemented by a bounded in-memory LRU and an atomic-write disk layer, plus a singleflight guard so concurrent lookups share one upstream fetch.
cargo
Package cargo implements the Cargo sparse-index mirror backend.
Package cargo implements the Cargo sparse-index mirror backend.
composer
Package composer implements the Composer / Packagist mirror backend.
Package composer implements the Composer / Packagist mirror backend.
dns
Package dns implements DNS-provider-based mirror testing: resolve a mirror's hostname through different resolvers (UDP, DoH, DoT, or the system) and probe connectivity to the mirror via each provider's IPs.
Package dns implements DNS-provider-based mirror testing: resolve a mirror's hostname through different resolvers (UDP, DoH, DoT, or the system) and probe connectivity to the mirror via each provider's IPs.
docker
Package docker implements the OCI / Docker registry mirror backend.
Package docker implements the OCI / Docker registry mirror backend.
gomod
Package gomod implements the Go module proxy (GOPROXY protocol) backend.
Package gomod implements the Go module proxy (GOPROXY protocol) backend.
httpx
Package httpx provides shared HTTP plumbing for mirava-core backends: URL joining, the shared default client, User-Agent construction, and a single speed-measurement loop used by every backend's Speed probe.
Package httpx provides shared HTTP plumbing for mirava-core backends: URL joining, the shared default client, User-Agent construction, and a single speed-measurement loop used by every backend's Speed probe.
npm
Package npm implements the npm registry mirror backend.
Package npm implements the npm registry mirror backend.
pacman
Package pacman implements the Arch Linux mirror backend.
Package pacman implements the Arch Linux mirror backend.
pypi
Package pypi implements the PyPI (PEP 503 simple index) mirror backend.
Package pypi implements the PyPI (PEP 503 simple index) mirror backend.
pkg
apt
Package apt implements APT mirror internals.
Package apt implements APT mirror internals.

Jump to

Keyboard shortcuts

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