Skip to content

Commit

Permalink
adding delete key share message type
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo committed Jun 27, 2019
1 parent e017848 commit 4825795
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions message/messagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ const (
None Type = iota
SendKeyShare
AskForSigShare
DeleteKeyShare
)

// TypeToString transforms a message type into a string. Useful for debugging.
var TypeToString = map[Type]string{
None: "Undefined type",
SendKeyShare: "Send Key Share",
AskForSigShare: "Ask for Signature Share",
DeleteKeyShare: "Delete Key Share",
}

func (mType Type) String() string {
Expand Down
20 changes: 20 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ func (server *Server) Listen() {
break
}
resp.AddMessage(encodedSigShare)
case message.DeleteKeyShare:
log.Printf("Server %s is asking us to delete a KeyShare", server.GetConnString())
if len(msg.Data) != 1 { // keyID
resp.Error = message.InvalidMessageError
break
}
keyID := string(msg.Data[0])
log.Printf("Deleting keyshare for keyid=%s", keyID)
if err := server.DeleteKey(keyID); err != nil {
log.Printf("Error with key saving: %s", err)
resp.Error = message.InternalError
break
}
log.Printf("Keyshare deleted for keyid=%s", keyID)
default:
log.Printf("invalid message received from server %s", server.GetConnString())

Expand Down Expand Up @@ -125,3 +139,9 @@ func (server *Server) SaveKey(id string, keyShare *tcrsa.KeyShare, keyMeta *tcrs
key.Share = keyShare
return server.client.SaveConfigKeys()
}

// SaveKey deletes a key from the array of the server and asks the node to save the new key array into the config file.
func (server *Server) DeleteKey(id string) error {
delete(server.keys, id)
return server.client.SaveConfigKeys()
}

0 comments on commit 4825795

Please sign in to comment.