Thread-safety techniques for secure .mnet remoting
I have overriden the client and the server channel sinks to encrypt messages on one side and decrypt the same on the other. I am using the lock statement inside the sinks to achieve thread-safety. However it seems that this technique makes the communication very slow. What are the other techniques that can be used to achieve thread safety?
Heres the sample from my application
private bool ProcessEncryptedMessage(IMessage message,ITransportHeaders requestHeaders,Stream requestStream,
out ITransportHeaders responseHeaders,out Stream responseStream)
// Encrypt the message. We track the id of the transaction so that we know
// whether the key has changed between encryption and decryption. If it has,
// we have a problem and need to try again.
id = EnsureServerAndID(message,requestHeaders);
requestStream = SetupEncryptedMessage(requestHeaders,requestStream );
//Send the encrypted request to the server
m_Next.ProcessMessage(message,requestHeaders,reque stStream,out responseHeaders,out responseStream);
// Decrypt the response stream. If decryption fails, and if no one has changed the
// transaction key (meaning someone else already had a problem and tried to fix
// it by clearing it out), then we need to clear it out such that it will be
// updated the next time through.
responseStream = DecryptResponse(responseStream, responseHeaders);
if (responseStream == null && id.Equals(m_TransactionID)) ClearSessionKey();
// Return whether we were successful
return responseStream != null;