Help us shape the future of Go! Take the 2026 Go Developer Survey

skyroute

package
v1.3.103 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package skyroute pkg/skyroute/pool.go c2-net-routing connections — browser SOCKS5 requests through the resolving proxy, skysocks-lite fetches, skychat messages — don't each pay a fresh route setup.

A skywire routing rule expires after DefaultRouteKeepAlive (10 min) unless an OPEN RouteGroup's keepalive loop keeps re-arming every hop. The resolving proxy historically dialed a fresh route per connection and closed it when the connection ended, so multihop routes died and every page load re-ran route-finding + per-hop rule setup (seconds). Direct routes re-set-up instantly, which is why "it only worked for direct routes".

Pool fixes that by holding ONE route group per route KEY open and multiplexing many logical connections over it with yamux — exactly the shape skysocks-lite already used privately. The held route group's keepalive keeps the multihop hops warm, so subsequent connections reuse it with zero setup. The route lives on the visor (not the browser), so this needs no "page is open" signal and fixes the external-browser SOCKS5 case and the in-tab iframe case identically. An idle route group is reclaimed after IdleTTL; a holder that knows it's done (an iframe window closing) can Release it eagerly.

The key is opaque to the pool: the resolving proxy keys the route-finder path on the destination PK and the explicit source-route path on destination+hop-set, so a `<pk>.skynet` fetch and a `<hop>.<pk>.skynet` fetch hold independent warm route groups instead of one clobbering the other. The caller passes the dial closure per OpenStream, so the pool needs no knowledge of how a given route is built.

The far end must run the yamux-aware skyfwd server (skyenv.SkyForwardingMuxPort). Against older visors that don't, the first dial fails, OpenStream returns ErrNoMux (negative-cached briefly), and the caller falls back to a 1:1 dial.

Index

Constants

View Source
const (
	// DefaultIdleTTL is how long a route group is held open after its last stream
	// closes before the reaper reclaims it. The route's keepalive keeps the hops
	// warm during this window so reconnects reuse it with no setup.
	DefaultIdleTTL = 10 * time.Minute
)

Variables

View Source
var ErrNoMux = errors.New("skyroute: destination does not serve the mux forwarding port")

ErrNoMux means the destination's visor does not serve the yamux forwarding port (an older build). The caller should fall back to a 1:1 SkyForwardingServerPort dial. The pool negative-caches this per route key so it isn't re-probed on every request.

Functions

This section is empty.

Types

type DialRoute

type DialRoute func(ctx context.Context, muxPort uint16) (net.Conn, error)

DialRoute dials the destination's forwarding server on muxPort over a (possibly multihop) route and returns the route-group net.Conn. It captures whatever destination / hop-set specifics it needs, so the pool stays route-agnostic. The pool yamux-muxes over whatever conn this returns; it can take several seconds (route setup) and is always called without the pool lock held.

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool holds and reuses route groups keyed by an opaque route key.

func New

func New(idleTTL time.Duration, log logrus.FieldLogger) *Pool

New builds a Pool. idleTTL ≤ 0 uses DefaultIdleTTL. A nil log discards output.

func (*Pool) Close

func (p *Pool) Close() error

Close tears down the pool and every held route group.

func (*Pool) OpenStream

func (p *Pool) OpenStream(ctx context.Context, key string, dial DialRoute) (net.Conn, error)

OpenStream returns a stream to the route key's skyfwd server over a HELD, reused route group, dialing (via the supplied closure) + caching the route group on first use (or after the previous one died). The caller then runs the skynet handshake (skynetweb.PerformHandshake) on the returned conn exactly as it would on a fresh route. Returns ErrNoMux when the destination doesn't serve the mux port (caller should fall back to a 1:1 dial).

func (*Pool) Release

func (p *Pool) Release(key string)

Release eagerly closes and drops a route key's held route group (e.g. an iframe window that owned it has closed). Idempotent.

Jump to

Keyboard shortcuts

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