share

package
v0.4.140 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 43 Imported by: ? modules, 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.

Documentation

Overview

Package share publishes apps of this box on the internet through the relay.

Index

Constants

View Source
const (
	DefaultACMEDirectory = "https://acme-v02.api.letsencrypt.org/directory"
	TOSURL               = "https://letsencrypt.org/repository/"
)
View Source
const GuardFile = "share-guard.json"

GuardFile is kept next to StateFile: the protection settings, the people and the secret.

View Source
const StateFile = "share.json"

StateFile is kept in the fleet's state directory, under the root.

View Source
const TunnelPath = "/v1/share/tunnel"

TunnelPath is the relay route a box dials to publish its apps.

Variables

View Source
var (
	ErrRelayNoShare   = errors.New("this relay does not support public sharing")
	ErrWaitMaster     = errors.New("waiting for the master to register this box at the relay")
	ErrNoName         = errors.New("this box has no public name yet")
	ErrNameTaken      = errors.New("this name is already taken")
	ErrNameReserved   = errors.New("this name is reserved")
	ErrNameRevoked    = errors.New("this name was revoked and cannot be used")
	ErrNameQuarantine = errors.New("this name was released recently and is not available yet")
	// ErrRelayRejected is a 400: the relay will never accept this request as sent.
	ErrRelayRejected = errors.New("the relay refused")
)
View Source
var (
	ErrTOS        = errors.New("the terms of service of Let's Encrypt must be accepted")
	ErrNameSet    = errors.New("this box already has a public name")
	ErrUnknownApp = errors.New("this app is not installed")
	ErrNoRelay    = errors.New("remote access is off: public sharing goes through its relay")
	ErrNoPort     = errors.New("this app has no web port to share")
)
View Source
var (
	// ErrBadLabel is Label's error.
	ErrBadLabel = errors.New("the app's name cannot be made into a DNS label")
	// ErrBadName is ValidName's error.
	ErrBadName = errors.New("a box name is 3 to 32 lowercase letters, digits or dashes, not starting or ending with a dash")
)
View Source
var Default = New("/")

Default is the box's own; main wires its funcs.

View Source
var ErrGatewayNoGuard = errors.New("the gateway on this box cannot protect shared apps")

ErrGatewayNoGuard is what a Gateway without the protection of shared apps gives: a 404 on /v1/gateway/guard.

View Source
var ErrGatewayNoShare = errors.New("the gateway on this box does not support public sharing yet")

ErrGatewayNoShare is what the gateway of a box without public sharing gives.

View Source
var ErrGuardPush = errors.New("the change is saved, but the Gateway has not taken it yet: it will be sent again")

ErrGuardPush is a change that is saved but that the Gateway has not taken: the resync pushes it again.

View Source
var ErrRelayPush = errors.New("the change is saved, but the relay has not taken it yet: it will be sent again")

ErrRelayPush is a relay setting that is saved but that the relay has not taken: the resync sends it again.

Functions

func CodeHash added in v0.4.114

func CodeHash(secret []byte, code string) string

CodeHash is the lowercase hex HMAC-SHA256 of the normalised code under secret.

func Label

func Label(composeName string) (string, error)

Label turns an app's compose name into the DNS label of its host.

func NewCode added in v0.4.114

func NewCode() string

NewCode is 12 random symbols shown as XXXX-XXXX-XXXX. Bytes of 248 and up are redrawn (248 = 8 x 31), so the modulo is unbiased.

func NormalizeCode added in v0.4.114

func NormalizeCode(s string) string

NormalizeCode uppercases ASCII letters and drops every character outside the code alphabet, like the Gateway.

func Serve

func Serve(ctx context.Context, s *Session, shareAddr func() (string, error)) int

Serve copies every accepted stream to a fresh TCP connection to the address shareAddr gives at that stream, at most maxStreams at a time (the others are closed at once), until the session ends or ctx is done. It returns the close code.

func ValidName

func ValidName(name string) error

ValidName reports whether name can be the name of a box.

Types

