本文整理汇总了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;
}
示例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());
}
}
示例3: Choke
public virtual void Choke(PeerId id)
{
id.AmChoking = true;
id.TorrentManager.UploadingTo--;
id.Enqueue(new ChokeMessage());
}
示例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));
}
}
示例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);
}
示例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));
}
}
示例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;
}
}
}
示例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);
}
示例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));
}
}
}
示例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;
}
}
}
示例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);
}
示例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;
}