/// <summary>
 /// Creates a new PeerMessageEventArgs
 /// </summary>
 /// <param name="manager">The manager.</param>
 /// <param name="message">The peer message involved</param>
 /// <param name="direction">The direction of the message</param>
 /// <param name="id">The identifier.</param>
 internal PeerMessageEventArgs(TorrentManager manager, PeerMessage message, Direction direction, PeerId id)
     : base(manager)
 {
     Direction = direction;
     ID = id;
     Message = message;
 }
Пример #2
0
        public static void EnqueueSendMessage(IConnection connection, IEncryption encryptor, PeerMessage message,
            IRateLimiter rateLimiter, ConnectionMonitor peerMonitor, ConnectionMonitor managerMonitor,
            AsyncIOCallback callback, object state)
        {
            var count = message.ByteLength;
            var buffer = ClientEngine.BufferManager.GetBuffer(count);
            message.Encode(buffer, 0);
            encryptor.Encrypt(buffer, 0, count);

            var data = SendCache.Dequeue().Initialise(buffer, callback, state);
            NetworkIO.EnqueueSend(connection, buffer, 0, count, rateLimiter, peerMonitor, managerMonitor,
                EndSendCallback, data);
        }
Пример #3
0
        public void SendMessage(PeerMessage message)
        {
            if (message == null)
                throw new ArgumentNullException(nameof(message));

            ClientEngine.MainLoop.QueueWait(delegate
            {
                if (Connection == null)
                    return;

                Enqueue(message);
            });
        }
Пример #4
0
 internal void EnqueueAt(PeerMessage message, int index)
 {
     if (_sendQueue.Count == 0 || index >= _sendQueue.Count)
         Enqueue(message);
     else
         _sendQueue.Insert(index, message);
 }
Пример #5
0
 internal void Enqueue(PeerMessage msg)
 {
     _sendQueue.Add(msg);
     if (!ProcessingQueue)
     {
         ProcessingQueue = true;
         ConnectionManager.ProcessQueue(this);
     }
 }
Пример #6
0
 public MessageBundle(PeerMessage message)
     : this()
 {
     Messages.Add(message);
 }
Пример #7
0
        /// <summary>
        ///     Called when [peer handshake received].
        /// </summary>
        /// <param name="succeeded">if set to <c>true</c> [succeeded].</param>
        /// <param name="message">The message.</param>
        /// <param name="state">The state.</param>
        private void OnPeerHandshakeReceived(bool succeeded, PeerMessage message, object state)
        {
            var id = (PeerId) state;

            try
            {
                if (succeeded)
                    HandleHandshake(id, (HandshakeMessage) message);
                else
                    id.Connection.Dispose();
            }
            catch (Exception)
            {
                Debug.WriteLine(id.Connection, "ListenManager - Socket exception receiving handshake");
                id.Connection.Dispose();
            }
        }