tunnel

package
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package tunnel publishes a local HTTP listener on a public https URL through a third-party connector, so devices that cannot route to the host (a phone on cellular, a laptop on another network) can still enroll and join the mesh. Providers wrap external programs; the mesh only learns the resulting URL, which it advertises exactly like a configured external URL.

Index

Constants

View Source
const CloudflaredLicenseURL = "https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/license/"

CloudflaredLicenseURL is what a user accepts by installing cloudflared.

View Source
const CloudflaredVersion = "2026.9.1"

CloudflaredVersion is the cloudflared release this build knows how to install. Bump it together with cloudflaredAssets: the digests are the only thing standing between "download from GitHub" and "run whatever answered".

View Source
const DefaultCloudflaredReleaseURL = "https://github.com/cloudflare/cloudflared/releases/download/"

DefaultCloudflaredReleaseURL is the GitHub releases download prefix.

Variables

View Source
var ErrCloudflaredUnavailable = errors.New("cloudflared not found")

ErrCloudflaredUnavailable is returned when no usable cloudflared exists and the provider was not allowed to install one.

Functions

func Names

func Names() []string

Names lists the registered providers.

Types

type Cloudflare

type Cloudflare struct {
	// Binary is an explicit cloudflared executable; when set, nothing else
	// is tried.
	Binary string
	// Timeout bounds how long Open waits for the URL and then for its
	// hostname to be published in DNS; defaults to 30s.
	Timeout time.Duration
	// InstallDir is where a downloaded cloudflared is kept (sam-one uses
	// <data-dir>/bin). Empty disables both the cache and downloads.
	InstallDir string
	// Consent is asked before downloading; installing cloudflared means
	// accepting Cloudflare's license, so this must be an explicit choice.
	// Nil never downloads.
	Consent func(version, url string) bool
	// ReleaseURL overrides the GitHub release download prefix (mirrors,
	// tests). The pinned digests still apply.
	ReleaseURL string
	// HTTPClient performs the download; nil uses a 10 minute timeout.
	HTTPClient *http.Client
	// LookupHost asks whether the assigned hostname exists yet; nil asks
	// the zone's authoritative nameserver (see authoritativeLookup). Tests
	// stub it.
	LookupHost func(ctx context.Context, host string) ([]string, error)
}

Cloudflare opens a TryCloudflare quick tunnel: `cloudflared tunnel --url <target>` publishes the target on a random https://*.trycloudflare.com subdomain with no account or login. Quick tunnels are a development convenience with no SLA; cloudflared prints the assigned URL on its log output, which is the only thing this provider parses.

The connector binary is resolved in order: Binary if set, `cloudflared` on PATH, a previously installed copy under InstallDir whose digest still matches the pin, and finally a fresh download of the pinned release, which happens only if Consent agrees. A cached copy that fails verification is never run.

func (*Cloudflare) Name

func (c *Cloudflare) Name() string

Name implements Provider.

func (*Cloudflare) Open

func (c *Cloudflare) Open(ctx context.Context, target string) (Tunnel, error)

Open implements Provider.

type Provider

type Provider interface {
	// Name is the operator-facing identifier (e.g. "cloudflare").
	Name() string
	// Open publishes target, a local http://host:port URL, and returns once
	// the public URL is known or ctx expires.
	Open(ctx context.Context, target string) (Tunnel, error)
}

Provider opens tunnels through one connector implementation.

func Lookup

func Lookup(name string) (Provider, error)

Lookup returns a fresh provider by name.

type Tunnel

type Tunnel interface {
	// URL is the public https base URL that reaches the local target.
	URL() string
	// Done is closed once the tunnel has stopped forwarding, for whatever
	// reason; Err then reports why (nil after Close).
	Done() <-chan struct{}
	Err() error
	// Close tears the tunnel down.
	Close() error
}

Tunnel is an open public endpoint forwarding to a local target.

Jump to

Keyboard shortcuts

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