diff --git a/single/reception.go b/single/reception.go index e1aa8e08d3341e6bf3bdb4d5354d6e4cf90dfda6..5bb65dde52e3589fdde7acbcb5d4d85fef5a640e 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) } } }