private void EndCheckEncryption(IAsyncResult result)
{
PeerId id = (PeerId)result.AsyncState;
byte[] initialData;
try
{
EncryptorFactory.EndCheckEncryption(result, out initialData);
if (initialData != null && initialData.Length > 0)
throw new EncryptionException("unhandled initial data");
EncryptionTypes e = engine.Settings.AllowedEncryption;
if (id.Encryptor is RC4 && !Toolbox.HasEncryption(e, EncryptionTypes.RC4Full) ||
id.Encryptor is RC4Header && !Toolbox.HasEncryption(e, EncryptionTypes.RC4Header) ||
id.Encryptor is PlainTextEncryption && !Toolbox.HasEncryption(e, EncryptionTypes.PlainText))
{
CleanupSocket(id, id.Encryptor.GetType().Name + " encryption is not enabled");
}
else
{
// Create a handshake message to send to the peer
HandshakeMessage handshake = new HandshakeMessage(id.TorrentManager.InfoHash, engine.PeerId, VersionInfo.ProtocolStringV100);
SendMessage(id, handshake, this.handshakeSentCallback);
}
}
catch
{
id.Peer.Encryption &= ~EncryptionTypes.RC4Full;
id.Peer.Encryption &= ~EncryptionTypes.RC4Header;
CleanupSocket(id, "Failed encryptor check");
}
}