Fix P2P Connectivity Regression + Dynamic Versioning System #12

Merged
tony merged 10 commits from feature/phase-4-real-providers into main 2025-09-26 06:10:01 +00:00
2 changed files with 56 additions and 54 deletions
Showing only changes of commit 14b5125c12 - Show all commits

View File

@@ -9,10 +9,11 @@ import (
"chorus/internal/logging"
"chorus/pubsub"
"github.com/gorilla/mux"
)
// HTTPServer provides HTTP API endpoints for Bzzz
// HTTPServer provides HTTP API endpoints for CHORUS
type HTTPServer struct {
port int
hypercoreLog *logging.HypercoreLog
@@ -20,7 +21,7 @@ type HTTPServer struct {
server *http.Server
}
// NewHTTPServer creates a new HTTP server for Bzzz API
// NewHTTPServer creates a new HTTP server for CHORUS API
func NewHTTPServer(port int, hlog *logging.HypercoreLog, ps *pubsub.PubSub) *HTTPServer {
return &HTTPServer{
port: port,
@@ -197,11 +198,11 @@ func (h *HTTPServer) handleGetLogsSince(w http.ResponseWriter, r *http.Request)
}
response := map[string]interface{}{
"entries": entries,
"count": len(entries),
"entries": entries,
"count": len(entries),
"since_index": index,
"timestamp": time.Now().Unix(),
"total": h.hypercoreLog.Length(),
"timestamp": time.Now().Unix(),
"total": h.hypercoreLog.Length(),
}
json.NewEncoder(w).Encode(response)
@@ -220,8 +221,8 @@ func (h *HTTPServer) handleHealth(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
health := map[string]interface{}{
"status": "healthy",
"timestamp": time.Now().Unix(),
"status": "healthy",
"timestamp": time.Now().Unix(),
"log_entries": h.hypercoreLog.Length(),
}
@@ -233,10 +234,10 @@ func (h *HTTPServer) handleStatus(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
status := map[string]interface{}{
"status": "running",
"timestamp": time.Now().Unix(),
"hypercore": h.hypercoreLog.GetStats(),
"api_version": "1.0.0",
"status": "running",
"timestamp": time.Now().Unix(),
"hypercore": h.hypercoreLog.GetStats(),
"api_version": "1.0.0",
}
json.NewEncoder(w).Encode(status)

View File

@@ -6,17 +6,18 @@ import (
"time"
"chorus/pkg/dht"
"github.com/libp2p/go-libp2p"
kaddht "github.com/libp2p/go-libp2p-kad-dht"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/p2p/net/connmgr"
"github.com/libp2p/go-libp2p/p2p/security/noise"
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
kaddht "github.com/libp2p/go-libp2p-kad-dht"
"github.com/multiformats/go-multiaddr"
)
// Node represents a Bzzz P2P node
// Node represents a CHORUS P2P node
type Node struct {
host host.Host
ctx context.Context
@@ -47,8 +48,8 @@ func NewNode(ctx context.Context, opts ...Option) (*Node, error) {
// Create connection manager with scaling-optimized limits
connManager, err := connmgr.NewConnManager(
config.LowWatermark, // Low watermark (32)
config.HighWatermark, // High watermark (128)
config.LowWatermark, // Low watermark (32)
config.HighWatermark, // High watermark (128)
connmgr.WithGracePeriod(30*time.Second), // Grace period before pruning
)
if err != nil {
@@ -64,7 +65,7 @@ func NewNode(ctx context.Context, opts ...Option) (*Node, error) {
libp2p.DefaultMuxers,
libp2p.EnableRelay(),
libp2p.ConnectionManager(connManager), // Add connection management
libp2p.EnableAutoRelay(), // Enable AutoRelay for container environments
libp2p.EnableAutoRelay(), // Enable AutoRelay for container environments
)
if err != nil {
cancel()
@@ -171,7 +172,7 @@ func (n *Node) startBackgroundTasks() {
// logConnectionStatus logs the current connection status
func (n *Node) logConnectionStatus() {
peers := n.Peers()
fmt.Printf("🐝 Bzzz Node Status - ID: %s, Connected Peers: %d\n",
fmt.Printf("CHORUS Node Status - ID: %s, Connected Peers: %d\n",
n.ID().ShortString(), len(peers))
if len(peers) > 0 {