Commit 9b5f8923 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

refactor: prevent useless repeated map lookups

parent 8e71e1a3
...@@ -221,16 +221,18 @@ func (s *Server) generateCommitments(user *KeyshareUser, authorization string, k ...@@ -221,16 +221,18 @@ func (s *Server) generateCommitments(user *KeyshareUser, authorization string, k
// Store needed data for later requests. // Store needed data for later requests.
username := user.Username username := user.Username
s.sessionLock.Lock() s.sessionLock.Lock()
if _, ok := s.sessions[username]; !ok { session, ok := s.sessions[username]
s.sessions[username] = &SessionData{} if !ok {
session = &SessionData{}
s.sessions[username] = session
} }
// Of all keys involved in the current session, store the ID of the first one to be used when // Of all keys involved in the current session, store the ID of the first one to be used when
// the user comes back later to retrieve her response. gabi.ProofP.P will depend on this public // the user comes back later to retrieve her response. gabi.ProofP.P will depend on this public
// key, which is used only during issuance. Thus, this assumes that during issuance, the user // key, which is used only during issuance. Thus, this assumes that during issuance, the user
// puts the key ID of the credential(s) being issued at index 0. // puts the key ID of the credential(s) being issued at index 0.
s.sessions[username].LastKeyID = keys[0] session.LastKeyID = keys[0]
s.sessions[username].LastCommitID = commitID session.LastCommitID = commitID
s.sessions[username].expiry = time.Now().Add(10 * time.Second) session.expiry = time.Now().Add(10 * time.Second)
s.sessionLock.Unlock() s.sessionLock.Unlock()
// And send response // And send response
...@@ -241,7 +243,6 @@ func (s *Server) generateCommitments(user *KeyshareUser, authorization string, k ...@@ -241,7 +243,6 @@ func (s *Server) generateCommitments(user *KeyshareUser, authorization string, k
func (s *Server) handleResponse(w http.ResponseWriter, r *http.Request) { func (s *Server) handleResponse(w http.ResponseWriter, r *http.Request) {
// Fetch from context // Fetch from context
user := r.Context().Value("user").(*KeyshareUser) user := r.Context().Value("user").(*KeyshareUser)
username := user.Username
authorization := r.Context().Value("authorization").(string) authorization := r.Context().Value("authorization").(string)
// Read challenge // Read challenge
...@@ -268,7 +269,7 @@ func (s *Server) handleResponse(w http.ResponseWriter, r *http.Request) { ...@@ -268,7 +269,7 @@ func (s *Server) handleResponse(w http.ResponseWriter, r *http.Request) {
// Get data from session // Get data from session
s.sessionLock.Lock() s.sessionLock.Lock()
sessionData, ok := s.sessions[username] sessionData, ok := s.sessions[user.Username]
s.sessionLock.Unlock() s.sessionLock.Unlock()
if !ok { if !ok {
s.conf.Logger.Warn("Request for response without previous call to get commitments") s.conf.Logger.Warn("Request for response without previous call to get commitments")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment