resources

package
v0.22.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2020 License: BSD-3-Clause Imports: 12 Imported by: 0

README

Package github.com/ooni/probe-engine/resources

This package contains code to download OONI resources.

Documentation

Overview

Package resources contains code to download resources.

Index

Constants

View Source
const (
	// Version contains the assets version.
	Version = 20201207105127

	// ASNDatabaseName is the ASN-DB file name
	ASNDatabaseName = "asn.mmdb"

	// CountryDatabaseName is country-DB file name
	CountryDatabaseName = "country.mmdb"

	// BaseURL is the asset's repository base URL
	BaseURL = "https://github.com/"
)

Variables

View Source
var All = map[string]ResourceInfo{
	"asn.mmdb": {
		URLPath:  "/ooni/probe-assets/releases/download/20201207105127/asn.mmdb.gz",
		GzSHA256: "797f875415692d1c0dd4c2e87edefc2e4f37e477b296816ab86c96316faa6a9b",
		SHA256:   "9f8c85ee924d657a25ae0ce98b0b87ff5ff082f0acc57a119bae2d29af106ea4",
	},
	"country.mmdb": {
		URLPath:  "/ooni/probe-assets/releases/download/20201207105127/country.mmdb.gz",
		GzSHA256: "8ba25a0f64151e327c2877e2521eebd1db33ca85918e78861af1d03d5dcaeb8b",
		SHA256:   "87c4a2446e2dc2e29d272d3877a6ba5fb7a5cf551dfe705db13f5a5e63a32cf3",
	},
}

All contains info on all known assets.

Functions

This section is empty.

Types

type Client

type Client struct {
	// HTTPClient is the HTTP client to use.
	HTTPClient *http.Client

	// Logger is the logger to use.
	Logger model.Logger

	// OSMkdirAll allows testing os.MkdirAll failures.
	OSMkdirAll func(path string, perm os.FileMode) error

	// UserAgent is the user agent to use.
	UserAgent string

	// WorkDir is the directory where to save resources.
	WorkDir string
}

Client is a client for fetching resources.

func (*Client) Ensure

func (c *Client) Ensure(ctx context.Context) error

Ensure ensures that resources are downloaded and current.

func (*Client) EnsureForSingleResource

func (c *Client) EnsureForSingleResource(
	ctx context.Context, name string, resource ResourceInfo,
	equal func(real, expected string) bool,
	gzipNewReader func(r io.Reader) (*gzip.Reader, error),
	ioutilReadAll func(r io.Reader) ([]byte, error),
) error

EnsureForSingleResource ensures that a single resource is downloaded and is current.

type ResourceInfo

type ResourceInfo struct {
	// URLPath is the resource's URL path.
	URLPath string

	// GzSHA256 is used to validate the downloaded file.
	GzSHA256 string

	// SHA256 is used to check whether the assets file
	// stored locally is still up-to-date.
	SHA256 string
}

ResourceInfo contains information on a resource.

Jump to

Keyboard shortcuts

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