mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-24 14:47:23 +00:00
RunPeerReachabilityProbe is the post-migration replacement for the
active swUpdateUrl round-trip: register the device IP with the
in-process observer, nudge :8090/swUpdateCheck, and wait for any
inbound from that IP. No device-state mutation. Any inbound counts
as proof — on a migrated speaker, DNS interception routes the
daemon's outbounds through this service regardless of which URL it
resolved internally, so reachability reduces to "did the device
dial us at all."
PeerHit and the abstract observer interface live in setup alongside
the probe logic; handlers.peerObserver implements the interface and
the existing observer files now import from setup.
Route: POST /setup/peer-probe/{deviceId}. Timeout: 30s, surfaced as
result.ElapsedMs so the budget can be tuned from real data. The
pre-flight orchestrator gains the branch in the next commit.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
32 lines
1.1 KiB
Go
32 lines
1.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gesellix/bose-soundtouch/pkg/service/setup"
|
|
)
|
|
|
|
// PeerObserverMiddleware records every incoming request's source IP and
|
|
// path in the peerObserver registry. It fires on every request before
|
|
// the handler runs, so passive reachability probes can register a device
|
|
// IP and learn whether any inbound landed in their wait window.
|
|
//
|
|
// Placement: after TrustedRealIPMiddleware (so r.RemoteAddr reflects the
|
|
// trusted client IP) and after Recoverer (so any panic inside this
|
|
// middleware is contained). Before any short-circuiting middleware
|
|
// would be unnecessary — Signal runs before next.ServeHTTP, so the
|
|
// observation lands regardless of how later middleware handles the
|
|
// request.
|
|
func (s *Server) PeerObserverMiddleware(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
|
if err == nil && host != "" {
|
|
s.peerObserver.Signal(host, setup.PeerHit{Path: r.URL.Path, At: time.Now()})
|
|
}
|
|
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|