internal ListenManager(ClientEngine engine) { Engine = engine; listeners = new MonoTorrentCollection<PeerListener>(); endCheckEncryptionCallback = ClientEngine.MainLoop.Wrap(EndCheckEncryption); handshakeReceivedCallback = (a, b, c) => ClientEngine.MainLoop.Queue(() => onPeerHandshakeReceived(a, b, c)); }
internal ListenManager(ClientEngine engine) { Engine = engine; listeners = new MonoTorrentCollection <PeerListener>(); endCheckEncryptionCallback = ClientEngine.MainLoop.Wrap(EndCheckEncryption); handshakeReceivedCallback = (a, b, c) => ClientEngine.MainLoop.Queue(() => onPeerHandshakeReceived(a, b, c)); }
public static void EnqueueReceiveMessage(IConnection connection, IEncryption decryptor, IRateLimiter rateLimiter, ConnectionMonitor monitor, TorrentManager manager, AsyncMessageReceivedCallback callback, object state) { // FIXME: Hardcoded number int count = 4; var buffer = ClientEngine.BufferManager.GetBuffer (count); var data = receiveCache.Dequeue ().Initialise (connection, decryptor, rateLimiter, monitor, manager, buffer, callback, state); NetworkIO.EnqueueReceive (connection, buffer, 0, count, rateLimiter, monitor, data.ManagerMonitor, MessageLengthReceivedCallback, data); }
public static void EnqueueReceiveHandshake(IConnection connection, IEncryption decryptor, AsyncMessageReceivedCallback callback, object state) { var buffer = ClientEngine.BufferManager.GetBuffer(HandshakeMessage.HandshakeLength); var data = ReceiveCache.Dequeue() .Initialise(connection, decryptor, null, null, null, buffer, callback, state); NetworkIO.EnqueueReceive(connection, buffer, 0, HandshakeMessage.HandshakeLength, null, null, null, HandshakeReceivedCallback, data); }
public ReceiveMessageState Initialise(IConnection connection, IEncryption decryptor, IRateLimiter limiter, ConnectionMonitor peerMonitor, TorrentManager manager, byte[] buffer, AsyncMessageReceivedCallback callback, object state) { Connection = connection; Decryptor = decryptor; Manager = manager; Buffer = buffer; PeerMonitor = peerMonitor; RateLimiter = limiter; ManagerMonitor = manager == null ? null : manager.Monitor; Callback = callback; State = state; return(this); }
public static void EnqueueReceiveMessage(IConnection connection, IEncryption decryptor, IRateLimiter rateLimiter, ConnectionMonitor peerMonitor, TorrentManager manager, AsyncMessageReceivedCallback callback, object state) { // FIXME: Hardcoded number const int count = 4; var buffer = ClientEngine.BufferManager.GetBuffer(count); var data = receiveCache.Dequeue().Initialise(connection, decryptor, rateLimiter, peerMonitor, manager, buffer, callback, state); NetworkIO.EnqueueReceive(connection, buffer, 0, count, rateLimiter, peerMonitor, data.ManagerMonitor, MessageLengthReceivedCallback, data); }
public ReceiveMessageState Initialise (IConnection connection, IEncryption decryptor, IRateLimiter limiter, ConnectionMonitor peerMonitor, TorrentManager manager, byte[] buffer, AsyncMessageReceivedCallback callback, object state) { Connection = connection; Decryptor = decryptor; Manager = manager; Buffer = buffer; PeerMonitor = peerMonitor; RateLimiter = limiter; ManagerMonitor = manager == null ? null : manager.Monitor; Callback = callback; State = state; return this; }
/// <summary> /// /// </summary> /// <param name="settings"></param> public ConnectionManager(ClientEngine engine) { this.engine = engine; this.endCheckEncryptionCallback = ClientEngine.MainLoop.Wrap(EndCheckEncryption); this.endSendMessageCallback = (a, b, c) => ClientEngine.MainLoop.Queue(() => EndSendMessage(a, b, c)); this.endCreateConnectionCallback = (a, b, c) => ClientEngine.MainLoop.Queue(() => EndCreateConnection(a, b, c)); this.incomingConnectionAcceptedCallback = (a, b, c) => ClientEngine.MainLoop.Queue(() => IncomingConnectionAccepted(a, b, c)); this.handshakeSentCallback = PeerHandshakeSent; this.peerHandshakeReceivedCallback = (a, b, c) => ClientEngine.MainLoop.Queue(() => PeerHandshakeReceived(a, b, c)); this.messageSentCallback = PeerMessageSent; this.messageReceivedCallback = (a, b, c) => ClientEngine.MainLoop.Queue(() => MessageReceived(a, b, c)); this.pendingConnects = new List <AsyncConnectState>(); }
public ConnectionManager(ClientEngine engine) { _engine = engine; _endCheckEncryptionCallback = ClientEngine.MainLoop.Wrap(EndCheckEncryption); _endSendMessageCallback = (a, b, c) => ClientEngine.MainLoop.Queue(() => EndSendMessage(a, b, c)); _endCreateConnectionCallback = (a, b, c) => ClientEngine.MainLoop.Queue(() => EndCreateConnection(a, b, c)); IncomingConnectionAcceptedCallback = (a, b, c) => ClientEngine.MainLoop.Queue(() => IncomingConnectionAccepted(a, b, c)); _handshakeSentCallback = PeerHandshakeSent; _peerHandshakeReceivedCallback = (a, b, c) => ClientEngine.MainLoop.Queue(() => PeerHandshakeReceived(a, b, c)); _messageSentCallback = PeerMessageSent; MessageReceivedCallback = (a, b, c) => ClientEngine.MainLoop.Queue(() => MessageReceived(a, b, c)); _pendingConnects = new List<AsyncConnectState>(); }
public void ReceiveTwoKeepAlives() { var message = new KeepAliveMessage(); var buffer = message.Encode(); var handle = new AutoResetEvent(false); NetworkIO.EnqueueSend(Outgoing, buffer, 0, buffer.Length, null, null, null, delegate { }, null); NetworkIO.EnqueueSend(Outgoing, buffer, 0, buffer.Length, null, null, null, delegate { }, null); AsyncMessageReceivedCallback callback = (s, m, state) => { if (s && m is KeepAliveMessage) { handle.Set(); } }; PeerIO.EnqueueReceiveMessage(Incoming, new PlainTextEncryption(), null, null, null, callback, null); Assert.IsTrue(handle.WaitOne(TimeSpan.FromSeconds(2)), "#Should receive first message"); PeerIO.EnqueueReceiveMessage(Incoming, new PlainTextEncryption(), null, null, null, callback, null); Assert.IsTrue(handle.WaitOne(TimeSpan.FromSeconds(2)), "#Should receive second message"); }