type ACME

type ACME struct {
	Directory         string // "" → CASAOS_SHARE_ACME_DIRECTORY or DefaultACMEDirectory
	CAFile            string // "" → CASAOS_SHARE_ACME_CA; a PEM root replacing the system pool (tests, Pebble)
	AccountFile       string // {"key": "<base64url P-256 PKCS8>"}
	KeyFile, CertFile string
	TXT               TXT
	Now               func() time.Time // nil → time.Now
	// contains filtered or unexported fields
}

ACME gets and renews the wildcard certificate of this box from Let's Encrypt by DNS-01.

func (*ACME) Loop

func (a *ACME) Loop(ctx context.Context, wildcard func() string, tick time.Duration)

Loop checks every tick and calls Obtain when Needs; after an error it waits an hour (measured with Now), doubling up to a day. An empty wildcard() means nothing is shared: idle.

func (*ACME) Needs

func (a *ACME) Needs(wildcard string, now time.Time) bool

Needs is true when there is no certificate for wildcard, or it expires within renewBefore.

func (*ACME) Obtain

func (a *ACME) Obtain(ctx context.Context, host string) (err error)

Obtain gets *.<host>: it writes KeyFile, then CertFile, only once the CA has issued.

func (*ACME) Status

func (a *ACME) Status() CertStatus

func (*ACME) Wake

func (a *ACME) Wake()

Wake makes Loop run its check now rather than at the next tick. It never blocks.

type App

type App struct {
	Port   string `json:"port"`
	Scheme string `json:"scheme"`
}

App is what an app that is shared is reached on.

type AppStatus

type AppStatus struct {
	Name   string `json:"name"`
	Label  string `json:"label"`
	Shared bool   `json:"shared"`
	URL    string `json:"url"`
	Port   string `json:"port"`
	Scheme string `json:"scheme"`
	Error  string `json:"error"`
}

type Apps

type Apps struct{ RuntimePath func() string }

Apps is AppManagement, reached through the runtime directory.

func (Apps) List

func (a Apps) List(ctx context.Context) ([]Installed, error)

List returns the installed apps, sorted by name.

type BanReport added in v0.4.115

type BanReport struct {
	Key    string    `json:"key"`
	Reason string    `json:"reason"`
	App    string    `json:"app"`
	Since  time.Time `json:"since"`
}

BanReport is one ban of this box's Gateway, as sent to the relay.

type BanRules added in v0.4.114

type BanRules struct {
	WAFHits     int `json:"waf_hits"`
	WAFWindowS  int `json:"waf_window_s"`
	Scan404     int `json:"scan_404"`
	ScanWindowS int `json:"scan_window_s"`
	RateStrikes int `json:"rate_strikes"`
	RateWindowS int `json:"rate_window_s"`
	CodeFails   int `json:"code_fails"`
	CodeWindowS int `json:"code_window_s"`
}

type BusyError

type BusyError struct{ RetryAfter time.Duration }

BusyError is the relay asking to come back later.

func (BusyError) Error

func (e BusyError) Error() string

type CertStatus

type CertStatus struct {
	NotAfter time.Time
	Pending  bool
	Error    string
	Names    []string
}

CertStatus is what the certificate on disk and the last attempt say.

type CertView

type CertView struct {
	NotAfter *time.Time `json:"not_after"`
	Pending  bool       `json:"pending"`
	Error    string     `json:"error"`
}

type Countries added in v0.4.114

type Countries struct {
	Mode string   `json:"mode"` // "none", "block", "allow"
	List []string `json:"list"` // ISO 3166-1 alpha-2, uppercase
}

type DialError

type DialError struct {
	StatusCode int
	RetryAfter time.Duration
	Err        error
}

DialError is a refused upgrade (401, 403, 429, 503...). StatusCode is 0 when the relay did not answer; RetryAfter comes from a 429's Retry-After header, 0 otherwise.

func (*DialError) Error

func (e *DialError) Error() string

func (*DialError) Unwrap

func (e *DialError) Unwrap() error

