1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00

added check if key hash is the same when asking for key updates

This commit is contained in:
postmannen 2022-05-16 11:20:39 +02:00
parent 3bd54d9cfc
commit 45d304bf6f

View file

@ -2064,7 +2064,11 @@ func (m methodREQPublicKeysGet) handler(proc process, message Message, node stri
case <-ctx.Done(): case <-ctx.Done():
// case out := <-outCh: // case out := <-outCh:
case <-outCh: case <-outCh:
// Using a func here to set the scope of the lock, and then be able to
// defer the unlock when leaving that scope.
func() {
proc.centralAuth.pki.nodesAcked.mu.Lock() proc.centralAuth.pki.nodesAcked.mu.Lock()
defer proc.centralAuth.pki.nodesAcked.mu.Unlock()
// TODO: We should probably create a hash of the current map content, // TODO: We should probably create a hash of the current map content,
// store it alongside the KeyMap, and send both the KeyMap and hash // store it alongside the KeyMap, and send both the KeyMap and hash
// back. We can then later send that hash when asking for keys, compare // back. We can then later send that hash when asking for keys, compare
@ -2073,18 +2077,25 @@ func (m methodREQPublicKeysGet) handler(proc process, message Message, node stri
fmt.Printf(" <---- methodREQPublicKeysGet: received hash from NODE=%v, HASH=%v\n", message.FromNode, message.Data) fmt.Printf(" <---- methodREQPublicKeysGet: received hash from NODE=%v, HASH=%v\n", message.FromNode, message.Data)
// Check if the received hash is the same as the one currently active,
if bytes.Equal(proc.centralAuth.pki.nodesAcked.keysAndHash.Hash[:], message.Data) {
fmt.Printf("\n ------------ NODE AND CENTRAL ARE EQUAL, NOTHING TO DO, EXITING HANDLER\n\n")
return
}
fmt.Printf("\n ------------ NODE AND CENTRAL WERE NOT EQUAL, PREPARING TO SEND NEW VERSION OF KEYS\n\n")
fmt.Printf(" * methodREQPublicKeysGet: marshalling new keys and hash to send: map=%v, hash=%v\n\n", proc.centralAuth.pki.nodesAcked.keysAndHash.Keys, proc.centralAuth.pki.nodesAcked.keysAndHash.Hash) fmt.Printf(" * methodREQPublicKeysGet: marshalling new keys and hash to send: map=%v, hash=%v\n\n", proc.centralAuth.pki.nodesAcked.keysAndHash.Keys, proc.centralAuth.pki.nodesAcked.keysAndHash.Hash)
b, err := json.Marshal(proc.centralAuth.pki.nodesAcked.keysAndHash) b, err := json.Marshal(proc.centralAuth.pki.nodesAcked.keysAndHash)
proc.centralAuth.pki.nodesAcked.mu.Unlock()
if err != nil { if err != nil {
er := fmt.Errorf("error: REQPublicKeysGet, failed to marshal keys map: %v", err) er := fmt.Errorf("error: REQPublicKeysGet, failed to marshal keys map: %v", err)
proc.errorKernel.errSend(proc, message, er) proc.errorKernel.errSend(proc, message, er)
} }
fmt.Printf("\n ----> methodREQPublicKeysGet: SENDING KEYS TO NODE=%v\n", message.FromNode) fmt.Printf("\n ----> methodREQPublicKeysGet: SENDING KEYS TO NODE=%v\n", message.FromNode)
newReplyMessage(proc, message, b) newReplyMessage(proc, message, b)
}()
} }
}() }()