From 446c62bcd9e4cfb8b6e3ae052887e6ac3e066daf Mon Sep 17 00:00:00 2001 From: Kleissner Date: Wed, 17 Nov 2021 17:37:04 +0100 Subject: [PATCH] Explicitly define locations for important files and folders in the config file. This removes the hardcoded paths for the blockchain and warehouse. --- .gitignore | 1 - Blockchain.go | 5 +---- Config Default.yaml | 6 +++++- Config.go | 13 ++++++++++++- Network IPv6 Multicast.go | 2 +- Warehouse.go | 5 +---- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 092f84b..632de23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ *.exe log.txt *debug_bin -self.* test.* \ No newline at end of file diff --git a/Blockchain.go b/Blockchain.go index b74434e..cbcdba9 100644 --- a/Blockchain.go +++ b/Blockchain.go @@ -15,14 +15,11 @@ import ( // UserBlockchain is the user's blockchain and exports functions to directly read and write it var UserBlockchain *blockchain.Blockchain -// filenameUserBlockchain is the filename/folder of the user's blockchain -const filenameUserBlockchain = "self.blockchain" - // initUserBlockchain initializes the users blockchain. It creates the blockchain file if it does not exist already. // If it is corrupted, it will log the error and exit the process. func initUserBlockchain() { var err error - UserBlockchain, err = blockchain.Init(peerPrivateKey, filenameUserBlockchain) + UserBlockchain, err = blockchain.Init(peerPrivateKey, config.BlockchainMain) if err != nil { Filters.LogError("initUserBlockchain", "error: %s\n", err.Error()) diff --git a/Config Default.yaml b/Config Default.yaml index 919c20d..df10cc4 100644 --- a/Config Default.yaml +++ b/Config Default.yaml @@ -1,4 +1,8 @@ -LogFile: Log.txt +# Locations of important files and folders +LogFile: "data/log.txt" # Log file. It contains informational and error messages. +BlockchainMain: "data/blockchain main/" # Blockchain main stores the end-users blockchain data. It contains meta data of shared files, profile data, and social interactions. +BlockchainGlobal: "data/blockchain global/" # Blockchain global stores blockchain data from global users. +WarehouseMain: "data/warehouse main/" # Warehouse main stores the actual data of files shared by the end-user. # Listen defines all IP:Port combinations to listen on. If empty, it will listen on all IPs automatically on available ports. # IPv6 must be in the form "[IPv6]:Port". This setting is only recommended to be set on servers. diff --git a/Config.go b/Config.go index 04dc480..001cc66 100644 --- a/Config.go +++ b/Config.go @@ -11,6 +11,7 @@ import ( "io/ioutil" "log" "os" + "path" "gopkg.in/yaml.v3" ) @@ -19,8 +20,13 @@ import ( const Version = "Alpha 4/15.11.2021" var config struct { - LogFile string `yaml:"LogFile"` // Log file + // Locations of important files and folders + LogFile string `yaml:"LogFile"` // Log file. It contains informational and error messages. + BlockchainMain string `yaml:"BlockchainMain"` // Blockchain main stores the end-users blockchain data. It contains meta data of shared files, profile data, and social interactions. + BlockchainGlobal string `yaml:"BlockchainGlobal"` // Blockchain global stores blockchain data from global users. + WarehouseMain string `yaml:"WarehouseMain"` // Warehouse main stores the actual data of files shared by the end-user. + // Listen settings Listen []string `yaml:"Listen"` // IP:Port combinations ListenWorkers int `yaml:"ListenWorkers"` // Count of workers to process incoming raw packets. Default 2. @@ -118,6 +124,11 @@ func saveConfig() { // InitLog redirects subsequent log messages into the default log file specified in the configuration func InitLog() (err error) { + // create the directory to the log file if specified + if directory, _ := path.Split(config.LogFile); directory != "" { + os.MkdirAll(directory, os.ModePerm) + } + logFile, err := os.OpenFile(config.LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { return err diff --git a/Network IPv6 Multicast.go b/Network IPv6 Multicast.go index 3144337..eee1d5e 100644 --- a/Network IPv6 Multicast.go +++ b/Network IPv6 Multicast.go @@ -63,7 +63,7 @@ func (network *Network) MulticastIPv6Join() (err error) { joinMulticastGroup := func(iface *net.Interface) (err error) { pc := ipv6.NewPacketConn(network.multicastSocket) if err := pc.JoinGroup(iface, &net.UDPAddr{IP: network.multicastIP}); err != nil { - Filters.LogError("MulticastIPv6Join", "join multicast group iface '%s' multicast IP '%s' listen on IP '%s' port '%d': %v\n", iface.Name, network.multicastIP.String(), network.address.IP.String(), ipv6MulticastPort, err) + //Filters.LogError("MulticastIPv6Join", "join multicast group iface '%s' multicast IP '%s' listen on IP '%s' port '%d': %v\n", iface.Name, network.multicastIP.String(), network.address.IP.String(), ipv6MulticastPort, err) return err } diff --git a/Warehouse.go b/Warehouse.go index 54d8773..799bc15 100644 --- a/Warehouse.go +++ b/Warehouse.go @@ -13,12 +13,9 @@ import ( // UserWarehouse is the user's warehouse for storing files that are shared var UserWarehouse *warehouse.Warehouse -// folderUserWarehouse is the folder of the user's warehouse -const folderUserWarehouse = "warehouse" - func initUserWarehouse() { var err error - UserWarehouse, err = warehouse.Init(folderUserWarehouse) + UserWarehouse, err = warehouse.Init(config.WarehouseMain) if err != nil { Filters.LogError("initUserWarehouse", "error: %s\n", err.Error())