type ErrGuard added in v0.4.114

type ErrGuard struct{ Code string }

ErrGuard is a refusal the contract names: gateway_unsupported, bad_name, not_shared, not_found, unknown_app:<name>, bad_policy:<field>. Its message is the code.

func (ErrGuard) Error added in v0.4.114

func (e ErrGuard) Error() string

type ErrLabelTaken

type ErrLabelTaken struct{ Other string }

ErrLabelTaken is a Share refused because another shared app has the same address.

func (ErrLabelTaken) Error

func (e ErrLabelTaken) Error() string

type Gateway

type Gateway struct{ RuntimePath func() string }

Gateway is the box's gateway, reached through the runtime directory.

func (Gateway) DeleteHost

func (g Gateway) DeleteHost(ctx context.Context, host string) error

DeleteHost stops the gateway sending requests for host anywhere.

func (Gateway) GuardBans added in v0.4.114

func (g Gateway) GuardBans(ctx context.Context) (json.RawMessage, error)

GuardBans is the Gateway's active bans.

func (Gateway) GuardEvents added in v0.4.114

func (g Gateway) GuardEvents(ctx context.Context, app, reason string, limit int) (json.RawMessage, error)

GuardEvents is the Gateway's journal, newest first; empty filters and limit 0 are left out.

func (Gateway) GuardStatus added in v0.4.114

func (g Gateway) GuardStatus(ctx context.Context) (GuardGatewayStatus, bool, error)

GuardStatus is the Gateway's view of the protection; supported is false only when it has no guard route.

func (Gateway) Hosts added in v0.4.114

func (g Gateway) Hosts(ctx context.Context) ([]string, error)

Hosts is every host the gateway serves.

func (Gateway) SetGuard added in v0.4.114

func (g Gateway) SetGuard(ctx context.Context, cfg GatewayGuardConfig) error

SetGuard replaces the Gateway's whole protection config.

func (Gateway) SetHost

func (g Gateway) SetHost(ctx context.Context, host, target string) error

SetHost makes the gateway send requests for host to target.

func (Gateway) ShareAddr

func (g Gateway) ShareAddr() (string, error)

ShareAddr is the address the gateway hands the relay's connections to.

func (Gateway) Unban added in v0.4.114

func (g Gateway) Unban(ctx context.Context, key string) error

Unban lifts the ban on key now.

type GatewayGuardApp added in v0.4.114

type GatewayGuardApp struct {
	App    string `json:"app"`
	Access string `json:"access"`
	Policy Policy `json:"policy"` // the effective one: the Gateway never merges
}

type GatewayGuardConfig added in v0.4.114

type GatewayGuardConfig struct {
	Secret     []byte                     `json:"secret"` // base64 std in JSON
	Protection bool                       `json:"protection"`
	Apps       map[string]GatewayGuardApp `json:"apps"`
	People     []GatewayPerson            `json:"people"`
}

GatewayGuardConfig is the body of PUT /v1/gateway/guard; apps are keyed by the host registered for them.

type GatewayPerson added in v0.4.114

type GatewayPerson struct {
	ID       string   `json:"id"`
	Gen      int      `json:"gen"`
	CodeHash string   `json:"code_hash"`
	Apps     []string `json:"apps"`
}

GatewayPerson is what the Gateway needs of a person: no name, no dates.

type GeoFetcher added in v0.4.114

type GeoFetcher struct {
	Dir     string
	BaseURL string
	Client  *http.Client
	Now     func() time.Time
	// contains filtered or unexported fields
}

GeoFetcher keeps DB-IP Lite's country and network files current. The Gateway memory-maps them, so a file is only ever replaced by renaming a finished one over it.

func (*GeoFetcher) Stale added in v0.4.114

func (f *GeoFetcher) Stale() bool

Stale is whether a file is missing or older than 32 days.

func (*GeoFetcher) Status added in v0.4.114

func (f *GeoFetcher) Status() GeoStatus

Status reads the files' state; a missing file is false.

