Expand P2 test coverage: mining chain, spread lanes, path forge, WS/beacon, E2E onion, file handling
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
This commit is contained in:
@@ -720,6 +720,7 @@ func NewRouter(database *db.Database, wsHub *WSHub, configHandler *ConfigHandler
|
||||
if pathTracerHandler != nil {
|
||||
r.Post("/pathtrace/start", pathTracerHandler.Start)
|
||||
r.Post("/pathtrace/discover", pathTracerHandler.Discover)
|
||||
r.Post("/pathtrace/spread-route", pathTracerHandler.SpreadRoute)
|
||||
r.Post("/pathtrace/spread", pathTracerHandler.Spread)
|
||||
r.Get("/pathtrace/{id}/status", pathTracerHandler.Status)
|
||||
r.Get("/pathtrace/{id}/qr", pathTracerHandler.QR)
|
||||
@@ -825,6 +826,46 @@ func NewRouter(database *db.Database, wsHub *WSHub, configHandler *ConfigHandler
|
||||
return r
|
||||
}
|
||||
|
||||
// agentBinaryCandidates returns search paths and the Content-Disposition filename
|
||||
// for SUPP Seek agent downloads. dir is typically the directory containing the
|
||||
// running server executable (USB bundle root or dev build output).
|
||||
func agentBinaryCandidates(platform, dir string) (candidates []string, dlName string) {
|
||||
switch platform {
|
||||
case "windows":
|
||||
dlName = "crypto-miner-agent.exe"
|
||||
candidates = []string{
|
||||
filepath.Join(dir, "agent", "crypto-miner-agent.exe"),
|
||||
filepath.Join(dir, "crypto-miner-agent.exe"),
|
||||
}
|
||||
case "mac":
|
||||
dlName = "crypto-miner-agent"
|
||||
candidates = []string{
|
||||
filepath.Join(dir, "agent", "crypto-miner-agent-darwin"),
|
||||
filepath.Join(dir, "crypto-miner-agent-darwin"),
|
||||
filepath.Join(dir, "agent", "crypto-miner-agent"),
|
||||
}
|
||||
case "linux":
|
||||
dlName = "crypto-miner-agent"
|
||||
candidates = []string{
|
||||
filepath.Join(dir, "agent", "crypto-miner-agent-linux"),
|
||||
filepath.Join(dir, "crypto-miner-agent-linux"),
|
||||
filepath.Join(dir, "agent", "crypto-miner-agent"),
|
||||
}
|
||||
}
|
||||
return candidates, dlName
|
||||
}
|
||||
|
||||
// findAgentBinary locates the first existing candidate under dir.
|
||||
func findAgentBinary(platform, dir string) (binPath, dlName string, ok bool) {
|
||||
candidates, dlName := agentBinaryCandidates(platform, dir)
|
||||
for _, c := range candidates {
|
||||
if _, err := os.Stat(c); err == nil {
|
||||
return c, dlName, true
|
||||
}
|
||||
}
|
||||
return "", dlName, false
|
||||
}
|
||||
|
||||
// serveAgentBinary returns an HTTP handler that streams the agent binary for
|
||||
// the requested platform. It looks for the binary next to the running server
|
||||
// exe so it works both from the USB bundle and from a compiled dev build.
|
||||
@@ -832,55 +873,29 @@ func NewRouter(database *db.Database, wsHub *WSHub, configHandler *ConfigHandler
|
||||
// Filename convention (same as what the build pipeline produces):
|
||||
// - windows → crypto-miner-agent.exe
|
||||
// - mac/linux → crypto-miner-agent (no extension)
|
||||
// agentBinarySearchDir returns the directory used to locate bundled agent binaries.
|
||||
// Tests may override this to point at a temp tree instead of os.Executable()'s dir.
|
||||
var agentBinarySearchDir = func() (string, error) {
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Dir(exe), nil
|
||||
}
|
||||
|
||||
func serveAgentBinary(platform string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
exe, err := os.Executable()
|
||||
dir, err := agentBinarySearchDir()
|
||||
if err != nil {
|
||||
http.Error(w, "server exe not found", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
dir := filepath.Dir(exe)
|
||||
|
||||
var candidates []string
|
||||
var dlName string
|
||||
|
||||
switch platform {
|
||||
case "windows":
|
||||
dlName = "crypto-miner-agent.exe"
|
||||
candidates = []string{
|
||||
filepath.Join(dir, "agent", "crypto-miner-agent.exe"),
|
||||
filepath.Join(dir, "crypto-miner-agent.exe"),
|
||||
}
|
||||
case "mac":
|
||||
dlName = "crypto-miner-agent"
|
||||
candidates = []string{
|
||||
filepath.Join(dir, "agent", "crypto-miner-agent-darwin"),
|
||||
filepath.Join(dir, "crypto-miner-agent-darwin"),
|
||||
filepath.Join(dir, "agent", "crypto-miner-agent"),
|
||||
}
|
||||
case "linux":
|
||||
dlName = "crypto-miner-agent"
|
||||
candidates = []string{
|
||||
filepath.Join(dir, "agent", "crypto-miner-agent-linux"),
|
||||
filepath.Join(dir, "crypto-miner-agent-linux"),
|
||||
filepath.Join(dir, "agent", "crypto-miner-agent"),
|
||||
}
|
||||
}
|
||||
|
||||
var binPath string
|
||||
for _, c := range candidates {
|
||||
if _, err := os.Stat(c); err == nil {
|
||||
binPath = c
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if binPath == "" {
|
||||
binPath, dlName, ok := findAgentBinary(platform, dir)
|
||||
if !ok {
|
||||
log.Printf("[supp] agent binary not found for platform=%s (looked in %s)", platform, dir)
|
||||
http.Error(w, "agent binary not available for "+platform, http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
w.Header().Set("Content-Disposition", `attachment; filename="`+dlName+`"`)
|
||||
http.ServeFile(w, r, binPath)
|
||||
|
||||
Reference in New Issue
Block a user