当前位置: 首页>>代码示例>>C#>>正文


C# PeerId.Enqueue方法代码示例

本文整理汇总了C#中MonoTorrent.Client.PeerId.Enqueue方法的典型用法代码示例。如果您正苦于以下问题:C# PeerId.Enqueue方法的具体用法?C# PeerId.Enqueue怎么用?C# PeerId.Enqueue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MonoTorrent.Client.PeerId的用法示例。


在下文中一共展示了PeerId.Enqueue方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Unchoke

 public virtual void Unchoke(PeerId id)
 {
     id.AmChoking = false;
     id.TorrentManager.UploadingTo++;
     id.Enqueue(new UnchokeMessage());
     id.LastUnchoked = DateTime.Now;
 }
开发者ID:rajkosto,项目名称:DayZeroLauncher,代码行数:7,代码来源:Unchoker.cs

示例2: SetAmInterestedStatus

        protected virtual void SetAmInterestedStatus(PeerId id, bool interesting)
        {
            if (interesting && !id.AmInterested)
            {
                id.AmInterested = true;
                id.Enqueue(new InterestedMessage());

                // He's interesting, so attempt to queue up any FastPieces (if that's possible)
                manager.PieceManager.AddPieceRequests(id);
            }
            else if (!interesting && id.AmInterested)
            {
                id.AmInterested = false;
                id.Enqueue(new NotInterestedMessage());
            }
        }
开发者ID:Cyarix,项目名称:monotorrent,代码行数:16,代码来源:Mode.cs

示例3: Choke

 public virtual void Choke(PeerId id)
 {
     id.AmChoking = true;
     id.TorrentManager.UploadingTo--;
     id.Enqueue(new ChokeMessage());
 }
开发者ID:rajkosto,项目名称:DayZeroLauncher,代码行数:6,代码来源:Unchoker.cs

示例4: HandleRequestMessage

        protected virtual void HandleRequestMessage(PeerId id, RequestMessage message)
        {
            // If we are not on the last piece and the user requested a stupidly big/small amount of data
            // we will close the connection
            if (manager.Torrent.Pieces.Count != (message.PieceIndex + 1))
                if (message.RequestLength > RequestMessage.MaxSize || message.RequestLength < RequestMessage.MinSize)
                    throw new MessageException("Illegal piece request received. Peer requested " + message.RequestLength.ToString() + " byte");

            PieceMessage m = new PieceMessage(message.PieceIndex, message.StartOffset, message.RequestLength);

            // If we're not choking the peer, enqueue the message right away
            if (!id.AmChoking)
            {
                id.IsRequestingPiecesCount++;
                id.PieceReads.Add(m);
                id.TryProcessAsyncReads();
            }

            // If the peer supports fast peer and the requested piece is one of the allowed pieces, enqueue it
            // otherwise send back a reject request message
            else if (id.SupportsFastPeer && ClientEngine.SupportsFastPeer)
            {
                if (id.AmAllowedFastPieces.Contains(message.PieceIndex))
                {
                    id.IsRequestingPiecesCount++;
                    id.PieceReads.Add(m);
                    id.TryProcessAsyncReads();
                }
                else
                    id.Enqueue(new RejectRequestMessage(m));
            }
        }
开发者ID:Cyarix,项目名称:monotorrent,代码行数:32,代码来源:Mode.cs

示例5: HandlePeerConnected

        public virtual void HandlePeerConnected(PeerId id, Direction direction)
        {
            MessageBundle bundle = new MessageBundle();

            AppendBitfieldMessage(id, bundle);
            AppendExtendedHandshake(id, bundle);
            AppendFastPieces(id, bundle);

            id.Enqueue(bundle);
        }
开发者ID:Cyarix,项目名称:monotorrent,代码行数:10,代码来源:Mode.cs

