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
- Variables
- func ID(pub ed25519.PublicKey) string
- func LoadKey(path string) (ed25519.PrivateKey, error)
- func NeedsSubscription(err error) bool
- func ProofMessage(host string, nonce []byte) []byte
- func Public(ip netip.Addr) bool
- func URL(ip netip.Addr, port int) string
- type Billing
- type Checked
- type Checkout
- type Client
- func (c *Client) Check(ctx context.Context, port int, pass string) (netip.Addr, bool, error)
- func (c *Client) ID() string
- func (c *Client) LookupURL() string
- func (c *Client) Prove(host string, nonce []byte) (pub ed25519.PublicKey, sig []byte)
- func (c *Client) Register(ctx context.Context, port int, pass string) (Registered, error)
- func (c *Client) Subscribe(ctx context.Context, session string) (Pass, error)
- type Found
- type Pass
- type Plan
- type Registered
- type Service
- type StatusError
- type Stripe
Constants ¶
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.
const DefaultURL = "https://connect.matinee.yeix.io"
DefaultURL is the service Yeix hosts for every Matinee server.
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 ¶
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 ¶
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 ¶
NeedsSubscription reports whether err is the service turning away a server without a paid subscription.
func ProofMessage ¶
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.
Types ¶
type Billing ¶
Billing is yeix.io's side of buying Matinee Connect.
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 ¶
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) Prove ¶
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.
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 ¶
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.
type StatusError ¶
StatusError is the service turning a request down.
func (*StatusError) Error ¶
func (e *StatusError) Error() string