From fbdfa23c7761ad20c5cd3966fa5937eeed1e89fd Mon Sep 17 00:00:00 2001 From: anonpenguin23 Date: Wed, 5 Nov 2025 17:32:18 +0200 Subject: [PATCH] feat: enhance IPFS and Cluster integration in setup - Added automatic setup for IPFS and IPFS Cluster during the network setup process. - Implemented initialization of IPFS repositories and Cluster configurations for each node. - Enhanced Makefile to support starting IPFS and Cluster daemons with improved logging. - Introduced a new documentation guide for IPFS Cluster setup, detailing configuration and verification steps. - Updated changelog to reflect the new features and improvements. --- pkg/cli/config_commands.go | 2 +- pkg/client/defaults_test.go | 9 ++++++--- pkg/config/validate_test.go | 10 +++++----- pkg/gateway/anon_proxy_handler.go | 2 +- pkg/gateway/gateway.go | 4 ++-- pkg/node/node_test.go | 10 +++++----- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/pkg/cli/config_commands.go b/pkg/cli/config_commands.go index 208aac7..a7043af 100644 --- a/pkg/cli/config_commands.go +++ b/pkg/cli/config_commands.go @@ -286,7 +286,7 @@ func initFullStack(force bool) { fmt.Printf("✅ Generated bootstrap identity: %s (Peer ID: %s)\n", bootstrapIdentityPath, bootstrapInfo.PeerID.String()) // Construct bootstrap multiaddr - bootstrapMultiaddr := fmt.Sprintf("/ip4/localhost/tcp/4001/p2p/%s", bootstrapInfo.PeerID.String()) + bootstrapMultiaddr := fmt.Sprintf("/ip4/127.0.0.1/tcp/4001/p2p/%s", bootstrapInfo.PeerID.String()) fmt.Printf(" Bootstrap multiaddr: %s\n", bootstrapMultiaddr) // Generate configs for all nodes... diff --git a/pkg/client/defaults_test.go b/pkg/client/defaults_test.go index a686094..82cdbc2 100644 --- a/pkg/client/defaults_test.go +++ b/pkg/client/defaults_test.go @@ -11,7 +11,7 @@ func TestDefaultBootstrapPeersNonEmpty(t *testing.T) { old := os.Getenv("DEBROS_BOOTSTRAP_PEERS") t.Cleanup(func() { os.Setenv("DEBROS_BOOTSTRAP_PEERS", old) }) // Set a valid bootstrap peer - validPeer := "/ip4/localhost/tcp/4001/p2p/12D3KooWHbcFcrGPXKUrHcxvd8MXEeUzRYyvY8fQcpEBxncSUwhj" + validPeer := "/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWHbcFcrGPXKUrHcxvd8MXEeUzRYyvY8fQcpEBxncSUwhj" _ = os.Setenv("DEBROS_BOOTSTRAP_PEERS", validPeer) peers := DefaultBootstrapPeers() if len(peers) == 0 { @@ -50,8 +50,11 @@ func TestNormalizeEndpoints(t *testing.T) { } func TestEndpointFromMultiaddr(t *testing.T) { - ma, _ := multiaddr.NewMultiaddr("/ip4/localhost/tcp/4001") - if ep := endpointFromMultiaddr(ma, 5001); ep != "http://localhost:5001" { + ma, err := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/4001") + if err != nil { + t.Fatalf("failed to create multiaddr: %v", err) + } + if ep := endpointFromMultiaddr(ma, 5001); ep != "http://127.0.0.1:5001" { t.Fatalf("unexpected endpoint: %s", ep) } } diff --git a/pkg/config/validate_test.go b/pkg/config/validate_test.go index f351e9d..79a829f 100644 --- a/pkg/config/validate_test.go +++ b/pkg/config/validate_test.go @@ -7,7 +7,7 @@ import ( // validConfigForType returns a valid config for the given node type func validConfigForType(nodeType string) *Config { - validPeer := "/ip4/localhost/tcp/4001/p2p/12D3KooWHbcFcrGPXKUrHcxvd8MXEeUzRYyvY8fQcpEBxncSUwhj" + validPeer := "/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWHbcFcrGPXKUrHcxvd8MXEeUzRYyvY8fQcpEBxncSUwhj" cfg := &Config{ Node: NodeConfig{ Type: nodeType, @@ -205,7 +205,7 @@ func TestValidateRQLiteJoinAddress(t *testing.T) { } func TestValidateBootstrapPeers(t *testing.T) { - validPeer := "/ip4/localhost/tcp/4001/p2p/12D3KooWHbcFcrGPXKUrHcxvd8MXEeUzRYyvY8fQcpEBxncSUwhj" + validPeer := "/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWHbcFcrGPXKUrHcxvd8MXEeUzRYyvY8fQcpEBxncSUwhj" tests := []struct { name string nodeType string @@ -217,9 +217,9 @@ func TestValidateBootstrapPeers(t *testing.T) { {"bootstrap with peer", "bootstrap", []string{validPeer}, false}, {"bootstrap without peer", "bootstrap", []string{}, false}, {"invalid multiaddr", "node", []string{"invalid"}, true}, - {"missing p2p", "node", []string{"/ip4/localhost/tcp/4001"}, true}, + {"missing p2p", "node", []string{"/ip4/127.0.0.1/tcp/4001"}, true}, {"duplicate peer", "node", []string{validPeer, validPeer}, true}, - {"invalid port", "node", []string{"/ip4/localhost/tcp/99999/p2p/12D3KooWHbcFcrGPXKUrHcxvd8MXEeUzRYyvY8fQcpEBxncSUwhj"}, true}, + {"invalid port", "node", []string{"/ip4/127.0.0.1/tcp/99999/p2p/12D3KooWHbcFcrGPXKUrHcxvd8MXEeUzRYyvY8fQcpEBxncSUwhj"}, true}, } for _, tt := range tests { @@ -397,7 +397,7 @@ func TestValidateCompleteConfig(t *testing.T) { }, Discovery: DiscoveryConfig{ BootstrapPeers: []string{ - "/ip4/localhost/tcp/4001/p2p/12D3KooWHbcFcrGPXKUrHcxvd8MXEeUzRYyvY8fQcpEBxncSUwhj", + "/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWHbcFcrGPXKUrHcxvd8MXEeUzRYyvY8fQcpEBxncSUwhj", }, DiscoveryInterval: 15 * time.Second, BootstrapPort: 4001, diff --git a/pkg/gateway/anon_proxy_handler.go b/pkg/gateway/anon_proxy_handler.go index 7b0cd2d..692434d 100644 --- a/pkg/gateway/anon_proxy_handler.go +++ b/pkg/gateway/anon_proxy_handler.go @@ -234,7 +234,7 @@ func isPrivateOrLocalHost(host string) bool { } // Check for localhost variants - if host == "localhost" || host == "localhost" || host == "::1" { + if host == "localhost" || host == "::1" { return true } diff --git a/pkg/gateway/gateway.go b/pkg/gateway/gateway.go index e14a043..546293d 100644 --- a/pkg/gateway/gateway.go +++ b/pkg/gateway/gateway.go @@ -371,7 +371,7 @@ func discoverOlricServers(networkClient client.NetworkClient, logger *zap.Logger } // Skip localhost loopback addresses (we'll use localhost:3320 as fallback) - if ip == "localhost" || ip == "::1" || ip == "localhost" { + if ip == "localhost" || ip == "::1" { continue } @@ -402,7 +402,7 @@ func discoverOlricServers(networkClient client.NetworkClient, logger *zap.Logger } // Skip localhost - if ip == "localhost" || ip == "::1" || ip == "localhost" { + if ip == "localhost" || ip == "::1" { continue } diff --git a/pkg/node/node_test.go b/pkg/node/node_test.go index b07bb05..8ee0ab4 100644 --- a/pkg/node/node_test.go +++ b/pkg/node/node_test.go @@ -177,13 +177,13 @@ func TestHashBootstrapConnections(t *testing.T) { } // Create two hosts (A and B) listening on localhost TCP - hA, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/localhost/tcp/0")) + hA, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0")) if err != nil { t.Fatalf("libp2p.New (A): %v", err) } defer hA.Close() - hB, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/localhost/tcp/0")) + hB, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0")) if err != nil { t.Fatalf("libp2p.New (B): %v", err) } @@ -244,19 +244,19 @@ func TestHashBootstrapConnections(t *testing.T) { } // Create three hosts (A, B, C) listening on localhost TCP - hA, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/localhost/tcp/0")) + hA, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0")) if err != nil { t.Fatalf("libp2p.New (A): %v", err) } defer hA.Close() - hB, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/localhost/tcp/0")) + hB, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0")) if err != nil { t.Fatalf("libp2p.New (B): %v", err) } defer hB.Close() - hC, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/localhost/tcp/0")) + hC, err := libp2p.New(libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0")) if err != nil { t.Fatalf("libp2p.New (C): %v", err) }