From ca1ce3c53439053344456b2e7ef6d13ee5847122 Mon Sep 17 00:00:00 2001
From: postmannen <postmannen@gmail.com>
Date: Wed, 18 Dec 2024 15:47:05 +0100
Subject: [PATCH] updated key comments, and added doc section for central node

---
 central_auth_key_handling.go   | 16 ++++++++--------
 doc/src/SUMMARY.md             |  7 ++++++-
 doc/src/core_acl.md            |  1 +
 doc/src/core_audit_log.md      |  1 +
 doc/src/core_central.md        |  3 +++
 doc/src/core_hello_messages.md | 11 +++++++++++
 doc/src/core_signing_keys.md   |  1 +
 requests_std.go                |  5 +----
 8 files changed, 32 insertions(+), 13 deletions(-)
 create mode 100644 doc/src/core_acl.md
 create mode 100644 doc/src/core_audit_log.md
 create mode 100644 doc/src/core_central.md
 create mode 100644 doc/src/core_hello_messages.md
 create mode 100644 doc/src/core_signing_keys.md

diff --git a/central_auth_key_handling.go b/central_auth_key_handling.go
index 2000ed9..c4be790 100644
--- a/central_auth_key_handling.go
+++ b/central_auth_key_handling.go
@@ -133,14 +133,14 @@ func (c *centralAuth) addPublicKey(proc process, msg Message) {
 	}
 
 	c.pki.nodeNotAckedPublicKeys.mu.Lock()
-	existingNotAckedKey, ok := c.pki.nodeNotAckedPublicKeys.KeyMap[msg.FromNode]
-	// We only want to send one notification to the error kernel about new key detection,
-	// so we check if the values are the same as the one we already got before we continue
-	// with registering and logging for the the new key.
-	if ok && bytes.Equal(existingNotAckedKey, msg.Data) {
-		c.pki.nodeNotAckedPublicKeys.mu.Unlock()
-		return
-	}
+	// existingNotAckedKey, ok := c.pki.nodeNotAckedPublicKeys.KeyMap[msg.FromNode]
+	// // We only want to send one notification to the error kernel about new key detection,
+	// // so we check if the values are the same as the one we already got before we continue
+	// // with registering and logging for the the new key.
+	// if ok && bytes.Equal(existingNotAckedKey, msg.Data) {
+	// 	c.pki.nodeNotAckedPublicKeys.mu.Unlock()
+	// 	return
+	// }
 
 	c.pki.nodeNotAckedPublicKeys.KeyMap[msg.FromNode] = msg.Data
 	c.pki.nodeNotAckedPublicKeys.mu.Unlock()
diff --git a/doc/src/SUMMARY.md b/doc/src/SUMMARY.md
index 83fb5c6..03c02c5 100644
--- a/doc/src/SUMMARY.md
+++ b/doc/src/SUMMARY.md
@@ -20,6 +20,11 @@
 - [{{CTRL_DATA}} variable](./core_messaging_CTRL_DATA.md)
 - [{{CTRL_FILE}} variable](./core_messaging_CTRL_FILE.md)
 - [Errors](./core_errors.md)
+- [central](./core_central.md)
+  - [hello messages](./core_hello_messages.md)
+  - [signing keys](./core_signing_keys.md)
+  - [ACL](./core_acl.md)
+  - [audit log](./core_audit_log.md)
 
 # Examples standard messages
 
@@ -32,4 +37,4 @@
 
 # Using ctrl
 
-- [ctrl as github action runner](usecase-ctrl-as-github-action-runner)
\ No newline at end of file
+- [ctrl as github action runner](usecase-ctrl-as-github-action-runner)
diff --git a/doc/src/core_acl.md b/doc/src/core_acl.md
new file mode 100644
index 0000000..8cd8bbc
--- /dev/null
+++ b/doc/src/core_acl.md
@@ -0,0 +1 @@
+# ACL
diff --git a/doc/src/core_audit_log.md b/doc/src/core_audit_log.md
new file mode 100644
index 0000000..0698f0f
--- /dev/null
+++ b/doc/src/core_audit_log.md
@@ -0,0 +1 @@
+# audit log
diff --git a/doc/src/core_central.md b/doc/src/core_central.md
new file mode 100644
index 0000000..fec3bb7
--- /dev/null
+++ b/doc/src/core_central.md
@@ -0,0 +1,3 @@
+# central
+
+To get functionality like central audit log, signing keys, authorization with ACL's and hello messages one node should be started with the node name **central**
diff --git a/doc/src/core_hello_messages.md b/doc/src/core_hello_messages.md
new file mode 100644
index 0000000..bc6c30e
--- /dev/null
+++ b/doc/src/core_hello_messages.md
@@ -0,0 +1,11 @@
+# Hello messages
+
+All nodes can send hello messages to inform that they are up. The interval between sending a hello message can be set with the `START_PUB_HELLO` environment variable.
+
+Hello messages are sent to the node with the name **central**. When a hello message are received on central, information with the time and node name will be stored in the **ctrl data folder**
+
+## Public keys
+
+ctrl nodes can use ed25519 keys for signing messages, so each ctrl instance will generate a public and private key pair on startup. The public keys are sent to the central server with the hello messages.
+
+To read more about signing keys here: [signing keys](./core_signing_keys.md)
diff --git a/doc/src/core_signing_keys.md b/doc/src/core_signing_keys.md
new file mode 100644
index 0000000..f8bed16
--- /dev/null
+++ b/doc/src/core_signing_keys.md
@@ -0,0 +1 @@
+# signing keys
diff --git a/requests_std.go b/requests_std.go
index 2b49e69..825b97a 100644
--- a/requests_std.go
+++ b/requests_std.go
@@ -49,10 +49,7 @@ func methodHello(proc process, message Message, node string) ([]byte, error) {
 		proc.errorKernel.errSend(proc, message, er, logWarning)
 	}
 
-	// --------------------------
-
-	// send the message to the procFuncCh which is running alongside the process
-	// and can hold registries and handle special things for an individual process.
+	// The handling of the public key that is in the message.Data field is handled in the procfunc.
 	proc.procFuncCh <- message
 
 	ackMsg := []byte("confirmed from: " + node + ": " + fmt.Sprint(message.ID))