connect

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0 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 connect is the rendezvous service that lets the apps find a home server whose internet address changed, and the server's side of it.

It only ever carries addresses. Servers register the address the service sees them at; apps look a server up by its id and connect to it directly. No media, API calls or credentials pass through the service, and there is no relay to fall back to: when the internet can't reach a server, the server's Settings say what to change.

A server's id comes from its public key, so only that server can register addresses under its id, and ids can't be guessed. The service registers only the address a request comes from, never one it's told, so nobody can point a server's id, or the service's reachability check, at someone else's machine.

Index

Constants

View Source
const DefaultBillingURL = "https://yeix.io"

DefaultBillingURL is where Matinee Connect is bought: yeix.io opens a Stripe checkout for one server and its customer portal.

View Source
const DefaultURL = "https://connect.matinee.yeix.io"

DefaultURL is the service Yeix hosts for every Matinee server.

View Source
const Product = "matinee-connect"

Product is the Checkout Session metadata yeix.io marks a Matinee Connect subscription with; the session's server metadata is the server's id.

Variables

View Source
var (
	ErrNotPaid = errors.New("the checkout isn't paid yet")
	ErrEnded   = errors.New("the subscription has ended")
)

What Subscribe returns for a checkout that isn't paid, or a subscription that has ended (or a checkout that never was one).

Functions

func ID

func ID(pub ed25519.PublicKey) string

ID is the server id for public key pub: 24 characters of base32, 120 bits of the key's SHA-256.

func LoadKey

func LoadKey(path string) (ed25519.PrivateKey, error)

LoadKey reads the server's key from path, or makes and saves one. The server's id follows from it, so it's kept for good.

func NeedsSubscription

func NeedsSubscription(err error) bool

NeedsSubscription reports whether err is the service turning away a server without a paid subscription.

func ProofMessage

func ProofMessage(host string, nonce []byte) []byte

ProofMessage is what a server reached at host signs for an app's nonce. host is the address the app asked for, without a :443 port.

func Public

func Public(ip netip.Addr) bool

Public reports whether ip can be reached from the internet: not private, and not in the 100.64.0.0/10 range providers share among customers.

func URL

func URL(ip netip.Addr, port int) string

URL is the HTTPS address of ip on port.

Types

type Billing

type Billing struct {
	URL        string
	HTTPClient *http.Client
}

Billing is yeix.io's side of buying Matinee Connect.

func (*Billing) Checkout

func (b *Billing) Checkout(ctx context.Context, id, plan string) (Checkout, error)

Checkout opens a checkout for server id's subscription on plan.

func (*Billing) Plans

func (b *Billing) Plans(ctx context.Context) ([]Plan, error)

Plans lists what can be bought.

func (*Billing) Portal

func (b *Billing) Portal(ctx context.Context, session string) (string, error)

Portal opens Stripe's customer portal for the subscription session bought.

type Checked

type Checked struct {
	// IP is the address the request came from: the home's public address.
	IP string `json:"ip"`
	// Reachable means the service could open a connection to IP on the
	// port asked about.
	Reachable bool `json:"reachable"`
}

Checked is the service's answer to a reachability check.

type Checkout

type Checkout struct {
	URL       string `json:"url"`
	SessionID string `json:"session_id"`
	Expires   int64  `json:"expires"`
}

Checkout is an open Stripe checkout for a server's subscription.

type Client

type Client struct {
	URL        string // the service, such as DefaultURL
	Key        ed25519.PrivateKey
	HTTPClient *http.Client
}

Client is a server's side of the service.

func (*Client) Check

func (c *Client) Check(ctx context.Context, port int, pass string) (netip.Addr, bool, error)

Check asks the service for this home's public address and whether it can reach the server there on the router's external port.

func (*Client) ID

func (c *Client) ID() string

ID is this server's id.

func (*Client) LookupURL

func (c *Client) LookupURL() string

LookupURL is where the apps look this server up.

func (*Client) Prove

func (c *Client) Prove(host string, nonce []byte) (pub ed25519.PublicKey, sig []byte)

Prove signs nonce from an app that reached this server at host. The app checks the key leads to the id it knows and the signature is right, so whoever answers at an address the connect service gave out has to be the server itself, not someone passing its answers along: the host is signed too, and the server only signs its own.

func (*Client) Register

func (c *Client) Register(ctx context.Context, port int, pass string) (Registered, error)

Register tells the service this server is reachable on the router's external port, at whatever address the request comes from; port 0 takes the registration down. pass shows the subscription is paid.

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, session string) (Pass, error)

Subscribe trades the Checkout Session that bought this server's subscription for a pass. It returns ErrNotPaid while the checkout isn't paid, and ErrEnded once the subscription has ended.

type Found

type Found struct {
	ID string `json:"id"`
	// URLs are where the server said it was, most recent first.
	URLs    []string `json:"urls"`
	Updated int64    `json:"updated"`
}

Found is the service's answer to a lookup.

type Pass

type Pass struct {
	Pass  string `json:"pass"`
	Until int64  `json:"until"`
}

Pass is the service's answer to a subscription: the pass to send with registrations and checks, and until when (Unix seconds) it's good.

type Plan

type Plan struct {
	// ID is monthly or yearly.
	ID string `json:"id"`
	// Price is ready to show, such as "$3.99", and Interval month or year.
	Price    string `json:"price"`
	Interval string `json:"interval"`
}

Plan is a way to pay, as yeix.io offers it.

type Registered

type Registered struct {
	ID  string `json:"id"`
	URL string `json:"url,omitempty"`
	// TTL is how long, in seconds, the registration lasts without another.
	TTL int `json:"ttl"`
}

Registered is the service's answer to a registration.

type Service

type Service struct {
	// ClientIPHeader names the header a proxy in front puts the client's
	// address in, such as X-Real-IP. Empty uses the connection's address.
	ClientIPHeader string
	// Dial opens the reachability check's connection; nil uses net.Dialer.
	Dial func(ctx context.Context, network, addr string) (net.Conn, error)
	// AllowPrivate accepts private addresses, for tests.
	AllowPrivate bool
	// Now is the clock, for tests.
	Now func() time.Time
	// Stripe reads the checkouts that buy passes, and PassKey signs the
	// passes. Without Stripe, servers need no pass (pass.go).
	Stripe  *Stripe
	PassKey []byte
	// contains filtered or unexported fields
}

Service answers servers and apps. It keeps everything in memory: servers register again every few minutes, so a restart forgets nothing for long.

func (*Service) Handler

func (s *Service) Handler() http.Handler

Handler serves the service's API.

func (*Service) Run

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

Run forgets expired registrations until ctx ends.

type StatusError

type StatusError struct {
	URL     string
	Code    int
	Message string
}

StatusError is the service turning a request down.

func (*StatusError) Error

func (e *StatusError) Error() string

type Stripe

type Stripe struct {
	Key        string
	BaseURL    string // default https://api.stripe.com
	HTTPClient *http.Client
}

Stripe reads Checkout Sessions, with a restricted key that can read Checkout Sessions and Subscriptions.

Jump to

Keyboard shortcuts

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