Fix DHT and tracker stats display
Some checks are pending
CI Pipeline / Run Tests (push) Waiting to run
CI Pipeline / Lint Code (push) Waiting to run
CI Pipeline / Security Scan (push) Waiting to run
CI Pipeline / E2E Tests (push) Blocked by required conditions

This commit is contained in:
Enki 2025-08-27 21:05:59 -07:00
parent 42fad7c9fd
commit 4f4c817276
2 changed files with 59 additions and 4 deletions

View File

@ -3326,7 +3326,7 @@ func RegisterRoutes(r *mux.Router, cfg *config.Config, storage *storage.Backend)
publicRoutes.HandleFunc("/profile/{pubkey}", gateway.ProfileHandler).Methods("GET")
// System stats endpoint (public)
r.HandleFunc("/stats", systemStatsHandler(storage, trackerInstance)).Methods("GET")
r.HandleFunc("/stats", systemStatsHandler(gateway, storage, trackerInstance)).Methods("GET")
// Branding configuration endpoint (public)
r.HandleFunc("/branding", brandingHandler(cfg)).Methods("GET")
@ -3939,7 +3939,7 @@ func brandingHandler(cfg *config.Config) http.HandlerFunc {
}
}
func systemStatsHandler(storage *storage.Backend, trackerInstance *tracker.Tracker) http.HandlerFunc {
func systemStatsHandler(gateway *Gateway, storage *storage.Backend, trackerInstance *tracker.Tracker) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
@ -4013,8 +4013,8 @@ func systemStatsHandler(storage *storage.Backend, trackerInstance *tracker.Track
},
"dht": map[string]interface{}{
"status": "healthy",
"port": 6882,
"peers": 0, // Would need DHT integration
"port": 6883, // Fixed port number
"peers": 0, // Will be updated below if DHT available
"torrents": torrentFiles,
},
"system": map[string]interface{}{
@ -4027,6 +4027,17 @@ func systemStatsHandler(storage *storage.Backend, trackerInstance *tracker.Track
},
}
// Update DHT stats with real data if DHT is enabled
if gateway.config.IsServiceEnabled("dht") && gateway.dhtBootstrap != nil {
dhtStats := gateway.dhtBootstrap.GetDHTStats()
if dhtMap, exists := stats["dht"].(map[string]interface{}); exists {
// Update peers count with routing table size
if routingTableSize, hasRouting := dhtStats["routing_table_size"]; hasRouting {
dhtMap["peers"] = routingTableSize
}
}
}
// Add tracker stats if enabled
if trackerInstance != nil {
trackerStats := trackerInstance.GetStats()

View File

@ -260,6 +260,50 @@
</div>
</div>
<div class="stats-section">
<h3>🌐 DHT Network</h3>
<div class="service-grid">
<div class="stat-card">
<div class="stat-header">Status</div>
<div class="stat-value status-indicator" id="dht-status">🔴</div>
</div>
<div class="stat-card">
<div class="stat-header">Routing Table</div>
<div class="stat-value" id="dht-peers">--</div>
</div>
<div class="stat-card">
<div class="stat-header">Announced Torrents</div>
<div class="stat-value" id="dht-torrents">--</div>
</div>
</div>
</div>
<div class="stats-section">
<h3>📊 Tracker Stats</h3>
<div class="service-grid">
<div class="stat-card">
<div class="stat-header">Status</div>
<div class="stat-value status-indicator" id="tracker-status">🔴</div>
</div>
<div class="stat-card">
<div class="stat-header">Torrents</div>
<div class="stat-value" id="tracker-torrents">--</div>
</div>
<div class="stat-card">
<div class="stat-header">Total Peers</div>
<div class="stat-value" id="tracker-peers">--</div>
</div>
<div class="stat-card">
<div class="stat-header">Seeders</div>
<div class="stat-value" id="tracker-seeders">--</div>
</div>
<div class="stat-card">
<div class="stat-header">Leechers</div>
<div class="stat-value" id="tracker-leechers">--</div>
</div>
</div>
</div>
<div class="stats-section">
<h3>📱 WebTorrent Integration</h3>
<div class="service-grid">