68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type Config struct {
|
|
Port int
|
|
AuthCode string
|
|
PeerID string
|
|
Peers []string
|
|
Domain string
|
|
NodesEnabled bool
|
|
CrawlerEnabled bool
|
|
WebsiteEnabled bool
|
|
LogLevel int
|
|
HardCacheDuration time.Duration
|
|
}
|
|
|
|
var defaultConfig = Config{
|
|
Port: 5000,
|
|
Domain: "localhost",
|
|
Peers: []string{},
|
|
AuthCode: generateStrongRandomString(64),
|
|
NodesEnabled: true,
|
|
CrawlerEnabled: true,
|
|
WebsiteEnabled: true,
|
|
LogLevel: 1,
|
|
HardCacheDuration: 0,
|
|
}
|
|
|
|
const configFilePath = "config.ini"
|
|
|
|
var config Config
|
|
|
|
func main() {
|
|
err := initConfig()
|
|
if err != nil {
|
|
printErr("Error during initialization:")
|
|
return
|
|
}
|
|
|
|
loadNodeConfig()
|
|
go startFileWatcher()
|
|
go checkMasterHeartbeat()
|
|
|
|
if config.AuthCode == "" {
|
|
config.AuthCode = generateStrongRandomString(64)
|
|
printInfo("Generated connection code: %s\n", config.AuthCode)
|
|
saveConfig(config)
|
|
}
|
|
|
|
// Generate Host ID
|
|
hostID, nodeErr := generateHostID()
|
|
if nodeErr != nil {
|
|
printErr("Failed to generate host ID: %v", nodeErr)
|
|
}
|
|
config.PeerID = hostID
|
|
|
|
if len(config.Peers) > 0 {
|
|
time.Sleep(2 * time.Second) // Give some time for connections to establish
|
|
startElection()
|
|
}
|
|
|
|
go startNodeClient()
|
|
|
|
runServer()
|
|
}
|