private void EndCheckEncryption(IAsyncResult result) { var id = (PeerId)result.AsyncState; try { byte[] initialData; EncryptorFactory.EndCheckEncryption(result, out initialData); if (initialData != null && initialData.Length > 0) { throw new EncryptionException("unhandled initial data"); } var 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 var handshake = new HandshakeMessage(id.TorrentManager.InfoHash, _engine.PeerId, VersionInfo.ProtocolStringV100); SendMessage(id, handshake, _handshakeSentCallback); } } catch { id.Peer.Encryption &= ~EncryptionTypes.RC4Full; id.Peer.Encryption &= ~EncryptionTypes.RC4Header; CleanupSocket(id, "Failed encryptor check"); } }
private void EndCheckEncryption(IAsyncResult result) { PeerId id = (PeerId)result.AsyncState; try { byte[] initialData; EncryptorFactory.EndCheckEncryption(result, out initialData); if (initialData != null && initialData.Length == HandshakeMessage.HandshakeLength) { HandshakeMessage message = new HandshakeMessage(); message.Decode(initialData, 0, initialData.Length); handleHandshake(id, message); } else if (initialData.Length > 0) { throw new Exception("Argh. I can't handle this scenario. It also shouldn't happen. Ever."); } else { PeerIO.EnqueueReceiveHandshake(id.Connection, id.Decryptor, handshakeReceivedCallback, id); } } catch { id.Connection.Dispose(); } }
public void InitiateTransfer(CustomConnection connection) { PeerId id = new PeerId(new Peer("", connection.Uri), rig.Manager); id.Connection = connection; byte[] data; EncryptorFactory.EndCheckEncryption(EncryptorFactory.BeginCheckEncryption(id, 68, null, null, new InfoHash[] { id.TorrentManager.InfoHash }), out data); decryptor = id.Decryptor; encryptor = id.Encryptor; TestHandshake(data, connection); }
public void Setup(bool metadataMode, string metadataPath) { pair = new ConnectionPair(55432); rig = TestRig.CreateSingleFile(1024 * 1024 * 1024, 32768, metadataMode); rig.MetadataPath = metadataPath; rig.RecreateManager(); rig.Manager.HashChecked = true; rig.Manager.Start(); rig.AddConnection(pair.Outgoing); var connection = pair.Incoming; PeerId id = new PeerId(new Peer("", connection.Uri), rig.Manager); id.Connection = connection; byte[] data; EncryptorFactory.EndCheckEncryption(EncryptorFactory.BeginCheckEncryption(id, 68, null, null, new InfoHash[] { id.TorrentManager.InfoHash }), out data); decryptor = id.Decryptor; encryptor = id.Encryptor; }