本文整理汇总了C#中MonoTorrent.Client.PeerId类的典型用法代码示例。如果您正苦于以下问题:C# PeerId类的具体用法?C# PeerId怎么用?C# PeerId使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PeerId类属于MonoTorrent.Client命名空间,在下文中一共展示了PeerId类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EndGamePickerTests
public EndGamePickerTests()
{
rig = TestRig.CreateMultiFile();
bitfield = new BitField(40).SetAll(true)
.Set(4, false)
.Set(6, false)
.Set(24, false)
.Set(36, false);
picker = new EndGamePicker();
pieces = new List<Piece>(new[]
{
new Piece(4, rig.Torrent.PieceLength, rig.Torrent.Size),
new Piece(6, rig.Torrent.PieceLength, rig.Torrent.Size),
new Piece(24, rig.Torrent.PieceLength, rig.Torrent.Size),
new Piece(36, rig.Torrent.PieceLength, rig.Torrent.Size)
});
id = new PeerId(new Peer("peerid", new Uri("tcp://weburl.com")), rig.Manager);
id.IsChoking = false;
id.BitField.SetAll(false);
other = new PeerId(new Peer("other", new Uri("tcp://other.com")), rig.Manager);
other.IsChoking = false;
other.BitField.SetAll(false);
}
示例2: EncryptorAsyncResult
public EncryptorAsyncResult(PeerId id, AsyncCallback callback, object state)
: base(callback, state)
{
Id = id;
Decryptor = new PlainTextEncryption();
Encryptor = new PlainTextEncryption();
}
示例3: Unchoke
public virtual void Unchoke(PeerId id)
{
id.AmChoking = false;
id.TorrentManager.UploadingTo++;
id.Enqueue(new UnchokeMessage());
id.LastUnchoked = DateTime.Now;
}
示例4: PeerMessageEventArgs
/// <summary>
/// Creates a new PeerMessageEventArgs
/// </summary>
/// <param name="message">The peer message involved</param>
/// <param name="direction">The direction of the message</param>
internal PeerMessageEventArgs(TorrentManager manager, PeerMessage message, Direction direction, PeerId id)
: base(manager)
{
this.direction = direction;
this.id = id;
this.message = message;
}
示例5: PeerConnectionEventArgs
internal PeerConnectionEventArgs(TorrentManager manager, PeerId id, Direction direction, String message)
: base(manager)
{
peerConnectionId = id;
connectionDirection = direction;
this.message = message;
}
示例6: AppendBitfieldMessage
protected override void AppendBitfieldMessage(PeerId id, MessageBundle bundle)
{
if (id.SupportsFastPeer)
bundle.Messages.Add(new HaveNoneMessage());
else
bundle.Messages.Add(new BitfieldMessage(zero));
}
示例7: PickPiece
public override MessageBundle PickPiece(PeerId id, BitField peerBitfield, List<PeerId> otherPeers, int count,
int startIndex, int endIndex)
{
// Only request 2 pieces at a time in endgame mode
// to prevent a *massive* overshoot
if (id.IsChoking || id.AmRequestingPiecesCount > 2)
return null;
LoadPieces(id, peerBitfield);
// 1) See if there are any blocks which have not been requested at all. Request the block if the peer has it
foreach (var p in pieces)
{
if (!peerBitfield[p.Index] || p.AllBlocksRequested)
continue;
for (var i = 0; i < p.BlockCount; i++)
{
if (p.Blocks[i].Requested)
continue;
p.Blocks[i].Requested = true;
var request = new Request(id, p.Blocks[i]);
requests.Add(request);
return new MessageBundle(request.Block.CreateRequest(id));
}
}
// 2) For each block with an existing request, add another request. We do a search from the start
// of the list to the end. So when we add a duplicate request, move both requests to the end of the list
foreach (var p in pieces)
{
if (!peerBitfield[p.Index])
continue;
for (var i = 0; i < p.BlockCount; i++)
{
if (p.Blocks[i].Received || AlreadyRequested(p.Blocks[i], id))
continue;
var c = requests.Count;
for (var j = 0; j < requests.Count - 1 && (c-- > 0); j++)
{
if (requests[j].Block.PieceIndex == p.Index &&
requests[j].Block.StartOffset == p.Blocks[i].StartOffset)
{
var r = requests[j];
requests.RemoveAt(j);
requests.Add(r);
j--;
}
}
p.Blocks[i].Requested = true;
var request = new Request(id, p.Blocks[i]);
requests.Add(request);
return new MessageBundle(request.Block.CreateRequest(id));
}
}
return null;
}
示例8: SeededPiece
public SeededPiece(PeerId peer, int index, int totalBlocks)
{
Index = index;
Peer = peer;
SeededAt = DateTime.Now;
TotalBlocks = totalBlocks;
}
示例9: Setup
public void Setup()
{
requestedUrl.Clear();
partialData = false;
int i;
for (i = 0; i < 1000; i++)
{
try
{
listener = new HttpListener();
listener.Prefixes.Add(string.Format(listenerURL, i));
listener.Start();
break;
}
catch
{
}
}
listener.BeginGetContext(GotContext, null);
rig = TestRig.CreateMultiFile();
connection = new HttpConnection(new Uri(string.Format(listenerURL, i)));
connection.Manager = rig.Manager;
id = new PeerId(new Peer("this is my id", connection.Uri), rig.Manager);
id.Connection = connection;
id.IsChoking = false;
id.AmInterested = true;
id.BitField.SetAll(true);
id.MaxPendingRequests = numberOfPieces;
requests = rig.Manager.PieceManager.Picker.PickPiece(id, new List<PeerId>(), numberOfPieces);
}
示例10: FixtureSetup
public void FixtureSetup()
{
rig = TestRig.CreateMultiFile();
id = new PeerId(new Peer(new string('a', 20), new Uri("tcp://BLAH")), rig.Manager);
for (int i = 0; i < id.BitField.Length; i += 2)
id.BitField[i] = true;
}
示例11: ConnectionReceived
private void ConnectionReceived(object sender, NewConnectionEventArgs e)
{
if (Engine.ConnectionManager.ShouldBanPeer(e.Peer))
{
e.Connection.Dispose();
return;
}
var id = new PeerId(e.Peer, e.TorrentManager);
id.Connection = e.Connection;
Logger.Log(id.Connection, "ListenManager - ConnectionReceived");
if (id.Connection.IsIncoming)
{
var skeys = new List<InfoHash>();
ClientEngine.MainLoop.QueueWait(delegate
{
for (var i = 0; i < Engine.Torrents.Count; i++)
skeys.Add(Engine.Torrents[i].InfoHash);
});
EncryptorFactory.BeginCheckEncryption(id, HandshakeMessage.HandshakeLength, endCheckEncryptionCallback,
id, skeys.ToArray());
}
else
{
ClientEngine.MainLoop.Queue(delegate { Engine.ConnectionManager.ProcessFreshConnection(id); });
}
}
示例12: PeerConnectionEventArgs
internal PeerConnectionEventArgs(TorrentManager manager, PeerId id, Direction direction, string message)
: base(manager)
{
PeerID = id;
ConnectionDirection = direction;
Message = message;
}
示例13: PeerMessageEventArgs
/// <summary>
/// Creates a new PeerMessageEventArgs
/// </summary>
/// <param name="message">The peer message involved</param>
/// <param name="direction">The direction of the message</param>
internal PeerMessageEventArgs(TorrentManager manager, PeerMessage message, Direction direction, PeerId id)
: base(manager)
{
Direction = direction;
ID = id;
Message = message;
}
示例14: PeerExchangePeersAdded
public PeerExchangePeersAdded(TorrentManager manager, int count, int total, PeerId id)
:base(manager, count, total)
{
if (id == null)
throw new ArgumentNullException("id");
this.id = id;
}
示例15: PickPiece
public override MessageBundle PickPiece(PeerId id, BitField peerBitfield, List<PeerId> otherPeers, int count,
int startIndex, int endIndex)
{
var bundle = ActivePicker.PickPiece(id, peerBitfield, otherPeers, count, startIndex, endIndex);
if (bundle == null && TryEnableEndgame())
return ActivePicker.PickPiece(id, peerBitfield, otherPeers, count, startIndex, endIndex);
return bundle;
}