node update sync wip
This commit is contained in:
parent
30aa3d0238
commit
8f913eca0d
5 changed files with 189 additions and 45 deletions
36
init.go
36
init.go
|
@ -2,17 +2,22 @@ package main
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Configuration structure
|
||||
type Config struct {
|
||||
Port int
|
||||
OpenSearch OpenSearchConfig
|
||||
Port int
|
||||
ConnectionCode string
|
||||
Peers []string
|
||||
OpenSearch OpenSearchConfig
|
||||
}
|
||||
|
||||
type OpenSearchConfig struct {
|
||||
|
@ -37,6 +42,9 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
// This is stupid
|
||||
loadNodeConfig()
|
||||
|
||||
// Start the main application
|
||||
runServer()
|
||||
}
|
||||
|
@ -74,6 +82,21 @@ func createConfig() error {
|
|||
if domain != "\n" {
|
||||
config.OpenSearch.Domain = domain[:len(domain)-1]
|
||||
}
|
||||
|
||||
fmt.Print("Do you want to connect to other nodes? (yes/no): ")
|
||||
connectNodes, _ := reader.ReadString('\n')
|
||||
if strings.TrimSpace(connectNodes) == "yes" {
|
||||
fmt.Println("Enter peer addresses (comma separated, e.g., http://localhost:5000,http://localhost:5001): ")
|
||||
peersStr, _ := reader.ReadString('\n')
|
||||
if peersStr != "\n" {
|
||||
config.Peers = strings.Split(strings.TrimSpace(peersStr), ",")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if config.ConnectionCode == "" {
|
||||
config.ConnectionCode = generateStrongRandomString(32)
|
||||
fmt.Printf("Generated connection code: %s\n", config.ConnectionCode)
|
||||
}
|
||||
|
||||
saveConfig(config)
|
||||
|
@ -114,3 +137,12 @@ func loadConfig() Config {
|
|||
|
||||
return config
|
||||
}
|
||||
|
||||
func generateStrongRandomString(length int) string {
|
||||
bytes := make([]byte, length)
|
||||
_, err := rand.Read(bytes)
|
||||
if err != nil {
|
||||
log.Fatalf("Error generating random string: %v", err)
|
||||
}
|
||||
return base64.URLEncoding.EncodeToString(bytes)[:length]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue