feat(funnel): cloudflare quick tunnel embedded subprocess (0.9.5)
Gives the daemon a public HTTPS hostname (`https://<random>.trycloudflare.com`)
so the in-browser player on torrentclaw.com plays cross-network without
Tailscale or port forwarding — the mixed-content block that was breaking
HTTPS-page → HTTP-daemon fetches is gone. Bytes proxy through CloudFlare,
never through TorrentClaw infra (preserves the aggregator legal posture).
New surface:
• `internal/funnel/` package: subprocess wrapper + auto-download for
cloudflared. Linux amd64/arm64/armhf/386 fetched from GitHub releases
on first run, validated by ELF magic + size sanity, O_EXCL partial
write so concurrent daemons don't clobber each other.
• `unarr funnel on/off/status` cobra command (sibling of `unarr vpn`).
• Daemon supervisor goroutine keeps cloudflared up across crashes + CF's
~6h Quick Tunnel rotation. Exponential backoff (2 s → 5 min). On exit
the reported URL is cleared so the web stops handing out a dead host.
• Wire: agent registers/syncs a FunnelURL field; web prefers it over
Tailscale/LAN for in-browser playback (HlsStreamPlayer + Stremio
addon).
Default ON for fresh installs (NAS/Docker get it without terminal-in);
existing configs that pre-date the feature stay off until the operator
opts in with `unarr funnel on`.
Docker image now bundles cloudflared (built per TARGETARCH via buildx).
Also fixed: libx264 'frame MB size > level limit' on anamorphic >16:9
sources. The level we hint to libx264 was derived from height alone,
which busted on 720p cinemascope (1728×720 = 4860 MBs > level 3.1's
3600). Bumped each tier: 720p → 4.0, 1080p → 4.1.
Version: 0.9.4 → 0.9.5.
This commit is contained in:
parent
ca7de23a56
commit
88316e7017
15 changed files with 778 additions and 13 deletions
|
|
@ -55,6 +55,10 @@ type Daemon struct {
|
|||
vpnMode string
|
||||
vpnServer string
|
||||
|
||||
// CloudFlare Quick Tunnel public URL; folded into DaemonState + heartbeat
|
||||
// so the web can prefer it over Tailscale/LAN for in-browser playback.
|
||||
funnelURL string
|
||||
|
||||
// Watching tracks whether a user is viewing download progress in the web UI.
|
||||
Watching atomic.Bool
|
||||
|
||||
|
|
@ -85,6 +89,15 @@ func (d *Daemon) SetVPNState(active bool, mode, server string) {
|
|||
d.vpnServer = server
|
||||
}
|
||||
|
||||
// SetFunnelURL records the CloudFlare Quick Tunnel hostname so it's reflected
|
||||
// in the daemon state file (read by `unarr funnel status`) and in heartbeat
|
||||
// requests (so the web prefers it over Tailscale/LAN). Pass "" to clear.
|
||||
func (d *Daemon) SetFunnelURL(url string) {
|
||||
d.funnelURL = url
|
||||
d.State.FunnelURL = url
|
||||
WriteState(&d.State)
|
||||
}
|
||||
|
||||
// UpdateStreamPort updates the stream port reported in sync requests.
|
||||
func (d *Daemon) UpdateStreamPort(port int) {
|
||||
d.cfg.StreamPort = port
|
||||
|
|
@ -109,6 +122,7 @@ func (d *Daemon) Register(ctx context.Context) error {
|
|||
VPNActive: d.vpnActive,
|
||||
VPNMode: d.vpnMode,
|
||||
VPNServer: d.vpnServer,
|
||||
FunnelURL: d.funnelURL,
|
||||
}
|
||||
if free, total, err := DiskInfo(d.cfg.DownloadDir); err == nil {
|
||||
req.DiskFreeBytes = free
|
||||
|
|
@ -162,6 +176,7 @@ func (d *Daemon) Register(ctx context.Context) error {
|
|||
VPNActive: d.vpnActive,
|
||||
VPNMode: d.vpnMode,
|
||||
VPNServer: d.vpnServer,
|
||||
FunnelURL: d.funnelURL,
|
||||
}
|
||||
WriteState(&d.State)
|
||||
|
||||
|
|
@ -234,6 +249,9 @@ func (d *Daemon) Run(ctx context.Context) error {
|
|||
d.sync.GetVPNState = func() (bool, string, string) {
|
||||
return d.vpnActive, d.vpnMode, d.vpnServer
|
||||
}
|
||||
d.sync.GetFunnelURL = func() string {
|
||||
return d.funnelURL
|
||||
}
|
||||
d.sync.OnSyncSuccess = func() {
|
||||
d.State.LastHeartbeat = time.Now()
|
||||
if d.GetActiveCount != nil {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,11 @@ type DaemonState struct {
|
|||
VPNActive bool `json:"vpnActive,omitempty"`
|
||||
VPNMode string `json:"vpnMode,omitempty"` // managed | self-hosted
|
||||
VPNServer string `json:"vpnServer,omitempty"` // WireGuard endpoint (ip:port)
|
||||
|
||||
// CloudFlare Quick Tunnel state, so `unarr funnel status` can report the
|
||||
// HTTPS hostname the daemon is reachable at from anywhere on the internet.
|
||||
// Empty when the funnel is off or hasn't registered yet.
|
||||
FunnelURL string `json:"funnelUrl,omitempty"`
|
||||
}
|
||||
|
||||
// stateFilePathFn is overridable for testing.
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ type SyncClient struct {
|
|||
// WireGuard tunnel is up, the mode, and the exit server) so the web can track
|
||||
// which agent holds the single WG slot.
|
||||
GetVPNState func() (active bool, mode, server string)
|
||||
// GetFunnelURL returns the CloudFlare Quick Tunnel public hostname if one
|
||||
// is active, else "". Sent on every sync so the web picks it up live.
|
||||
GetFunnelURL func() string
|
||||
// OnDeleteFiles is called when the server requests file deletion from disk.
|
||||
// It should delete the files and return the IDs of successfully deleted items.
|
||||
OnDeleteFiles func(items []LibraryDeleteRequest) []int
|
||||
|
|
@ -162,6 +165,9 @@ func (sc *SyncClient) buildRequest() SyncRequest {
|
|||
if sc.GetVPNState != nil {
|
||||
req.VPNActive, req.VPNMode, req.VPNServer = sc.GetVPNState()
|
||||
}
|
||||
if sc.GetFunnelURL != nil {
|
||||
req.FunnelURL = sc.GetFunnelURL()
|
||||
}
|
||||
// Flush confirmed deletions from previous cycle.
|
||||
// Once flushed, remove IDs from deleteInFlight — the server will stop sending
|
||||
// them after this sync, so deduplication protection is no longer needed.
|
||||
|
|
|
|||
|
|
@ -34,6 +34,9 @@ type RegisterRequest struct {
|
|||
VPNActive bool `json:"vpnActive"`
|
||||
VPNMode string `json:"vpnMode,omitempty"` // managed | self-hosted
|
||||
VPNServer string `json:"vpnServer,omitempty"`
|
||||
// CloudFlare Quick Tunnel hostname when enabled; the web prefers it over
|
||||
// Tailscale/LAN for in-browser playback because it works on any network.
|
||||
FunnelURL string `json:"funnelUrl,omitempty"`
|
||||
}
|
||||
|
||||
// RegisterResponse is returned by the server after registration.
|
||||
|
|
@ -359,6 +362,8 @@ type SyncRequest struct {
|
|||
VPNActive bool `json:"vpnActive"`
|
||||
VPNMode string `json:"vpnMode,omitempty"`
|
||||
VPNServer string `json:"vpnServer,omitempty"`
|
||||
// CloudFlare Quick Tunnel hostname when enabled, else empty.
|
||||
FunnelURL string `json:"funnelUrl,omitempty"`
|
||||
}
|
||||
|
||||
// ControlAction represents a server-side control signal for a task.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue