From 9a0fe9ae7a5a0560f2c8445dbd5028f5b0f7a235 Mon Sep 17 00:00:00 2001 From: postmannen Date: Thu, 9 Jan 2025 08:07:58 +0100 Subject: [PATCH] fixed error with missing database folder, also added sending all keys to to acked and not acked nodes --- central_auth_key_handling.go | 1 + requests_keys.go | 29 ++++++++--------------------- server.go | 11 ++++++++++- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/central_auth_key_handling.go b/central_auth_key_handling.go index ead8dd7..ca0de90 100644 --- a/central_auth_key_handling.go +++ b/central_auth_key_handling.go @@ -199,6 +199,7 @@ func (c *centralAuth) deletePublicKeys(proc process, msg Message, nodes []string // dbUpdatePublicKey will update the public key for a node in the db. func (p *pki) dbUpdatePublicKey(node string, value []byte) error { + fmt.Printf("\n ***** DEBUG: %v\n\n", p.db) err := p.db.Update(func(tx *bolt.Tx) error { //Create a bucket bu, err := tx.CreateBucketIfNotExists([]byte(p.bucketNamePublicKeys)) diff --git a/requests_keys.go b/requests_keys.go index 9e502a1..1d75a21 100644 --- a/requests_keys.go +++ b/requests_keys.go @@ -326,26 +326,16 @@ func methodKeysAllow(proc process, message Message, node string) ([]byte, error) // also able to send an update to them as well. func pushKeys(proc process, message Message, nodes []Node) error { er := fmt.Errorf("info: beginning of pushKeys, nodes=%v", nodes) - var knh []byte proc.errorKernel.logDebug(er) - err := func() error { - proc.centralAuth.pki.nodesAcked.mu.Lock() - defer proc.centralAuth.pki.nodesAcked.mu.Unlock() - - b, err := json.Marshal(proc.centralAuth.pki.nodesAcked.keysAndHash) - if err != nil { - er := fmt.Errorf("error: methodKeysAllow, failed to marshal keys map: %v", err) - return er - } - - copy(knh, b) - - return nil - }() + proc.centralAuth.pki.nodesAcked.mu.Lock() + defer proc.centralAuth.pki.nodesAcked.mu.Unlock() + // Create the data payload of the current allowed keys. + b, err := json.Marshal(proc.centralAuth.pki.nodesAcked.keysAndHash) if err != nil { - return err + er := fmt.Errorf("error: methodKeysAllow, failed to marshal keys map: %v", err) + proc.errorKernel.errSend(proc, message, er, logWarning) } // proc.centralAuth.pki.nodeNotAckedPublicKeys.mu.Lock() @@ -358,7 +348,7 @@ func pushKeys(proc process, message Message, nodes []Node) error { msg := Message{ ToNode: n, Method: KeysUpdateReceive, - Data: knh, + Data: b, ReplyMethod: None, ACKTimeout: 0, } @@ -369,9 +359,6 @@ func pushKeys(proc process, message Message, nodes []Node) error { proc.errorKernel.logDebug(er) } - proc.centralAuth.pki.nodesAcked.mu.Lock() - defer proc.centralAuth.pki.nodesAcked.mu.Unlock() - // Concatenate the current nodes in the keysAndHash map and the nodes // we got from the function argument when this function was called. nodeMap := make(map[Node]struct{}) @@ -390,7 +377,7 @@ func pushKeys(proc process, message Message, nodes []Node) error { msg := Message{ ToNode: n, Method: KeysUpdateReceive, - Data: knh, + Data: b, ReplyMethod: None, ACKTimeout: 0, } diff --git a/server.go b/server.go index 7401ae3..0783ddc 100644 --- a/server.go +++ b/server.go @@ -207,6 +207,15 @@ func NewServer(configuration *Configuration, version string) (*server, error) { } } + // Check if tmp folder for socket exists, if not create it + if _, err := os.Stat(configuration.DatabaseFolder); os.IsNotExist(err) { + err := os.MkdirAll(configuration.DatabaseFolder, 0770) + if err != nil { + cancel() + return nil, fmt.Errorf("error: failed to create database folder directory %v: %v", configuration.DatabaseFolder, err) + } + } + //var nodeAuth *nodeAuth //if configuration.EnableSignatureCheck { nodeAuth := newNodeAuth(configuration, errorKernel) @@ -258,7 +267,7 @@ func NewServer(configuration *Configuration, version string) (*server, error) { if configuration.SubscribersDataFolder == "" { return nil, fmt.Errorf("error: subscribersDataFolder value is empty, you need to provide the config or the flag value at startup %v: %v", configuration.SubscribersDataFolder, err) } - err := os.Mkdir(configuration.SubscribersDataFolder, 0770) + err := os.MkdirAll(configuration.SubscribersDataFolder, 0770) if err != nil { return nil, fmt.Errorf("error: failed to create data folder directory %v: %v", configuration.SubscribersDataFolder, err) }