diff --git a/auth/callback.go b/auth/callback.go index ab5d8902eec326ed084e98b7a6c1fef8ba39e46b..362efcaade20a3ed5e00d0b44c6847855c6471fa 100644 --- a/auth/callback.go +++ b/auth/callback.go @@ -12,6 +12,7 @@ import ( jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces/contact" + "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage/auth" "gitlab.com/elixxir/crypto/cyclic" @@ -25,48 +26,55 @@ import ( func (m *Manager) StartProcessies() stoppable.Stoppable { stop := stoppable.NewSingle("Auth") - authStore := m.storage.Auth() - grp := m.storage.E2e().GetGroup() go func() { - select { - case <-stop.Quit(): - return - case msg := <-m.rawMessages: - //lookup the message, check if it is an auth request - cmixMsg := format.Unmarshal(msg.Payload) - fp := cmixMsg.GetKeyFP() - jww.INFO.Printf("RAW AUTH FP: %v", fp) - // this takes the request lock if it is a specific fp, - // all exits after this need to call fail or delete if it is - // specific - fpType, sr, myHistoricalPrivKey, err := authStore.GetFingerprint(fp) - if err != nil { - jww.TRACE.Printf("FINGERPRINT FAILURE: %s", err.Error()) - // if the lookup fails, ignore the message. It is likely - // garbled or for a different protocol - break - } - - //denote that the message is not garbled - m.storage.GetGarbledMessages().Remove(cmixMsg) - - switch fpType { - // if it is general, that means a new request has been received - case auth.General: - m.handleRequest(cmixMsg, myHistoricalPrivKey, grp) - // if it is specific, that means the original request was sent - // by this users and a confirmation has been received - case auth.Specific: - jww.INFO.Printf("Received AutConfirm from %s,"+ - " msgDigest: %s", sr.GetPartner(), cmixMsg.Digest()) - m.handleConfirm(cmixMsg, sr, grp) + for { + select { + case <-stop.Quit(): + return + case msg := <-m.rawMessages: + m.processAuthMessage(msg) } } }() return stop } +func (m *Manager) processAuthMessage(msg message.Receive) { + authStore := m.storage.Auth() + //lookup the message, check if it is an auth request + cmixMsg := format.Unmarshal(msg.Payload) + fp := cmixMsg.GetKeyFP() + jww.INFO.Printf("RAW AUTH FP: %v", fp) + // this takes the request lock if it is a specific fp, all + // exits after this need to call fail or delete if it is + // specific + fpType, sr, myHistoricalPrivKey, err := authStore.GetFingerprint(fp) + if err != nil { + jww.TRACE.Printf("FINGERPRINT FAILURE: %s", err.Error()) + // if the lookup fails, ignore the message. It is + // likely garbled or for a different protocol + return + } + + //denote that the message is not garbled + m.storage.GetGarbledMessages().Remove(cmixMsg) + grp := m.storage.E2e().GetGroup() + + switch fpType { + case auth.General: + // if it is general, that means a new request has + // been received + m.handleRequest(cmixMsg, myHistoricalPrivKey, grp) + case auth.Specific: + // if it is specific, that means the original request was sent + // by this users and a confirmation has been received + jww.INFO.Printf("Received AutConfirm from %s, msgDigest: %s", + sr.GetPartner(), cmixMsg.Digest()) + m.handleConfirm(cmixMsg, sr, grp) + } +} + func (m *Manager) handleRequest(cmixMsg format.Message, myHistoricalPrivKey *cyclic.Int, grp *cyclic.Group) { //decode the outer format