mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-10-06 06:19:08 +00:00
Remove legacy bootstrap and dev env logic
This commit is contained in:
parent
f8defe1110
commit
1a6806256d
@ -10,11 +10,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.debros.io/DeBros/network/pkg/anyoneproxy"
|
||||
"git.debros.io/DeBros/network/pkg/client"
|
||||
"git.debros.io/DeBros/network/pkg/constants"
|
||||
"github.com/libp2p/go-libp2p/core/crypto"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
"git.debros.io/DeBros/network/pkg/anyoneproxy"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -446,28 +445,7 @@ func handlePeerID() {
|
||||
}
|
||||
|
||||
func createClient() (client.NetworkClient, error) {
|
||||
var bootstrapPeers []string
|
||||
|
||||
if useProduction {
|
||||
// Set environment to production to trigger production bootstrap peers
|
||||
os.Setenv("ENVIRONMENT", "production")
|
||||
bootstrapPeers = constants.GetBootstrapPeers()
|
||||
if format != "json" {
|
||||
fmt.Printf("🔗 Using production bootstrap peers\n")
|
||||
}
|
||||
} else {
|
||||
// Try to discover the bootstrap peer from saved peer info
|
||||
discoveredPeer := discoverBootstrapPeer()
|
||||
if discoveredPeer != "" {
|
||||
bootstrapPeer = discoveredPeer
|
||||
}
|
||||
bootstrapPeers = []string{bootstrapPeer}
|
||||
}
|
||||
|
||||
config := client.DefaultClientConfig("network-cli")
|
||||
config.BootstrapPeers = bootstrapPeers
|
||||
config.ConnectTimeout = timeout
|
||||
config.QuietMode = true // Suppress debug/info logs for CLI
|
||||
|
||||
networkClient, err := client.NewClient(config)
|
||||
if err != nil {
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
goproxy "golang.org/x/net/proxy"
|
||||
@ -27,25 +26,11 @@ func Enabled() bool {
|
||||
if disabled {
|
||||
return false
|
||||
}
|
||||
if os.Getenv("ANYONE_DISABLE") == "1" {
|
||||
return false
|
||||
}
|
||||
// If explicitly enabled via env or custom addr provided, also true.
|
||||
if os.Getenv("ANYONE_PROXY_ENABLED") == "1" {
|
||||
return true
|
||||
}
|
||||
if os.Getenv("ANYONE_SOCKS5") != "" {
|
||||
return true
|
||||
}
|
||||
// Default: enabled
|
||||
return true
|
||||
}
|
||||
|
||||
// socksAddr returns the SOCKS5 address to use for proxying (host:port).
|
||||
func socksAddr() string {
|
||||
if v := os.Getenv("ANYONE_SOCKS5"); v != "" {
|
||||
return v
|
||||
}
|
||||
return "127.0.0.1:9050"
|
||||
}
|
||||
|
||||
|
@ -18,10 +18,10 @@ import (
|
||||
dht "github.com/libp2p/go-libp2p-kad-dht"
|
||||
libp2ppubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
|
||||
"git.debros.io/DeBros/network/pkg/anyoneproxy"
|
||||
"git.debros.io/DeBros/network/pkg/discovery"
|
||||
"git.debros.io/DeBros/network/pkg/pubsub"
|
||||
"git.debros.io/DeBros/network/pkg/storage"
|
||||
"git.debros.io/DeBros/network/pkg/anyoneproxy"
|
||||
)
|
||||
|
||||
// Client implements the NetworkClient interface
|
||||
@ -147,15 +147,17 @@ func (c *Client) Connect() error {
|
||||
|
||||
c.host = h
|
||||
|
||||
// Log host identity and listen addresses
|
||||
addrs := c.host.Addrs()
|
||||
addrStrs := make([]string, 0, len(addrs))
|
||||
for _, a := range addrs { addrStrs = append(addrStrs, a.String()) }
|
||||
c.logger.Info("LibP2P host created",
|
||||
zap.String("peer_id", c.host.ID().String()),
|
||||
zap.Int("listen_addr_count", len(addrStrs)),
|
||||
zap.Strings("listen_addrs", addrStrs),
|
||||
)
|
||||
// Log host identity and listen addresses
|
||||
addrs := c.host.Addrs()
|
||||
addrStrs := make([]string, 0, len(addrs))
|
||||
for _, a := range addrs {
|
||||
addrStrs = append(addrStrs, a.String())
|
||||
}
|
||||
c.logger.Info("LibP2P host created",
|
||||
zap.String("peer_id", c.host.ID().String()),
|
||||
zap.Int("listen_addr_count", len(addrStrs)),
|
||||
zap.Strings("listen_addrs", addrStrs),
|
||||
)
|
||||
|
||||
// Create LibP2P PubSub with enhanced discovery for Anchat
|
||||
var ps *libp2ppubsub.PubSub
|
||||
@ -248,15 +250,12 @@ func (c *Client) Connect() error {
|
||||
c.logger.Warn("Failed to start peer discovery", zap.Error(err))
|
||||
}
|
||||
|
||||
// Start generic aggressive peer discovery for all apps
|
||||
go c.startAggressivePeerDiscovery()
|
||||
|
||||
// Start connection monitoring
|
||||
c.startConnectionMonitoring()
|
||||
|
||||
c.connected = true
|
||||
|
||||
c.logger.Info("Client connected", zap.String("namespace", c.getAppNamespace()))
|
||||
c.logger.Info("Client connected", zap.String("namespace", c.getAppNamespace()))
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -299,7 +298,7 @@ func (c *Client) Disconnect() error {
|
||||
|
||||
c.connected = false
|
||||
|
||||
c.logger.Info("Client disconnected")
|
||||
c.logger.Info("Client disconnected")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -1,33 +1,17 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.debros.io/DeBros/network/pkg/constants"
|
||||
"git.debros.io/DeBros/network/pkg/config"
|
||||
"github.com/multiformats/go-multiaddr"
|
||||
)
|
||||
|
||||
// DefaultBootstrapPeers returns the library's default bootstrap peer multiaddrs.
|
||||
func DefaultBootstrapPeers() []string {
|
||||
// Development local-only override
|
||||
if truthy(os.Getenv("NETWORK_DEV_LOCAL")) {
|
||||
if ma := os.Getenv("LOCAL_BOOTSTRAP_MULTIADDR"); ma != "" {
|
||||
return []string{ma}
|
||||
}
|
||||
// Try to auto-resolve local bootstrap peer multiaddr from peer.info
|
||||
if ma, ok := readLocalPeerInfoMultiaddr(); ok {
|
||||
return []string{ma}
|
||||
}
|
||||
// Fallback to localhost transport without peer ID (connect will warn and skip)
|
||||
return []string{"/ip4/127.0.0.1/tcp/4001"}
|
||||
}
|
||||
peers := constants.GetBootstrapPeers()
|
||||
out := make([]string, len(peers))
|
||||
copy(out, peers)
|
||||
return out
|
||||
var cfg *config.Config
|
||||
return cfg.Discovery.BootstrapPeers
|
||||
}
|
||||
|
||||
// truthy reports if s is a common truthy string.
|
||||
@ -43,21 +27,11 @@ func truthy(s string) bool {
|
||||
// DefaultDatabaseEndpoints returns default DB HTTP endpoints derived from default bootstrap peers.
|
||||
// Port defaults to RQLite HTTP 5001, or RQLITE_PORT if set.
|
||||
func DefaultDatabaseEndpoints() []string {
|
||||
port := 5001
|
||||
if v := os.Getenv("RQLITE_PORT"); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil && n > 0 {
|
||||
port = n
|
||||
}
|
||||
}
|
||||
|
||||
// Development local-only override
|
||||
if truthy(os.Getenv("NETWORK_DEV_LOCAL")) {
|
||||
return []string{"http://127.0.0.1:" + strconv.Itoa(port)}
|
||||
}
|
||||
|
||||
var cfg *config.Config
|
||||
peers := DefaultBootstrapPeers()
|
||||
port := cfg.Database.RQLitePort
|
||||
if len(peers) == 0 {
|
||||
return []string{"http://localhost:" + strconv.Itoa(port)}
|
||||
return []string{"http://localhost:" + strconv.Itoa(cfg.Database.RQLitePort)}
|
||||
}
|
||||
|
||||
endpoints := make([]string, 0, len(peers))
|
||||
@ -95,16 +69,24 @@ func endpointFromMultiaddr(ma multiaddr.Multiaddr, port int) string {
|
||||
host = v
|
||||
}
|
||||
if host == "" {
|
||||
if v, err := ma.ValueForProtocol(multiaddr.P_DNS4); err == nil && v != "" { host = v }
|
||||
if v, err := ma.ValueForProtocol(multiaddr.P_DNS4); err == nil && v != "" {
|
||||
host = v
|
||||
}
|
||||
}
|
||||
if host == "" {
|
||||
if v, err := ma.ValueForProtocol(multiaddr.P_DNS6); err == nil && v != "" { host = v }
|
||||
if v, err := ma.ValueForProtocol(multiaddr.P_DNS6); err == nil && v != "" {
|
||||
host = v
|
||||
}
|
||||
}
|
||||
if host == "" {
|
||||
if v, err := ma.ValueForProtocol(multiaddr.P_IP4); err == nil && v != "" { host = v }
|
||||
if v, err := ma.ValueForProtocol(multiaddr.P_IP4); err == nil && v != "" {
|
||||
host = v
|
||||
}
|
||||
}
|
||||
if host == "" {
|
||||
if v, err := ma.ValueForProtocol(multiaddr.P_IP6); err == nil && v != "" { host = v }
|
||||
if v, err := ma.ValueForProtocol(multiaddr.P_IP6); err == nil && v != "" {
|
||||
host = v
|
||||
}
|
||||
}
|
||||
if host == "" {
|
||||
host = "localhost"
|
||||
@ -128,32 +110,3 @@ func dedupeStrings(in []string) []string {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// readLocalPeerInfoMultiaddr attempts to read the local bootstrap peer multiaddr from common dev paths.
|
||||
// It checks LOCAL_BOOTSTRAP_INFO (path), then ./data/bootstrap/peer.info, then ./data/peer.info.
|
||||
func readLocalPeerInfoMultiaddr() (string, bool) {
|
||||
candidates := make([]string, 0, 3)
|
||||
if p := strings.TrimSpace(os.Getenv("LOCAL_BOOTSTRAP_INFO")); p != "" {
|
||||
candidates = append(candidates, p)
|
||||
}
|
||||
candidates = append(candidates,
|
||||
filepath.Join(".", "data", "bootstrap", "peer.info"),
|
||||
filepath.Join(".", "data", "peer.info"),
|
||||
)
|
||||
|
||||
for _, p := range candidates {
|
||||
b, err := os.ReadFile(p)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
s := strings.TrimSpace(string(b))
|
||||
if s == "" {
|
||||
continue
|
||||
}
|
||||
// expect a full multiaddr with /p2p/<peerID>
|
||||
if strings.Contains(s, "/p2p/") {
|
||||
return s, true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
@ -1,48 +0,0 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// startAggressivePeerDiscovery implements aggressive peer discovery for non-Anchat apps
|
||||
func (c *Client) startAggressivePeerDiscovery() {
|
||||
ticker := time.NewTicker(3 * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
for i := 0; i < 20; i++ { // ~1 minute
|
||||
<-ticker.C
|
||||
if !c.isConnected() { return }
|
||||
|
||||
connectedPeers := c.host.Network().Peers()
|
||||
routingCount := 0
|
||||
if c.dht != nil {
|
||||
routingPeers := c.dht.RoutingTable().ListPeers()
|
||||
routingCount = len(routingPeers)
|
||||
for _, pid := range routingPeers {
|
||||
if pid == c.host.ID() { continue }
|
||||
already := false
|
||||
for _, cp := range connectedPeers { if cp == pid { already = true; break } }
|
||||
if !already {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
pi := c.host.Peerstore().PeerInfo(pid)
|
||||
if len(pi.Addrs) > 0 {
|
||||
if err := c.host.Connect(ctx, pi); err == nil {
|
||||
c.logger.Debug("Connected to DHT peer", zap.String("peer", pid.String()))
|
||||
}
|
||||
}
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
if i%10 == 0 {
|
||||
c.logger.Debug("Peer discovery status",
|
||||
zap.Int("iteration", i+1),
|
||||
zap.Int("connected_peers", len(connectedPeers)),
|
||||
zap.Int("routing_peers", routingCount),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -4,17 +4,16 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.debros.io/DeBros/network/pkg/storage"
|
||||
|
||||
"git.debros.io/DeBros/network/pkg/anyoneproxy"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
"github.com/multiformats/go-multiaddr"
|
||||
"github.com/rqlite/gorqlite"
|
||||
"git.debros.io/DeBros/network/pkg/anyoneproxy"
|
||||
)
|
||||
|
||||
// DatabaseClientImpl implements DatabaseClient
|
||||
@ -184,15 +183,6 @@ func (d *DatabaseClientImpl) getRQLiteNodes() []string {
|
||||
return dedupeStrings(normalizeEndpoints(d.client.config.DatabaseEndpoints))
|
||||
}
|
||||
|
||||
// 2) Backward compatibility: RQLITE_NODES environment variable
|
||||
if raw := os.Getenv("RQLITE_NODES"); strings.TrimSpace(raw) != "" {
|
||||
// split by comma or whitespace
|
||||
parts := splitCSVOrSpace(raw)
|
||||
if len(parts) > 0 {
|
||||
return dedupeStrings(normalizeEndpoints(parts))
|
||||
}
|
||||
}
|
||||
|
||||
// 3) Fallback to library defaults derived from bootstrap peers
|
||||
return DefaultDatabaseEndpoints()
|
||||
}
|
||||
|
@ -3,8 +3,6 @@ package client
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -139,21 +137,6 @@ func DefaultClientConfig(appName string) *ClientConfig {
|
||||
peers := DefaultBootstrapPeers()
|
||||
endpoints := DefaultDatabaseEndpoints()
|
||||
|
||||
// Development local-only override via env
|
||||
if isTruthyEnv("NETWORK_DEV_LOCAL") {
|
||||
port := 5001
|
||||
if v := os.Getenv("RQLITE_PORT"); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil && n > 0 {
|
||||
port = n
|
||||
}
|
||||
}
|
||||
endpoints = []string{fmt.Sprintf("http://127.0.0.1:%d", port)}
|
||||
if ma := os.Getenv("LOCAL_BOOTSTRAP_MULTIADDR"); ma != "" {
|
||||
peers = []string{ma}
|
||||
}
|
||||
// else: keep the peers from DefaultBootstrapPeers() which handles NETWORK_DEV_LOCAL appropriately
|
||||
}
|
||||
|
||||
return &ClientConfig{
|
||||
AppName: appName,
|
||||
DatabaseName: fmt.Sprintf("%s_db", appName),
|
||||
@ -164,14 +147,3 @@ func DefaultClientConfig(appName string) *ClientConfig {
|
||||
RetryDelay: time.Second * 5,
|
||||
}
|
||||
}
|
||||
|
||||
// isTruthyEnv returns true if the env var is set to a common truthy value.
|
||||
func isTruthyEnv(key string) bool {
|
||||
v := os.Getenv(key)
|
||||
switch v {
|
||||
case "1", "true", "TRUE", "True", "yes", "YES", "on", "ON":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -1,86 +0,0 @@
|
||||
package constants
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"git.debros.io/DeBros/network/pkg/config"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
"github.com/multiformats/go-multiaddr"
|
||||
)
|
||||
|
||||
// Bootstrap node configuration
|
||||
var (
|
||||
// BootstrapAddresses are the full multiaddrs for bootstrap nodes
|
||||
BootstrapAddresses []string
|
||||
|
||||
// BootstrapPort is the default port for bootstrap nodes (LibP2P)
|
||||
BootstrapPort int = 4001
|
||||
|
||||
// Primary bootstrap address (first in the list) - for backward compatibility
|
||||
BootstrapAddress string
|
||||
)
|
||||
|
||||
// Initialize bootstrap configuration (no .env loading; defaults only)
|
||||
func init() {
|
||||
setDefaultBootstrapConfig()
|
||||
updateBackwardCompatibilityConstants()
|
||||
}
|
||||
|
||||
// setDefaultBootstrapConfig sets default bootstrap configuration for local development
|
||||
func setDefaultBootstrapConfig() {
|
||||
var cfg *config.Config
|
||||
BootstrapAddresses = cfg.Discovery.BootstrapPeers
|
||||
BootstrapPort = cfg.Discovery.BootstrapPort
|
||||
}
|
||||
|
||||
// updateBackwardCompatibilityConstants updates the single constants for backward compatibility
|
||||
func updateBackwardCompatibilityConstants() {
|
||||
if len(BootstrapAddresses) > 0 {
|
||||
BootstrapAddress = BootstrapAddresses[0]
|
||||
}
|
||||
}
|
||||
|
||||
// GetBootstrapPeers returns a copy of all bootstrap peer addresses
|
||||
func GetBootstrapPeers() []string {
|
||||
if len(BootstrapAddresses) == 0 {
|
||||
setDefaultBootstrapConfig()
|
||||
updateBackwardCompatibilityConstants()
|
||||
}
|
||||
peers := make([]string, len(BootstrapAddresses))
|
||||
copy(peers, BootstrapAddresses)
|
||||
return peers
|
||||
}
|
||||
|
||||
// GetBootstrapPeerIDs extracts and returns peer IDs from bootstrap addresses
|
||||
func GetBootstrapPeerIDs() []string {
|
||||
if len(BootstrapAddresses) == 0 {
|
||||
setDefaultBootstrapConfig()
|
||||
updateBackwardCompatibilityConstants()
|
||||
}
|
||||
|
||||
var ids []string
|
||||
for _, addr := range BootstrapAddresses {
|
||||
if ma, err := multiaddr.NewMultiaddr(addr); err == nil {
|
||||
if pi, err := peer.AddrInfoFromP2pAddr(ma); err == nil {
|
||||
ids = append(ids, pi.ID.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// AddBootstrapPeer adds a new bootstrap peer address (runtime only)
|
||||
func AddBootstrapPeer(address string) {
|
||||
BootstrapAddresses = append(BootstrapAddresses, address)
|
||||
updateBackwardCompatibilityConstants()
|
||||
}
|
||||
|
||||
// GetEnvironmentInfo returns information about the current configuration
|
||||
func GetEnvironmentInfo() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"bootstrap_peers": GetBootstrapPeers(),
|
||||
"bootstrap_peer_ids": GetBootstrapPeerIDs(),
|
||||
"bootstrap_port": BootstrapPort,
|
||||
"environment": os.Getenv("ENVIRONMENT"),
|
||||
}
|
||||
}
|
@ -136,11 +136,6 @@ func coloredConsoleEncoder(enableColors bool) zapcore.Encoder {
|
||||
|
||||
// NewColoredLogger creates a new colored logger
|
||||
func NewColoredLogger(component Component, enableColors bool) (*ColoredLogger, error) {
|
||||
// Auto-detect color support if not explicitly disabled
|
||||
if enableColors {
|
||||
enableColors = supportsColor()
|
||||
}
|
||||
|
||||
// Create encoder
|
||||
encoder := coloredConsoleEncoder(enableColors)
|
||||
|
||||
@ -206,40 +201,6 @@ func (l *ColoredLogger) ComponentDebug(component Component, msg string, fields .
|
||||
l.Debug(msg, fields...)
|
||||
}
|
||||
|
||||
// supportsColor detects if the terminal supports color
|
||||
func supportsColor() bool {
|
||||
// Check environment variables
|
||||
term := os.Getenv("TERM")
|
||||
colorTerm := os.Getenv("COLORTERM")
|
||||
|
||||
// Common indicators of color support
|
||||
if colorTerm != "" {
|
||||
return true
|
||||
}
|
||||
|
||||
if term != "" {
|
||||
colorTerms := []string{
|
||||
"xterm", "xterm-color", "xterm-256color",
|
||||
"screen", "screen-256color",
|
||||
"tmux", "tmux-256color",
|
||||
"ansi", "color",
|
||||
}
|
||||
|
||||
for _, ct := range colorTerms {
|
||||
if strings.Contains(term, ct) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we're not in a pipe/redirect
|
||||
if fileInfo, _ := os.Stdout.Stat(); fileInfo != nil {
|
||||
return (fileInfo.Mode() & os.ModeCharDevice) == os.ModeCharDevice
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// StandardLogger provides colored standard library compatible logging
|
||||
type StandardLogger struct {
|
||||
logger *ColoredLogger
|
||||
|
@ -184,8 +184,6 @@ func (n *Node) startLibP2P() error {
|
||||
|
||||
n.host = h
|
||||
|
||||
// DHT removed - incompatible with Anyone proxy anonymity architecture
|
||||
|
||||
// Log configured bootstrap peers
|
||||
if len(n.config.Discovery.BootstrapPeers) > 0 {
|
||||
n.logger.ComponentInfo(logging.ComponentNode, "Configured bootstrap peers",
|
||||
|
@ -1,48 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/libp2p/go-libp2p/core/crypto"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Generate a fixed identity
|
||||
priv, pub, err := crypto.GenerateKeyPairWithReader(crypto.Ed25519, 2048, rand.Reader)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Get peer ID
|
||||
peerID, err := peer.IDFromPublicKey(pub)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Printf("Generated Peer ID: %s\n", peerID.String())
|
||||
|
||||
// Marshal private key
|
||||
data, err := crypto.MarshalPrivateKey(priv)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Create data directory
|
||||
dataDir := "./data/bootstrap"
|
||||
if err := os.MkdirAll(dataDir, 0755); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Save identity
|
||||
identityFile := filepath.Join(dataDir, "identity.key")
|
||||
if err := os.WriteFile(identityFile, data, 0600); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Printf("Identity saved to: %s\n", identityFile)
|
||||
fmt.Printf("Bootstrap address: /ip4/127.0.0.1/tcp/4001/p2p/%s\n", peerID.String())
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user