customhost

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package customhost decides whose a custom host is. The instance serves hosts for workspaces: the public pages and website domain, the SMS short-link domain, a link tracking domain and the push site of a publication website. A CNAME to the instance, or addresses matching it, only show that a host points at this server, not whose host it is, so a host belongs to one workspace: the first to use it. Any other workspace, and any workspace for a host under the instance's own address (where one wildcard record can point every name at the server), shows that a host is its own only with the TXT record _reputecast.<host>, whose value is that workspace's alone. The instance's own hosts are never a workspace's.

Every use of a host goes through here, so the pages, the short links and link tracking can't each draw the line in a different place.

Index

Constants

View Source
const PurposeInstance = "instance"

PurposeInstance is the purpose of a store.CustomHostClaims row for one of the instance's own hosts (its SMTP relay's).

Variables

This section is empty.

Functions

func HasToken

func HasToken(ctx context.Context, dns dnscheck.Resolver, workspace uuid.UUID, host string) (found, answered bool)

HasToken looks up host's TXT record and reports whether it holds workspace's token. answered is false when DNS gave no answer (a timeout, a failing server), which shows nothing either way; a name with no such record is an answer.

func RequestHost

func RequestHost(host string) string

RequestHost is the host of a request's Host header: lower case, without its port or a final dot.

func TXTName

func TXTName(host string) string

TXTName is where the TXT record that shows host is a workspace's lives.

func TakenBefore

func TakenBefore(c store.CustomHostClaimsRow, held *time.Time) bool

TakenBefore reports whether another workspace's use of a host keeps a workspace from it: any use while the workspace hasn't verified the host (held is nil), and afterwards one proven before the workspace's or at a time nobody recorded. A use proven later, or never, came second.

func Token

func Token(workspace uuid.UUID, host string) string

Token is the value of that TXT record for workspace: a hash of the workspace and the host, so it proves nothing for any other workspace or any other host.

Types

type Holder

type Holder struct {
	ID   uuid.UUID
	Slug string
}

Holder is a workspace that holds a host.

type Hosts

type Hosts struct {
	Q *store.Queries
	// Instance returns the instance's public URL, whose host is nobody's.
	Instance func() string
	Now      func() time.Time
	// contains filtered or unexported fields
}

Hosts says whose host a request came to, for what answers on every host that points at the instance: link tracking (/t/o, /t/c, /t/h), short links (/t/s), push clicks (/t/p) and a workspace's pages under /p/{workspace}. On a host a workspace holds (its verified custom domain, short-link domain or link tracking domain, or its publication website) only that workspace's links and pages answer: another workspace's would look as if they came from the host's owner, and could send people anywhere under its name. Any other host, the instance's own or one that nobody holds now, answers for every workspace, so links in mail already sent keep working: a workspace's links only ever name its own hosts and the instance's, and a host it stops using holds nobody else's.

A nil Hosts answers for every workspace on every host.

func (*Hosts) Carries

func (h *Hosts) Carries(ctx context.Context, host string, workspace uuid.UUID) (bool, error)

Carries reports whether host (a Host header) may carry workspace's links and pages: it is one of workspace's hosts, or nobody's.

func (*Hosts) CarriesSlug

func (h *Hosts) CarriesSlug(ctx context.Context, host, slug string) (bool, error)

CarriesSlug is Carries for the workspace a path names by its slug.

func (*Hosts) Holders

func (h *Hosts) Holders(ctx context.Context, host string) ([]Holder, error)

Holders returns the workspaces that hold host (a Host header): none for the instance's own host and for a host nobody holds.

type Proof

type Proof int

Proof is what can show, at a check, that a host is a workspace's.

const (
	// Records: whatever the use checks shows it (a CNAME to the instance,
	// matching addresses, the TXT record).
	Records Proof = iota
	// InUse: another workspace used the host first, so only the TXT record
	// shows it.
	InUse
	// UnderInstance: the host is under the instance's own address, so only
	// the TXT record shows it.
	UnderInstance
	// Never: one of the instance's own hosts, which nothing makes a
	// workspace's.
	Never
)

func ProofFor

func ProofFor(ctx context.Context, q *store.Queries, workspace uuid.UUID, host, instance string, held *time.Time) (Proof, error)

ProofFor says what can show that host is workspace's. instance is the host of the instance's public URL. held is since when the workspace has had host verified for the use being checked (nil while it hasn't): a use another workspace made later takes nothing away.

func (Proof) TXTOnly

func (p Proof) TXTOnly() bool

TXTOnly reports whether only the TXT record shows the host is the workspace's.

type Use

type Use int

Use is who else uses a host that a workspace saves.

const (
	// Free: nobody else uses the host.
	Free Use = iota
	// Instance: the host is one of the instance's own.
	Instance
	// Taken: another workspace uses the host, whatever its status there.
	Taken
)

func Claim

func Claim(ctx context.Context, q *store.Queries, workspace uuid.UUID, host string) (Use, error)

Claim says who else uses host as workspace saves it; only a Free host may be saved. It locks the host for the rest of q's transaction first, so two workspaces saving it at once can't both find it free.

Jump to

Keyboard shortcuts

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