private void PeerHandshakeReceived(bool succeeded, PeerMessage message, object state)
{
PeerId id = (PeerId)state;
if (!succeeded)
{
CleanupSocket(id, "Handshaking failed");
return;
}
try
{
message.Handle(id);
// If there are any pending messages, send them otherwise set the queue
// processing as finished.
if (id.QueueLength > 0)
id.ConnectionManager.ProcessQueue(id);
else
id.ProcessingQueue = false;
PeerIO.EnqueueReceiveMessage (id.Connection, id.Decryptor, id.TorrentManager.DownloadLimiter, id.Monitor, id.TorrentManager, messageReceivedCallback, id);
// Alert the engine that there is a new usable connection
id.TorrentManager.HandlePeerConnected(id, Direction.Outgoing);
}
catch (TorrentException ex)
{
CleanupSocket(id, ex.Message);
}
}