示例6: HandleLtMetadataMessage

 protected virtual void HandleLtMetadataMessage(PeerId id, LTMetadata message)
 {
     if (message.MetadataMessageType == LTMetadata.eMessageType.Request)
     {
         if (id.TorrentManager.HasMetadata)
             id.Enqueue(new LTMetadata(id, LTMetadata.eMessageType.Data, message.Piece, id.TorrentManager.Torrent.Metadata));
         else
             id.Enqueue(new LTMetadata(id, LTMetadata.eMessageType.Reject, message.Piece));
     }
 }
开发者ID:Cyarix,项目名称:monotorrent,代码行数:10,代码来源:Mode.cs

示例7: HandleCancelMessage

        protected virtual void HandleCancelMessage(PeerId id, CancelMessage message)
        {
            PeerMessage msg;
            for (int i = 0; i < id.QueueLength; i++)
            {
                msg = id.Dequeue();
                if (!(msg is PieceMessage))
                {
                    id.Enqueue(msg);
                    continue;
                }

                PieceMessage piece = msg as PieceMessage;
                if (!(piece.PieceIndex == message.PieceIndex && piece.StartOffset == message.StartOffset && piece.RequestLength == message.RequestLength))
                {
                    id.Enqueue(msg);
                }
                else
                {
                    id.IsRequestingPiecesCount--;
                }
            }

            for (int i = 0; i < id.PieceReads.Count; i++)
            {
                if (id.PieceReads[i].PieceIndex == message.PieceIndex && id.PieceReads[i].StartOffset == message.StartOffset && id.PieceReads[i].RequestLength == message.RequestLength)
                {
                    id.IsRequestingPiecesCount--;
                    id.PieceReads.RemoveAt(i);
                    break;
                }
            }
        }
开发者ID:Cyarix,项目名称:monotorrent,代码行数:33,代码来源:Mode.cs

示例8: RequestNextNeededPiece

        private void RequestNextNeededPiece(PeerId id)
        {
            int index = bitField.FirstFalse();
            if (index == -1)
                return;//throw exception or switch to regular?

            LTMetadata m = new LTMetadata(id, LTMetadata.eMessageType.Request, index);
            id.Enqueue(m);
            requestTimeout = DateTime.Now.Add(timeout);
        }
开发者ID:silvermcd123,项目名称:WoWPrivateServerLauncher,代码行数:10,代码来源:MetadataMode.cs

示例9: RejectPendingRequests

        /// <summary>
        /// Checks the send queue of the peer to see if there are any outstanding pieces which they requested
        /// and rejects them as necessary
        /// </summary>
        /// <param name="Peer"></param>
        private void RejectPendingRequests(PeerId Peer)
        {
            PeerMessage message;
            PieceMessage pieceMessage;
            int length = Peer.QueueLength;

            for (int i = 0; i < length; i++)
            {
                message = Peer.Dequeue();
                if (!(message is PieceMessage))
                {
                    Peer.Enqueue(message);
                    continue;
                }

                pieceMessage = (PieceMessage)message;

                // If the peer doesn't support fast peer, then we will never requeue the message
                if (!(Peer.SupportsFastPeer && ClientEngine.SupportsFastPeer))
                {
                    Peer.IsRequestingPiecesCount--;
                    continue;
                }

                // If the peer supports fast peer, queue the message if it is an AllowedFast piece
                // Otherwise send a reject message for the piece
                if (Peer.AmAllowedFastPieces.Contains(pieceMessage.PieceIndex))
                    Peer.Enqueue(pieceMessage);
                else
                {
                    Peer.IsRequestingPiecesCount--;
                    Peer.Enqueue(new RejectRequestMessage(pieceMessage));
                }
            }
        }
开发者ID:burris,项目名称:monotorrent,代码行数:40,代码来源:ChokeUnchokeManager.cs

