mirror of
https://github.com/DeBrosOfficial/network.git
synced 2026-01-30 11:33:04 +00:00
Fixed problem on ipfs
This commit is contained in:
parent
6c3d16c332
commit
e94da3a639
@ -61,7 +61,7 @@ func (ici *IPFSClusterInstaller) Configure() error {
|
|||||||
// InitializeConfig initializes IPFS Cluster configuration (unified - no bootstrap/node distinction)
|
// InitializeConfig initializes IPFS Cluster configuration (unified - no bootstrap/node distinction)
|
||||||
// This runs `ipfs-cluster-service init` to create the service.json configuration file.
|
// This runs `ipfs-cluster-service init` to create the service.json configuration file.
|
||||||
// For existing installations, it ensures the cluster secret is up to date.
|
// For existing installations, it ensures the cluster secret is up to date.
|
||||||
// clusterPeers should be in format: ["/ip4/<ip>/tcp/9098/p2p/<cluster-peer-id>"]
|
// clusterPeers should be in format: ["/ip4/<ip>/tcp/9100/p2p/<cluster-peer-id>"]
|
||||||
func (ici *IPFSClusterInstaller) InitializeConfig(clusterPath, clusterSecret string, ipfsAPIPort int, clusterPeers []string) error {
|
func (ici *IPFSClusterInstaller) InitializeConfig(clusterPath, clusterSecret string, ipfsAPIPort int, clusterPeers []string) error {
|
||||||
serviceJSONPath := filepath.Join(clusterPath, "service.json")
|
serviceJSONPath := filepath.Join(clusterPath, "service.json")
|
||||||
configExists := false
|
configExists := false
|
||||||
@ -146,18 +146,22 @@ func (ici *IPFSClusterInstaller) updateConfig(clusterPath, secret string, ipfsAP
|
|||||||
// Update cluster secret, listen_multiaddress, and peer addresses
|
// Update cluster secret, listen_multiaddress, and peer addresses
|
||||||
if cluster, ok := config["cluster"].(map[string]interface{}); ok {
|
if cluster, ok := config["cluster"].(map[string]interface{}); ok {
|
||||||
cluster["secret"] = secret
|
cluster["secret"] = secret
|
||||||
// Set consistent listen_multiaddress - port 9098 for cluster LibP2P communication
|
// Set consistent listen_multiaddress - port 9100 for cluster LibP2P communication
|
||||||
// This MUST match the port used in GetClusterPeerMultiaddr() and peer_addresses
|
// This MUST match the port used in GetClusterPeerMultiaddr() and peer_addresses
|
||||||
cluster["listen_multiaddress"] = []interface{}{"/ip4/0.0.0.0/tcp/9098"}
|
cluster["listen_multiaddress"] = []interface{}{"/ip4/0.0.0.0/tcp/9100"}
|
||||||
// Configure peer addresses for cluster discovery
|
// Configure peer addresses for cluster discovery
|
||||||
// This allows nodes to find and connect to each other
|
// This allows nodes to find and connect to each other
|
||||||
|
// Merge new peers with existing peers (preserves manually configured peers)
|
||||||
if len(bootstrapClusterPeers) > 0 {
|
if len(bootstrapClusterPeers) > 0 {
|
||||||
cluster["peer_addresses"] = bootstrapClusterPeers
|
existingPeers := ici.extractExistingPeers(cluster)
|
||||||
|
mergedPeers := ici.mergePeerAddresses(existingPeers, bootstrapClusterPeers)
|
||||||
|
cluster["peer_addresses"] = mergedPeers
|
||||||
}
|
}
|
||||||
|
// If no new peers provided, preserve existing peer_addresses (don't overwrite)
|
||||||
} else {
|
} else {
|
||||||
clusterConfig := map[string]interface{}{
|
clusterConfig := map[string]interface{}{
|
||||||
"secret": secret,
|
"secret": secret,
|
||||||
"listen_multiaddress": []interface{}{"/ip4/0.0.0.0/tcp/9098"},
|
"listen_multiaddress": []interface{}{"/ip4/0.0.0.0/tcp/9100"},
|
||||||
}
|
}
|
||||||
if len(bootstrapClusterPeers) > 0 {
|
if len(bootstrapClusterPeers) > 0 {
|
||||||
clusterConfig["peer_addresses"] = bootstrapClusterPeers
|
clusterConfig["peer_addresses"] = bootstrapClusterPeers
|
||||||
@ -193,6 +197,43 @@ func (ici *IPFSClusterInstaller) updateConfig(clusterPath, secret string, ipfsAP
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// extractExistingPeers extracts existing peer addresses from cluster config
|
||||||
|
func (ici *IPFSClusterInstaller) extractExistingPeers(cluster map[string]interface{}) []string {
|
||||||
|
var peers []string
|
||||||
|
if peerAddrs, ok := cluster["peer_addresses"].([]interface{}); ok {
|
||||||
|
for _, addr := range peerAddrs {
|
||||||
|
if addrStr, ok := addr.(string); ok && addrStr != "" {
|
||||||
|
peers = append(peers, addrStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return peers
|
||||||
|
}
|
||||||
|
|
||||||
|
// mergePeerAddresses merges existing and new peer addresses, removing duplicates
|
||||||
|
func (ici *IPFSClusterInstaller) mergePeerAddresses(existing, new []string) []string {
|
||||||
|
seen := make(map[string]bool)
|
||||||
|
var merged []string
|
||||||
|
|
||||||
|
// Add existing peers first
|
||||||
|
for _, peer := range existing {
|
||||||
|
if !seen[peer] {
|
||||||
|
seen[peer] = true
|
||||||
|
merged = append(merged, peer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add new peers (if not already present)
|
||||||
|
for _, peer := range new {
|
||||||
|
if !seen[peer] {
|
||||||
|
seen[peer] = true
|
||||||
|
merged = append(merged, peer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return merged
|
||||||
|
}
|
||||||
|
|
||||||
// verifySecret verifies that the secret in service.json matches the expected value
|
// verifySecret verifies that the secret in service.json matches the expected value
|
||||||
func (ici *IPFSClusterInstaller) verifySecret(clusterPath, expectedSecret string) error {
|
func (ici *IPFSClusterInstaller) verifySecret(clusterPath, expectedSecret string) error {
|
||||||
serviceJSONPath := filepath.Join(clusterPath, "service.json")
|
serviceJSONPath := filepath.Join(clusterPath, "service.json")
|
||||||
@ -221,7 +262,7 @@ func (ici *IPFSClusterInstaller) verifySecret(clusterPath, expectedSecret string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetClusterPeerMultiaddr reads the IPFS Cluster peer ID and returns its multiaddress
|
// GetClusterPeerMultiaddr reads the IPFS Cluster peer ID and returns its multiaddress
|
||||||
// Returns format: /ip4/<ip>/tcp/9098/p2p/<cluster-peer-id>
|
// Returns format: /ip4/<ip>/tcp/9100/p2p/<cluster-peer-id>
|
||||||
func (ici *IPFSClusterInstaller) GetClusterPeerMultiaddr(clusterPath string, nodeIP string) (string, error) {
|
func (ici *IPFSClusterInstaller) GetClusterPeerMultiaddr(clusterPath string, nodeIP string) (string, error) {
|
||||||
identityPath := filepath.Join(clusterPath, "identity.json")
|
identityPath := filepath.Join(clusterPath, "identity.json")
|
||||||
|
|
||||||
@ -243,9 +284,9 @@ func (ici *IPFSClusterInstaller) GetClusterPeerMultiaddr(clusterPath string, nod
|
|||||||
return "", fmt.Errorf("peer ID not found in identity.json")
|
return "", fmt.Errorf("peer ID not found in identity.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct multiaddress: /ip4/<ip>/tcp/9098/p2p/<peer-id>
|
// Construct multiaddress: /ip4/<ip>/tcp/9100/p2p/<peer-id>
|
||||||
// Port 9098 is the default cluster listen port
|
// Port 9100 is the cluster listen port for libp2p communication
|
||||||
multiaddr := fmt.Sprintf("/ip4/%s/tcp/9098/p2p/%s", nodeIP, peerID)
|
multiaddr := fmt.Sprintf("/ip4/%s/tcp/9100/p2p/%s", nodeIP, peerID)
|
||||||
return multiaddr, nil
|
return multiaddr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -336,12 +336,12 @@ func (ps *ProductionSetup) Phase2cInitializeServices(peerAddresses []string, vps
|
|||||||
var clusterPeers []string
|
var clusterPeers []string
|
||||||
if ipfsClusterPeer != nil && ipfsClusterPeer.PeerID != "" {
|
if ipfsClusterPeer != nil && ipfsClusterPeer.PeerID != "" {
|
||||||
// Construct cluster peer multiaddress using the discovered peer ID
|
// Construct cluster peer multiaddress using the discovered peer ID
|
||||||
// Format: /ip4/<ip>/tcp/9098/p2p/<cluster-peer-id>
|
// Format: /ip4/<ip>/tcp/9100/p2p/<cluster-peer-id>
|
||||||
peerIP := inferPeerIP(peerAddresses, vpsIP)
|
peerIP := inferPeerIP(peerAddresses, vpsIP)
|
||||||
if peerIP != "" {
|
if peerIP != "" {
|
||||||
// Construct the bootstrap multiaddress for IPFS Cluster
|
// Construct the bootstrap multiaddress for IPFS Cluster
|
||||||
// Note: IPFS Cluster listens on port 9098 for cluster communication
|
// Note: IPFS Cluster listens on port 9100 for cluster communication
|
||||||
clusterBootstrapAddr := fmt.Sprintf("/ip4/%s/tcp/9098/p2p/%s", peerIP, ipfsClusterPeer.PeerID)
|
clusterBootstrapAddr := fmt.Sprintf("/ip4/%s/tcp/9100/p2p/%s", peerIP, ipfsClusterPeer.PeerID)
|
||||||
clusterPeers = []string{clusterBootstrapAddr}
|
clusterPeers = []string{clusterBootstrapAddr}
|
||||||
ps.logf(" ℹ️ IPFS Cluster will connect to peer: %s", clusterBootstrapAddr)
|
ps.logf(" ℹ️ IPFS Cluster will connect to peer: %s", clusterBootstrapAddr)
|
||||||
} else if len(ipfsClusterPeer.Addrs) > 0 {
|
} else if len(ipfsClusterPeer.Addrs) > 0 {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user