1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-03-31 01:24:31 +00:00

changed debug print to slog

This commit is contained in:
postmannen 2025-01-10 06:30:19 +01:00
parent 940f336333
commit 48ec092737
4 changed files with 28 additions and 34 deletions

View file

@ -199,7 +199,6 @@ 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))

View file

@ -282,27 +282,21 @@ func (e *errorKernel) infoSend(proc process, msg Message, err error) {
}
func (e *errorKernel) logError(err error) {
if e.configuration.LogLevel == string(logError) {
fmt.Printf(" ,,,,,,,,,,,,,,,,,,,,,,,,, LOGGING ERROR: %v\n", err)
slog.Error("error", err)
}
slog.Error("error", err)
}
func (e *errorKernel) logInfo(err error) {
if e.configuration.LogLevel == string(logInfo) {
slog.Info(err.Error())
}
slog.Info(err.Error())
}
func (e *errorKernel) logWarn(err error) {
if e.configuration.LogLevel == string(logWarning) {
slog.Warn(err.Error())
}
slog.Warn("warn", err.Error())
}
func (e *errorKernel) logDebug(err error) {
if e.configuration.LogLevel == string(logDebug) {
slog.Debug(err.Error())
slog.Debug("debug", err.Error())
}
}

View file

@ -419,22 +419,17 @@ func (n *nodeAuth) verifySignature(m Message) bool {
var ok bool
err := func() error {
fmt.Printf(" ********************* DEBUG1 BEFORE LOCK: %v\n", m.Method)
n.publicKeys.mu.Lock()
defer n.publicKeys.mu.Unlock()
fmt.Printf(" ********************* DEBUG2 LOCK: %v\n", m.Method)
pubKey := n.publicKeys.keysAndHash.Keys[m.FromNode]
if len(pubKey) != 32 {
err := fmt.Errorf("length of publicKey not equal to 32: %v", len(pubKey))
fmt.Printf(" ********************* DEBUG3 LOCK: %v, ERROR: %v\n", m.Method, err)
return err
}
fmt.Printf(" ********************* DEBUG4 LOCK: %v\n", m.Method)
ok = ed25519.Verify(pubKey, []byte(argsStringified), m.ArgSignature)
fmt.Printf(" ********************* DEBUG AFTER LOCK: %v\n", m.Method)
return nil
}()

View file

@ -492,54 +492,60 @@ func (p process) callHandler(message Message, thisNode string) {
conf := p.nodeAuth.configuration
var er error
fmt.Printf("*** --- DEBUG: from: %v, method: %v, EnableSignatureCheck=%v, EnableAclCheck=%v\n", message.FromNode, message.Method, conf.EnableSignatureCheck, conf.EnableAclCheck)
er = fmt.Errorf("callhandler: got message from: %v, method: %v, EnableSignatureCheck=%v, EnableAclCheck=%v", message.FromNode, message.Method, conf.EnableSignatureCheck, conf.EnableAclCheck)
p.errorKernel.logDebug(er)
switch {
// If no checking enabled we should just allow the message.
case !conf.EnableSignatureCheck && !conf.EnableAclCheck:
fmt.Printf(" *** DEBUG: NO CHECK OF SIG OR ACL FLAG ENABLED, EXECUTING HANDLER: %v\n", message.Method)
er := fmt.Errorf("NO CHECK OF SIG OR ACL FLAG ENABLED, EXECUTING HANDLER: %v", message.Method)
p.errorKernel.logDebug(er)
executeHandler(p, message, thisNode)
return
// If only sig check enabled, and sig OK, we should allow the message.
case conf.EnableSignatureCheck && !conf.EnableAclCheck:
fmt.Printf("--------------------DEBUG1-----------------------: %v\n", message.Method)
sigOK := p.nodeAuth.verifySignature(message)
fmt.Printf("--------------------DEBUG2-----------------------: %v\n", message.Method)
fmt.Printf(" *** DEBUG: CHECK SIG TRUE: %v\n", message.Method)
er = fmt.Errorf("CHECK SIG TRUE: %v", message.Method)
p.errorKernel.logDebug(er)
if sigOK {
fmt.Printf(" *** DEBUG: CHECK SIG TRUE EVALUATED TO TRUE, EXECUTING HANDLER: %v\n", message.Method)
er = fmt.Errorf("CHECK SIG TRUE EVALUATED TO TRUE, EXECUTING HANDLER: %v", message.Method)
p.errorKernel.logDebug(er)
executeHandler(p, message, thisNode)
return
}
fmt.Printf(" *** DEBUG: CHECK SIG TRUE EVALUATED TO FALSE: %v\n", message.Method)
er = fmt.Errorf("callHandler: Only signature checking enabled, sigOK=%v, method %v", sigOK, message.Method)
er = fmt.Errorf("CHECK SIG TRUE EVALUATED TO FALSE: %v", message.Method)
p.errorKernel.logDebug(er)
// If both sig and acl check enabled, and sig and acl OK, we should allow the message.
case conf.EnableSignatureCheck && conf.EnableAclCheck:
sigOK := p.nodeAuth.verifySignature(message)
aclOK := p.nodeAuth.verifyAcl(message)
fmt.Printf(" *** DEBUG: CHECK SIG AND ACK TRUE: %v\n", message.Method)
er = fmt.Errorf("CHECK SIG AND ACK TRUE: %v", message.Method)
p.errorKernel.logDebug(er)
if sigOK && aclOK {
fmt.Printf(" *** DEBUG: CHECK SIG AND ACK TRUE EVALUATED TO FALSE, EXECUTING HANDLER: %v\n", message.Method)
er = fmt.Errorf("CHECK SIG AND ACK TRUE EVALUATED TO FALSE, EXECUTING HANDLER: %v", message.Method)
p.errorKernel.logDebug(er)
executeHandler(p, message, thisNode)
return
}
fmt.Printf(" *** DEBUG: CHECK SIG AND ACK TRUE EVALUATED TO FALSE: %v\n", message.Method)
er = fmt.Errorf("callHandler:both signature and acl checking enabled, sigOK=%v, aclOK=%v, method=%v", sigOK, aclOK, message.Method)
er = fmt.Errorf("CHECK SIG AND ACK TRUE EVALUATED TO FALSE: %v", message.Method)
p.errorKernel.logDebug(er)
default:
er = fmt.Errorf("callHandler: None of the verify flags matched, not doing handler for message, method=%v", message.Method)
fmt.Printf(" *** DEBUG: WRONG CHECKING FLAGS FOR ACL OR SIG: %v\n", message.Method)
p.errorKernel.logDebug(er)
}
p.errorKernel.logDebug(er)
er = fmt.Errorf("error: subscriberHandler: ACL or Signature were verified not-OK, doing nothing")
p.errorKernel.errSend(p, message, er, logWarning)
fmt.Printf("*** DEBUG: %v\n", er)
}()