Documentation
¶
Overview ¶
Package vpndetection is the official Go client library for the VPNDetection API: anonymity detection covering VPNs, residential proxies, Tor nodes, hosting servers, CDNs and relays.
Start with New and Client.Lookup. No API key is needed: the free tier answers ip and is_vpn and allows 1000 requests per day per source address.
Index ¶
- Constants
- func BoolValue(v *bool) bool
- func IsBogon(ip string) bool
- type BatchOption
- type BatchResult
- type Checksums
- type ClassDetail
- type Client
- type Database
- func (d *Database) Checksums(ctx context.Context, id string, format Format) (*Checksums, error)
- func (d *Database) Download(ctx context.Context, id string, format Format, dst io.Writer) (int64, error)
- func (d *Database) DownloadBytes(ctx context.Context, id string, format Format) ([]byte, error)
- func (d *Database) DownloadFile(ctx context.Context, id string, format Format, path string) (int64, error)
- func (d *Database) DownloadURL(ctx context.Context, id string, format Format) (string, error)
- func (d *Database) Downloads(ctx context.Context, limit int) ([]Download, error)
- func (d *Database) List(ctx context.Context) ([]LicensedDataset, error)
- func (d *Database) Metadata(ctx context.Context, id string) (*DatasetMetadata, error)
- type DatasetFormatSize
- type DatasetMetadata
- type DatasetMetadataColumn
- type Date
- type Download
- type DownloadOutcome
- type Error
- type ErrorKind
- type Format
- type LicenseType
- type LicensedDataset
- type LicensedVersion
- type LookupOption
- type LookupResponse
- type Option
- type ProxyDetail
- type Result
- type SampleFormat
- type Standing
- type VpnDetail
Constants ¶
const ( LicenseTypeEvaluation = api.Evaluation LicenseTypeStandard = api.Standard LicenseTypeRedistribute = api.Redistribute )
const ( StandingExpired = api.LicensedDatasetStandingExpired StandingLicensed = api.LicensedDatasetStandingLicensed StandingUnlicensed = api.LicensedDatasetStandingUnlicensed )
const ( DownloadOutcomeOK = api.DownloadOutcomeOk DownloadOutcomeDenied = api.DownloadOutcomeDenied DownloadOutcomeExpired = api.DownloadOutcomeExpired DownloadOutcomeUnknown = api.DownloadOutcomeUnknown )
const DefaultBaseURL = "https://api.vpndetection.io"
DefaultBaseURL is the production API. Override it with WithBaseURL.
Variables ¶
This section is empty.
Functions ¶
func BoolValue ¶
BoolValue returns the value of the bool pointer passed in, or false if the pointer is nil.
Go has no `??`, so this is how a caller who only wants to know whether an address is flagged reads a tier-gated member: BoolValue(r.IsHosting). Read the pointer itself wherever absent and false must be told apart, which is the whole reason these are pointers. Same name and behaviour as stripe-go's helper of the same name, so it should already be familiar.
func IsBogon ¶
IsBogon reports whether an address is private, loopback, link-local, documentation, multicast or otherwise not routable on the public internet, including the IPv6 equivalents and the 6to4 and Teredo ranges that wrap them.
These can never be VPN or proxy infrastructure, so the client answers them itself and they never cost a request. Client.IsBogon is the same check, for code that already holds a client.
Types ¶
type BatchOption ¶
type BatchOption interface {
// contains filtered or unexported methods
}
BatchOption overrides a client default for one batch. Options that only mean something for a batch are BatchOption alone, so passing one to Lookup does not compile rather than being accepted and ignored.
func Concurrency ¶
func Concurrency(n int) BatchOption
Concurrency overrides the client's in-flight request limit for this batch, so one large batch does not need a second client to widen it.
type BatchResult ¶
BatchResult is one address's outcome within a batch. Exactly one of Result and Err is set.
type Checksums ¶
type Checksums struct {
MD5 string `json:"md5,omitempty"`
SHA1 string `json:"sha1,omitempty"`
SHA256 string `json:"sha256,omitempty"`
SHA512 string `json:"sha512,omitempty"`
}
Checksums of one published dataset file. A digest the exporter did not write is an empty string.
type ClassDetail ¶
type ClassDetail = api.ClassDetail
The wire shapes a lookup answers with, re-exported so a consumer never has to name an internal package.
type Client ¶
type Client struct {
// Database is the licensed dataset downloads, for keys that carry the
// db.download scope.
Database *Database
// contains filtered or unexported fields
}
Client is a client for the VPNDetection API. It is safe for concurrent use.
The cache is per instance and never global: two clients holding different API keys are on different plans and entitled to different fields, so a shared cache would serve one of them the other's shape.
func (*Client) IsBogon ¶
IsBogon reports whether an address is answered locally rather than served. Exposed here so the check is reachable from the client you already hold; the package-level IsBogon is the same function.
func (*Client) Lookup ¶
Lookup classifies one address.
A bogon is answered locally and never reaches the network. Everything else is served, then cached for this client. Treat the answer as read only: repeat lookups of one address hand back the same cached pointers.
func (*Client) LookupBatch ¶
func (c *Client) LookupBatch( ctx context.Context, ips []string, opts ...BatchOption, ) (map[string]BatchResult, error)
LookupBatch classifies many addresses concurrently.
The answers are keyed by address rather than positional, so duplicates in the input collapse to a single request and the caller never has to line two lists up. An address that fails carries its error as its value, so one bad entry cannot lose the rest of the answers. The returned error is reserved for the batch as a whole failing, which today means the context was canceled.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database is the licensed dataset downloads. Access is granted by contract rather than self-serve, and needs a key carrying the db.download scope.
func (*Database) Checksums ¶
Checksums are the digests of one published file, for verifying a download.
func (*Database) Download ¶
func (d *Database) Download( ctx context.Context, id string, format Format, dst io.Writer, ) (int64, error)
Download streams one dataset file into dst and returns the bytes written.
Nothing beyond a single chunk is ever held in memory, whatever the dataset weighs. The transfer takes its deadline from ctx rather than from the HTTP client's Timeout, which would cap the whole body: 30 seconds is a sane bound on a lookup and the wrong one on a gigabyte.
A failure DURING the transfer is returned as it happened rather than wrapped in an *Error: a reset socket and a full disk are different problems, and only one of them is ours.
func (*Database) DownloadBytes ¶
DownloadBytes downloads one dataset file and hands back its bytes.
This holds the ENTIRE file in memory, and the catalog spans five orders of magnitude, from cdn_ip_v1 at 10 KB to resproxy_ip_90d_v1 at 1.79 GB, so reach for it at the small end and use Download or DownloadFile for anything you have not measured.
func (*Database) DownloadFile ¶
func (d *Database) DownloadFile( ctx context.Context, id string, format Format, path string, ) (int64, error)
DownloadFile writes one dataset file to path and returns the bytes written.
The bytes land in a neighboring .part file that is renamed on completion, so a transfer that dies half way leaves no truncated file that reads as a whole dataset. Otherwise identical to Download.
func (*Database) DownloadURL ¶
DownloadURL is the time-limited URL for one dataset file.
The API answers 302 to object storage. The URL is returned rather than the bytes so the caller decides how to transfer a file that routinely runs to gigabytes; the link authorizes the START of a transfer, so one already running is not interrupted when it lapses.
func (*Database) Downloads ¶
Downloads is your organization's recent download attempts, newest first. A limit of zero or less takes the API's own default.
func (*Database) List ¶
func (d *Database) List(ctx context.Context) ([]LicensedDataset, error)
List is the dataset families your organization is licensed to download. A license covers a family, while a download names one of its versions, so the ids Download and Checksums take come from LicensedDataset.Versions.
type DatasetFormatSize ¶
type DatasetFormatSize = api.DatasetFormatSize
The dataset shapes, re-exported so a consumer never has to name an internal package.
type DatasetMetadata ¶
type DatasetMetadata = api.DatasetMetadata
The dataset shapes, re-exported so a consumer never has to name an internal package.
type DatasetMetadataColumn ¶
type DatasetMetadataColumn = api.DatasetMetadataColumn
The dataset shapes, re-exported so a consumer never has to name an internal package.
type Download ¶
The dataset shapes, re-exported so a consumer never has to name an internal package.
type DownloadOutcome ¶
type DownloadOutcome = api.DownloadOutcome
DownloadOutcome is how one download attempt ended.
type Error ¶
type Error struct {
Kind ErrorKind
// Message is the API's own explanation, or a transport failure's text.
Message string
// StatusCode is the HTTP status, or 0 when no response was received.
StatusCode int
// RetryAfter is how long the server asked us to wait. Zero when it did not
// ask, which on a 429 means an allowance is spent rather than throttled.
RetryAfter time.Duration
// contains filtered or unexported fields
}
Error is what every failure from this package unwraps to. Recover it with errors.As and branch on Kind.
type ErrorKind ¶
type ErrorKind string
ErrorKind says why a request failed.
KindRateLimited and KindQuotaExceeded both arrive as HTTP 429 and are NOT the same thing. A rate limit is the API protecting itself, carries Retry-After, and retrying works. A spent quota carries no such header and retrying will not help until the window rolls over or the limit is raised. The header is the only thing that distinguishes them.
type Format ¶
type Format string
Format is a format a dataset is published in. Not every dataset is built in every format: the _provider catalogs are keyed by provider id rather than by IP range, so no MMDB exists for them.
type LicenseType ¶ added in v1.2.0
type LicenseType = api.LicensedDatasetLicenseType
LicenseType is what a license permits you to do with the data.
type LicensedDataset ¶
type LicensedDataset = api.LicensedDataset
The dataset shapes, re-exported so a consumer never has to name an internal package.
type LicensedVersion ¶
type LicensedVersion = api.LicensedVersion
LicensedVersion is one published version of a licensed family. Its ID is what the download and checksum calls take.
type LookupOption ¶
type LookupOption interface {
BatchOption
// contains filtered or unexported methods
}
LookupOption overrides a client default for one call. Every LookupOption works on a batch too.
func Retries ¶
func Retries(n int) LookupOption
Retries overrides the client's retry count for this call.
type LookupResponse ¶
type LookupResponse = api.LookupResponse
The wire shapes a lookup answers with, re-exported so a consumer never has to name an internal package.
type Option ¶
type Option func(*config) error
Option configures a Client.
func WithAPIKey ¶
WithAPIKey authenticates as the key's organization. Which fields a lookup answers with, and how many requests are allowed, follow the key's plan.
func WithBaseURL ¶
WithBaseURL points the client at a different deployment of the API.
func WithCache ¶
WithCache sizes the per-client answer cache. Defaults are 10000 addresses and a one hour TTL.
func WithConcurrency ¶
WithConcurrency sets how many requests a batch keeps in flight. Default 8.
func WithHTTPClient ¶
WithHTTPClient supplies the HTTP client to send with, for a custom transport, proxy or timeout. Without it the SDK uses a client with a 30 second timeout.
The client is copied rather than mutated, and the copy adds a CheckRedirect that defers to yours (see Database.DownloadURL). A dataset transfer runs on a second copy with Timeout cleared, and is bounded by its context instead.
func WithRetries ¶
WithRetries sets how many further attempts a transient failure gets. Default 2.
func WithoutCache ¶
func WithoutCache() Option
WithoutCache turns caching off, so every lookup of a non-bogon address is served.
type ProxyDetail ¶
type ProxyDetail = api.ProxyDetail
The wire shapes a lookup answers with, re-exported so a consumer never has to name an internal package.
type Result ¶
type Result struct {
// The answer as it was served, with the wire's own optionality intact. Its
// fields are promoted, so r.IsVpn and r.Vpn read straight off the Result.
LookupResponse
// True when this answer was computed locally rather than served, which
// happens for a bogon and only for a bogon.
IsBogon bool `json:"is_bogon"`
}
Result is what a lookup answers.
A pointer member is one your plan does not include. It never means "we could not check", so nil and false are genuinely different answers: nil is "not in your plan", false is "checked, and no". BoolValue collapses the two for callers who only want to know whether an address is flagged.
A detail object that is present but empty means the flag above it is false. A populated one always carries every one of its keys, empty values included.
type SampleFormat ¶
type SampleFormat = api.LicensedVersionSampleFormats
SampleFormat is a format an evaluation sample is published in.
type Standing ¶
type Standing = api.LicensedDatasetStanding
Standing is where a license stands: live, lapsed, or never bought.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
api
Package api provides primitives to interact with the openapi HTTP API.
|
Package api provides primitives to interact with the openapi HTTP API. |
|
Package middleware holds the framework-agnostic half of a web middleware: resolve a client address, classify it, and decide whether to block.
|
Package middleware holds the framework-agnostic half of a web middleware: resolve a client address, classify it, and decide whether to block. |