Documentation
¶
Overview ¶
Package remote makes a home server reachable from the internet without router setup: it asks the router to forward a port (UPnP or NAT-PMP), gets a Let's Encrypt certificate for the router's public IP address, and serves the API over HTTPS there. The apps learn the address while at home (GET /api/v1/server) and use it when they're away.
When the router won't open ports, an admin can forward one by hand (SetForwardedPort). While it's ready, the server registers its address with the connect service, so the apps can find it after the address changes (internal/connect). Media never goes through anything but this port: when the internet provider shares one public address among customers, or a second router is in the way, Status says what to change.
Index ¶
- Constants
- Variables
- type ConnectStatus
- type Manager
- func (m *Manager) ConnectStatus() *ConnectStatus
- func (m *Manager) Findable() bool
- func (m *Manager) Lookup() (id, url string)
- func (m *Manager) ManageURL(ctx context.Context) (string, error)
- func (m *Manager) Plans(ctx context.Context) ([]connect.Plan, error)
- func (m *Manager) Run(ctx context.Context)
- func (m *Manager) SetEnabled(on bool)
- func (m *Manager) SetForwardedPort(ext int)
- func (m *Manager) Status() Status
- func (m *Manager) Subscribe(ctx context.Context, plan string) (string, error)
- func (m *Manager) URL() string
- type Status
Constants ¶
const ( StateOff = "off" StateWorking = "working" StateReady = "ready" StateFailed = "failed" )
const ( ConnectNone = "none" ConnectCheckout = "checkout" ConnectActive = "active" ConnectEnded = "ended" )
Variables ¶
var ( ErrNoBilling = errors.New("this server doesn't use Matinee Connect") ErrNoSubscriber = errors.New("this server has no Matinee Connect subscription bought in its settings") )
Errors for Settings.
Functions ¶
This section is empty.
Types ¶
type ConnectStatus ¶ added in v0.1.1
type ConnectStatus struct {
// State is none, checkout (waiting for payment), active, or ended.
State string `json:"state"`
Until *time.Time `json:"until,omitempty"`
// Checkout is the open checkout's page, while it's open.
Checkout string `json:"checkout,omitempty"`
Problem string `json:"problem,omitempty"`
}
ConnectStatus is what Settings shows about the subscription.
type Manager ¶
type Manager struct {
Addr string // the HTTPS listen address, such as :7443
Dir string // keeps the certificate and the CA account key
Handler http.Handler // serves the API
Log *slog.Logger
// Connect is the service the apps look this server up with; nil for
// none, which also rules out a port forwarded by hand.
Connect *connect.Client
// Billing is where Matinee Connect is bought, for Yeix's service;
// nil for one that needs no subscription.
Billing *connect.Billing
// For tests: the ACME directory (default Let's Encrypt), an HTTP client
// for it, a router, challenges to try, and accepting private addresses.
CA string
HTTPClient *http.Client
FindRouter func(context.Context) (router, error)
Challenges []challenge
AllowPrivate bool
// contains filtered or unexported fields
}
Manager keeps remote access going while it's on.
func (*Manager) ConnectStatus ¶ added in v0.1.1
func (m *Manager) ConnectStatus() *ConnectStatus
ConnectStatus reports the subscription, or nil when the server doesn't use the paid service.
func (*Manager) Findable ¶ added in v0.1.1
Findable reports whether the apps can look this server up right now.
func (*Manager) Lookup ¶ added in v0.1.1
Lookup is this server's id with the connect service and the address the apps look it up at, or "" without the service.
func (*Manager) ManageURL ¶ added in v0.1.1
ManageURL opens Stripe's page for changing the card or cancelling.
func (*Manager) Run ¶
Run keeps remote access up while it's on, until ctx ends; then it takes the router's forward down.
func (*Manager) SetEnabled ¶
SetEnabled turns remote access on or off; Run does the work.
func (*Manager) SetForwardedPort ¶ added in v0.1.1
SetForwardedPort says the admin forwarded the router's port ext (443 or 80) to this server's remote access port by hand; 0 goes back to asking the router.
type Status ¶
type Status struct {
Enabled bool `json:"enabled"`
// State is off, working (setting up), ready, or failed (see Problem).
State string `json:"state"`
// URL is the address the apps use away from home.
URL string `json:"url,omitempty"`
// Router is how the port was opened: UPnP or NAT-PMP.
Router string `json:"router,omitempty"`
PublicIP string `json:"publicIP,omitempty"`
// Problem says, for people, what stands in the way.
Problem string `json:"problem,omitempty"`
// provider shares one, or another router sits in front), which only a
// relay can get around.
SharedAddress bool `json:"sharedAddress,omitempty"`
// ForwardedPort is the router port an admin forwarded by hand; 0 means
// the router is asked to open one.
ForwardedPort int `json:"forwardedPort,omitempty"`
// ListenPort is this server's remote access port, where a port
// forwarded by hand should go.
ListenPort int `json:"listenPort,omitempty"`
// Findable means the connect service knows the current address, so
// the apps find this server even after the address changes.
Findable bool `json:"findable,omitempty"`
// Connect is the Matinee Connect subscription that pays for that;
// nil when the server uses a service that needs none.
Connect *ConnectStatus `json:"connect,omitempty"`
CertificateExpires *time.Time `json:"certificateExpires,omitempty"`
CheckedAt *time.Time `json:"checkedAt,omitempty"`
}
Status is what Settings shows about remote access.