diff --git a/internal/api/handlers.go b/internal/api/handlers.go index b1c772f..c93eef4 100644 --- a/internal/api/handlers.go +++ b/internal/api/handlers.go @@ -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() diff --git a/internal/web/index.html b/internal/web/index.html index eba5cee..d209245 100644 --- a/internal/web/index.html +++ b/internal/web/index.html @@ -260,6 +260,50 @@ +
+

🌐 DHT Network

+
+
+
Status
+
🔴
+
+
+
Routing Table
+
--
+
+
+
Announced Torrents
+
--
+
+
+
+ +
+

📊 Tracker Stats

+
+
+
Status
+
🔴
+
+
+
Torrents
+
--
+
+
+
Total Peers
+
--
+
+
+
Seeders
+
--
+
+
+
Leechers
+
--
+
+
+
+

📱 WebTorrent Integration