Documentation
¶
Overview ¶
Package yonder shares an in-process HTTP server on an ad-hoc URL through a yonder relay. The app never listens on a local port: Listen returns a net.Listener whose connections arrive over the relay tunnel.
l, err := yonder.Listen(ctx, yonder.Options{Relay: "https://share.example.com", Token: tok})
fmt.Println(l.URL())
http.Serve(l, handler)
The URL stops working as soon as the listener is closed or the process exits.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrRelayClosed = errors.New("yonder: relay connection closed")
ErrRelayClosed is reported by Err and Accept when the relay connection ended without Close being called.
Functions ¶
This section is empty.
Types ¶
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener is a net.Listener for one share. It is safe for concurrent use.
It owns one goroutine that accepts tunnel streams and one goroutine per stream while its preamble is read or an approval runs. Close stops them all and waits for them.
func Listen ¶
Listen registers a new share with the relay. ctx bounds only the handshake; the share lives until Close or until the relay connection ends.
func (*Listener) Done ¶
func (l *Listener) Done() <-chan struct{}
Done is closed when the share has ended, by Close or by losing the relay.
type Options ¶
type Options struct {
// Relay is the relay's base URL, for example "https://share.example.com".
// Plain http is accepted only for loopback and *.localhost hosts.
Relay string
// Token authenticates this client to the relay.
Token string
// Approve, if set, is called for each visitor who presented the right
// code. It runs concurrently on a library goroutine. ctx ends when the
// relay stops waiting. Return true to let the visitor in.
Approve func(ctx context.Context, v Visitor) bool
// HTTPClient is used for the handshake. Defaults to http.DefaultClient.
HTTPClient *http.Client
}
Options configures Listen.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
yonder-relay
command
Command yonder-relay runs a yonder relay.
|
Command yonder-relay runs a yonder relay. |
|
internal
|
|
|
relay
Package relay implements the yonder relay: it accepts tunnel connections from clients, gives each one an ad-hoc subdomain, gates visitors with the share code and proxies their HTTP traffic into the tunnel.
|
Package relay implements the yonder relay: it accepts tunnel connections from clients, gives each one an ad-hoc subdomain, gates visitors with the share code and proxies their HTTP traffic into the tunnel. |
|
wire
Package wire defines the protocol shared by the yonder client and relay: handshake headers and the preamble that starts every yamux stream.
|
Package wire defines the protocol shared by the yonder client and relay: handshake headers and the preamble that starts every yamux stream. |