mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-17 02:47:51 +01:00
Explicitly define locations for important files and folders in the config file.
This removes the hardcoded paths for the blockchain and warehouse.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,4 @@
|
||||
*.exe
|
||||
log.txt
|
||||
*debug_bin
|
||||
self.*
|
||||
test.*
|
||||
@@ -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())
|
||||
|
||||
@@ -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.
|
||||
|
||||
13
Config.go
13
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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user