func (*GeoFetcher) Update added in v0.4.114

func (f *GeoFetcher) Update(ctx context.Context) error

Update downloads the files that are missing or stale. A file that fails keeps its old version; the first error is returned and kept.

type GeoStatus added in v0.4.114

type GeoStatus struct {
	Country, ASN bool
	UpdatedAt    time.Time // the older of the two files; zero when none
	Error        string
}

GeoStatus is what the files on disk are, and why the last update failed ("" when it did not).

type GuardApp added in v0.4.114

type GuardApp struct {
	Access   string          `json:"access"` // "open" or "code"
	Override *PolicyOverride `json:"override"`
}

type GuardAppView added in v0.4.114

type GuardAppView struct {
	Access    string          `json:"access"`
	Override  *PolicyOverride `json:"override"`
	Effective Policy          `json:"effective"`
}

type GuardGatewayStatus added in v0.4.114

type GuardGatewayStatus struct {
	Version    int  `json:"version"`
	Configured bool `json:"configured"`
	Geo        struct {
		Country bool `json:"country"`
		ASN     bool `json:"asn"`
	} `json:"geo"`
	PeopleLastUsed map[string]time.Time `json:"people_last_used"`
	Waves          []GuardWave          `json:"waves"`
}

GuardGatewayStatus is the body of GET /v1/gateway/guard.

type GuardGeo added in v0.4.114