示例10: AddPieceRequests

        internal void AddPieceRequests(PeerId id)
        {
            PeerMessage msg = null;
            int maxRequests = id.MaxPendingRequests;

            if (id.AmRequestingPiecesCount >= maxRequests)
                return;

            int count = 1;
            if (id.Connection is HttpConnection)
            {
                // How many whole pieces fit into 2MB
                count = (2 * 1024 * 1024) / id.TorrentManager.Torrent.PieceLength;

                // Make sure we have at least one whole piece
                count = Math.Max(count, 1);
                
                count *= id.TorrentManager.Torrent.PieceLength / Piece.BlockSize;
            }

            if (!id.IsChoking || id.SupportsFastPeer)
            {
                while (id.AmRequestingPiecesCount < maxRequests)
                {
                    msg = Picker.ContinueExistingRequest(id);
                    if (msg != null)
                        id.Enqueue(msg);
                    else
                        break;
                } 
            }

            if (!id.IsChoking || (id.SupportsFastPeer && id.IsAllowedFastPieces.Count > 0))
            {
                while (id.AmRequestingPiecesCount < maxRequests)
                {
                    msg = Picker.PickPiece(id, id.TorrentManager.Peers.ConnectedPeers, count);
                    if (msg != null)
                        id.Enqueue(msg);
                    else
                        break;
                }
            }
        }
开发者ID:dontnod,项目名称:monotorrent,代码行数:44,代码来源:PieceManager.cs

示例11: PeerBitfieldSent

        private void PeerBitfieldSent(PeerId id)
        {
            if (id.Connection == null)
                return;

            // Free the old buffer and get a new one to recieve the length of the next message
            //ClientEngine.BufferManager.FreeBuffer(ref id.sendBuffer);

            // Now we will enqueue a FastPiece message for each piece we will allow the peer to download
            // even if they are choked
            if (ClientEngine.SupportsFastPeer && id.SupportsFastPeer)
                for (int i = 0; i < id.AmAllowedFastPieces.Count; i++)
                    id.Enqueue(new AllowedFastMessage(id.AmAllowedFastPieces[i]));

            // Allow the auto processing of the send queue to commence
            if (id.QueueLength > 0)
                id.ConnectionManager.ProcessQueue(id);
            else
                id.ProcessingQueue = false;

            // Begin the infinite looping to receive messages
            ClientEngine.BufferManager.FreeBuffer(ref id.recieveBuffer);
            NetworkIO.ReceiveMessage(id);
        }
开发者ID:burris,项目名称:monotorrent,代码行数:24,代码来源:ConnectionManager.cs

示例12: AddPieceRequest

        internal bool AddPieceRequest(PeerId id)
        {
            PeerMessage msg;

            // If someone can upload to us fast, queue more pieces off them. But no more than 100 blocks.
            int maxRequests = PieceManager.NormalRequestAmount + (int)(id.Monitor.DownloadSpeed / 1024.0 / BonusRequestPerKb);
            maxRequests = maxRequests > 50 ? 50 : maxRequests;

            if (id.AmRequestingPiecesCount >= maxRequests)
                return false;

            //if (this.InEndGameMode)// In endgame we only want to queue 2 pieces
            //    if (id.AmRequestingPiecesCount > PieceManager.MaxEndGameRequests)
            //        return false;

            int count = 1;
            if (id.Connection is HttpConnection)
            {
                // How many whole pieces fit into 2MB
                count = (2 * 1024 * 1024) / id.TorrentManager.Torrent.PieceLength;

                // Make sure we have at least one whole piece
                count = Math.Max(count, 1);

                count *= id.TorrentManager.Torrent.PieceLength / Piece.BlockSize;
            }

            msg = Picker.PickPiece(id, id.TorrentManager.Peers.ConnectedPeers, count);
            if (msg != null)
                id.Enqueue(msg);

            return msg != null;
        }
开发者ID:burris,项目名称:monotorrent,代码行数:33,代码来源:PieceManager.cs


注:本文中的MonoTorrent.Client.PeerId.Enqueue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。