From 82bff9103960b7ea1a9062f03bec6c5346957d2e Mon Sep 17 00:00:00 2001 From: Benjamin Wenger <ben@elixxir.ioo> Date: Sun, 23 Jan 2022 10:45:29 -0800 Subject: [PATCH] hotfix/parallelizeSingleReception --- single/reception.go | 83 +++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/single/reception.go b/single/reception.go index e1aa8e08d..5bb65dde5 100644 --- a/single/reception.go +++ b/single/reception.go @@ -33,47 +33,48 @@ func (m *Manager) receiveTransmissionHandler(rawMessages chan message.Receive, case msg := <-rawMessages: jww.TRACE.Printf("Received CMIX message; checking if it is a " + "single-use transmission.") - - // Check if message is a single-use transmit message - cmixMsg, err := format.Unmarshal(msg.Payload) - if err != nil { - jww.ERROR.Printf("Could not unmarshal msg: %s", - err.Error()) - continue - } - if fp != cmixMsg.GetKeyFP() { - // If the verification fails, then ignore the message as it is - // likely garbled or for a different protocol - jww.TRACE.Print("Failed to read single-use CMIX message: " + - "fingerprint verification failed.") - continue - } - - // Denote that the message is not garbled - jww.DEBUG.Printf("Received single-use transmission message.") - m.store.GetGarbledMessages().Remove(cmixMsg) - - // Handle message - payload, c, err := m.processTransmission(cmixMsg, fp) - if err != nil { - jww.WARN.Printf("Failed to read single-use CMIX message: %+v", - err) - continue - } - jww.DEBUG.Printf("Successfully processed single-use transmission message.") - - // Lookup the registered callback for the message's tag fingerprint - callback, err := m.callbackMap.getCallback(c.tagFP) - if err != nil { - jww.WARN.Printf("Failed to find module to pass single-use "+ - "payload: %+v", err) - continue - } - - jww.DEBUG.Printf("Calling single-use callback with tag "+ - "fingerprint %s.", c.tagFP) - - go callback(payload, c) + go func(m *Manager, msg message.Receive) { + // Check if message is a single-use transmit message + cmixMsg, err := format.Unmarshal(msg.Payload) + if err != nil { + jww.ERROR.Printf("Could not unmarshal msg: %s", + err.Error()) + return + } + if fp != cmixMsg.GetKeyFP() { + // If the verification fails, then ignore the message as it is + // likely garbled or for a different protocol + jww.TRACE.Print("Failed to read single-use CMIX message: " + + "fingerprint verification failed.") + return + } + + // Denote that the message is not garbled + jww.DEBUG.Printf("Received single-use transmission message.") + m.store.GetGarbledMessages().Remove(cmixMsg) + + // Handle message + payload, c, err := m.processTransmission(cmixMsg, fp) + if err != nil { + jww.WARN.Printf("Failed to read single-use CMIX message: %+v", + err) + return + } + jww.DEBUG.Printf("Successfully processed single-use transmission message.") + + // Lookup the registered callback for the message's tag fingerprint + callback, err := m.callbackMap.getCallback(c.tagFP) + if err != nil { + jww.WARN.Printf("Failed to find module to pass single-use "+ + "payload: %+v", err) + return + } + + jww.DEBUG.Printf("Calling single-use callback with tag "+ + "fingerprint %s.", c.tagFP) + + callback(payload, c) + }(m, msg) } } } -- GitLab