type GuardGeo struct {
	Country   bool       `json:"country"`
	ASN       bool       `json:"asn"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
	Error     string     `json:"error"`
}

type GuardRelay added in v0.4.115

type GuardRelay struct {
	Supported        bool       `json:"supported"`
	Filter           bool       `json:"filter"`
	ShareBans        bool       `json:"share_bans"`
	ShareBansAt      *time.Time `json:"share_bans_at"`
	CommunitySize    int        `json:"community_size"`
	ContributedMonth int        `json:"contributed_month"`
}

GuardRelay is the relay's part of the protection: the settings are the owner's (the file), the numbers the relay's last answer, zero while it has none or has no such routes.

type GuardState added in v0.4.114

type GuardState struct {
	Secret     []byte              `json:"secret"`
	Protection bool                `json:"protection"`
	Box        Policy              `json:"box"`
	Apps       map[string]GuardApp `json:"apps"`
	People     []Person            `json:"people"`
	ResetAt    time.Time           `json:"reset_at,omitzero"` // the file was found unusable and reset; cleared by the owner's next write the Gateway takes

	RelayFilter *bool     `json:"relay_filter,omitempty"` // the relay refuses known-bad addresses at the door; nil (an old file) is on
	ShareBans   bool      `json:"share_bans"`             // this box's bans go to the other boxes, and theirs come back; the owner's consent
	ShareBansAt time.Time `json:"share_bans_at,omitzero"` // when ShareBans went on
}

type GuardView added in v0.4.114

type GuardView struct {
	Supported  bool                    `json:"supported"`
	Reason     string                  `json:"reason"`
	Reset      bool                    `json:"reset"`
	Protection bool                    `json:"protection"`
	Box        Policy                  `json:"box"`
	Apps       map[string]GuardAppView `json:"apps"` // the shared apps only
	People     []PersonView            `json:"people"`
	Geo        GuardGeo                `json:"geo"`
	Waves      []GuardWave             `json:"waves"`
	Relay      GuardRelay              `json:"relay"`
}

GuardView is the body of GET /v1/share/guard.

type GuardWave added in v0.4.114

type GuardWave struct {
	App  string `json:"app"`
	Bans int    `json:"bans"`
}

type Info

type Info struct {
	Name         string `json:"name"`
	Host         string `json:"host"`
	Domain       string `json:"domain"`
	TunnelOnline bool   `json:"tunnel_online"`
}

Info is a box's public name at the relay.

type Installed

type Installed struct{ Name, Title, Port, Scheme string }

Installed is an installed app, by its compose name.

type Person added in v0.4.114

type Person struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	Apps      []string  `json:"apps"`
	CodeHash  string    `json:"code_hash"`
	Gen       int       `json:"gen"`
	CreatedAt time.Time `json:"created_at"`
}

Person holds a hash of the access code, never the code.

type PersonView added in v0.4.114

type PersonView struct {
	ID         string     `json:"id"`
	Name       string     `json:"name"`
	Apps       []string   `json:"apps"`
	CreatedAt  time.Time  `json:"created_at"`
	LastUsedAt *time.Time `json:"last_used_at,omitempty"`
}

PersonView is a person without the hash of the code.

type Policy added in v0.4.114

type Policy struct {
	WAF        string    `json:"waf"` // "off", "observe", "block"
	RulesOff   []int     `json:"rules_off"`
	Allow      []string  `json:"allow"`
	Block      []string  `json:"block"`
	Countries  Countries `json:"countries"`
	RatePerMin int       `json:"rate_per_min"`
	Ban        BanRules  `json:"ban"`
}

Policy, Countries and BanRules have the JSON shape of the Gateway's pkg/guard config.

func DefaultPolicy added in v0.4.114

func DefaultPolicy() Policy

func Effective added in v0.4.114

func Effective(box Policy, o *PolicyOverride) Policy

Effective is the policy an app runs under: the box's, with the override's lists added and its other set fields replacing.

func (Policy) Validate added in v0.4.114

func (p Policy) Validate() error

Validate refuses what the Gateway would: the error is bad_policy:<field>.

type PolicyOverride added in v0.4.114

type PolicyOverride struct {
	WAF        *string    `json:"waf"`
	RulesOff   []int      `json:"rules_off"`
	Allow      []string   `json:"allow"`
	Block      []string   `json:"block"`
	Countries  *Countries `json:"countries"`
	RatePerMin *int       `json:"rate_per_min"`
	Ban        *BanRules  `json:"ban"`
}

PolicyOverride is an app's own settings: nil follows the box; the lists add to the box's, the rest replace.

type Relay

type Relay struct {
	// Signed sends a request signed with this box's key (wired by main to the fleet's relay client), keeping at most
	// maxReply bytes of the answer (0: the client's 64 KiB).
	Signed func(ctx context.Context, method, path string, body []byte, maxReply int) (status int, reply []byte, retryAfter time.Duration, err error)
	// RegisterSelf links this box's key at the relay (wired to the fleet).
	RegisterSelf func(ctx context.Context) error
	// contains filtered or unexported fields
}

Relay talks to the relay as this box.

func (*Relay) ClaimName

func (r *Relay) ClaimName(ctx context.Context, name string) (Info, error)

ClaimName asks for name as this box's public name.

func (*Relay) ClearTXT

func (r *Relay) ClearTXT(ctx context.Context) error

ClearTXT removes the ACME challenge record.

func (*Relay) Refusals added in v0.4.115

func (r *Relay) Refusals(ctx context.Context) (json.RawMessage, error)

Refusals returns the relay's refusals of this box's name over the last 7 days, as the relay wrote them.

func (*Relay) ReleaseName

func (r *Relay) ReleaseName(ctx context.Context) error

ReleaseName gives the public name back (also fine when there was none).

func (*Relay) ReportBans added in v0.4.115

func (r *Relay) ReportBans(ctx context.Context, bans []BanReport) error

ReportBans sends the bans this box's Gateway started; ErrRelayRejected means drop the batch.

func (*Relay) SetProtection added in v0.4.115

func (r *Relay) SetProtection(ctx context.Context, filter, shareBans bool) (RelayProtection, error)

SetProtection pushes the two protection settings to the relay.

func (*Relay) SetTXT

func (r *Relay) SetTXT(ctx context.Context, value string) error

SetTXT publishes value as the ACME challenge record of this box's name.

func (*Relay) Status

func (r *Relay) Status(ctx context.Context) (Info, error)

Status tells what the relay knows of this box's name and tunnel.

type RelayProtection added in v0.4.115

type RelayProtection struct {
	Filter           bool       `json:"relay_filter"`
	ShareBans        bool       `json:"share_bans"`
	ShareBansAt      *time.Time `json:"share_bans_at"`
	CommunitySize    int        `json:"community_size"`
	ContributedMonth int        `json:"contributed_month"`
}

RelayProtection is what the relay holds of this box's protection settings.

type Service

type Service struct {
	Root        string
	RuntimePath func() string
	Relay       *Relay
	Gateway     Gateway
	Apps        Apps
	ACME        *ACME
	Geo         *GeoFetcher
	BoxKey      func() (ed25519.PrivateKey, error)
	RelayURL    func() (string, bool)
	Dialer      *websocket.Dialer // nil → Dial's default
	Log         func(msg string, err error)
	Now         func() time.Time
	Alert       func(key, sentence string, problem bool) // nil: no alerts; pkg/alerts' ShareGuardProblem
	// contains filtered or unexported fields
}

Service shares the apps of this box: its name at the relay, the Gateway's host routes, the tunnel and the certificate.

func New

func New(root string) *Service

New keeps the state and the certificate under root.

func (*Service) AddPerson added in v0.4.114

func (s *Service) AddPerson(ctx context.Context, name string, apps []string) (PersonView, string, error)

AddPerson adds a person with a first code, which this answer is the only place to show.

func (*Service) DeletePerson added in v0.4.114

func (s *Service) DeletePerson(ctx context.Context, id string) error

func (*Service) GuardBans added in v0.4.114

func (s *Service) GuardBans(ctx context.Context) (json.RawMessage, error)

GuardBans is the Gateway's active bans.

func (*Service) GuardEvents added in v0.4.114

func (s *Service) GuardEvents(ctx context.Context, app, reason string, limit int) (json.RawMessage, error)

GuardEvents is the Gateway's journal, newest first, filtered by compose name and reason.

func (*Service) GuardReset added in v0.4.114

func (s *Service) GuardReset() bool

GuardReset is whether share-guard.json was found unusable and reset, until the owner's next write the Gateway takes.

func (*Service) GuardView added in v0.4.114

func (s *Service) GuardView(ctx context.Context) (GuardView, error)

GuardView is the protection as the dashboard shows it. It takes no ops lock; a Gateway that cannot be asked gives the view without its last uses and waves. A guard file that cannot be read is an error, not a view of the placeholder.

func (*Service) NewPersonCode added in v0.4.114

func (s *Service) NewPersonCode(ctx context.Context, id string) (string, error)

NewPersonCode replaces a person's code: the old one stops working, and the new one is shown here only.

func (*Service) OnAppEvent

func (s *Service) OnAppEvent(name string, properties map[string]string)

OnAppEvent follows AppManagement (Hub.OnAppEvent). It returns at once.

func (*Service) RelayRefusals added in v0.4.115

func (s *Service) RelayRefusals(ctx context.Context) (json.RawMessage, error)

RelayRefusals is what the relay refused at its door for this box's name over a week; a relay without the route gives [].

func (*Service) Reset

func (s *Service) Reset(ctx context.Context)

Reset forgets the sharing of a box leaving its relay: the host routes are deleted first (local and fast), then the name is released, best effort, then the tunnel stopped and the state cleared. The certificate stays. Ban sharing ends with the relay it was agreed for. It runs while the fleet holds its relay lock: it only calls the relay's Signed and the Gateway. It does not wait for the operation under way, which may register a host after these deletes: the resync that clear wakes deletes what is left (sweep).

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run keeps the host routes, the tunnel and the certificate until ctx is done. Without a name and an app shared, nothing goes out. A second Run while one is under way returns at once.

func (*Service) SetAppGuard added in v0.4.114

func (s *Service) SetAppGuard(ctx context.Context, name, access string, o *PolicyOverride) (GuardView, error)

SetAppGuard sets who may enter a shared app ("open" or "code") and its own settings (nil: follow the box).

func (*Service) SetBoxPolicy added in v0.4.114

func (s *Service) SetBoxPolicy(ctx context.Context, p Policy) (GuardView, error)

SetBoxPolicy replaces the box's policy; absent lists are empty ones.

func (*Service) SetName

func (s *Service) SetName(ctx context.Context, name string, acceptTOS bool) error

SetName claims name at the relay and saves it. The tunnel waits for an app to be shared.

func (*Service) SetProtection added in v0.4.114

func (s *Service) SetProtection(ctx context.Context, on bool) (GuardView, error)

func (*Service) SetRelay added in v0.4.115

func (s *Service) SetRelay(ctx context.Context, filter, shareBans *bool, consent bool) (GuardView, error)

SetRelay changes the relay's two settings: filtering, and sharing this box's bans (which needs the owner's consent). A nil one is left as it is. The change is saved, then sent to the relay at once; a relay without the routes (too old) undoes it, and one that cannot take it yet (failing, or waiting for the master) leaves it for the resync to send.

func (*Service) Share

func (s *Service) Share(ctx context.Context, composeName string) error

Share publishes an installed app at https://<label>.<host>.

func (*Service) Status

func (s *Service) Status(ctx context.Context) Status

func (*Service) StopAll

func (s *Service) StopAll(ctx context.Context) error

StopAll unshares every app; the name stays.

func (*Service) Unban added in v0.4.114

func (s *Service) Unban(ctx context.Context, key string) error

Unban lifts the ban on key, as the router gave it (unescaped once): the Gateway call escapes it again.

func (*Service) Unshare

func (s *Service) Unshare(ctx context.Context, composeName string) error

Unshare stops publishing an app; an app that is not shared is fine.

func (*Service) UpdatePerson added in v0.4.114

func (s *Service) UpdatePerson(ctx context.Context, id, name string, apps []string) (PersonView, error)

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session is the box end of a tunnel. The relay opens the streams, so there is no Open: the relay drops the tunnel of a box that opens one.

func Dial

func Dial(ctx context.Context, relayURL string, key ed25519.PrivateKey, d *websocket.Dialer) (*Session, error)

Dial opens the tunnel to relayURL (https://host, or http:// in tests), signing GET TunnelPath with key. d nil means a dialer with a 15 s handshake timeout that honours the proxy environment.

func (*Session) Accept

func (s *Session) Accept() (net.Conn, error)

Accept returns the next visitor stream; it fails once the tunnel is closed.

func (*Session) Close

func (s *Session) Close() error

Close ends the tunnel and its streams.

func (*Session) CloseCode

func (s *Session) CloseCode() int

CloseCode is the code the relay closed the tunnel with: 4403 revoked, 4409 replaced, 1001 shutdown, 0 otherwise (network drop, local close, normal closure).

type State

type State struct {
	Name          string         `json:"name"`
	Host          string         `json:"host"`
	Domain        string         `json:"domain"`
	TOSAcceptedAt time.Time      `json:"tos_accepted_at,omitzero"`
	Apps          map[string]App `json:"apps"`
	Revoked       bool           `json:"revoked,omitempty"` // the relay closed the tunnel with 4403: no dial until a Share
}

State is what this box shares, as saved in StateFile.

type Status

type Status struct {
	Supported bool        `json:"supported"`
	Reason    string      `json:"reason"` // remote-access, gateway, relay, master
	Name      string      `json:"name"`
	Host      string      `json:"host"`
	Domain    string      `json:"domain"`
	TOSURL    string      `json:"tos_url"`
	Apps      []AppStatus `json:"apps"`
	Cert      CertView    `json:"cert"`
	Tunnel    TunnelView  `json:"tunnel"`
}

Status is what the API answers.

type TXT

type TXT interface {
	SetTXT(ctx context.Context, value string) error
	ClearTXT(ctx context.Context) error
}

TXT publishes the DNS-01 record through the relay (a *Relay does).

type TunnelView

type TunnelView struct {
	Connected bool   `json:"connected"`
	Error     string `json:"error"`
}

Jump to

Keyboard shortcuts

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