本文整理汇总了C#中MonoTorrent.Client.PeerId类的典型用法代码示例。如果您正苦于以下问题:C# PeerId类的具体用法?C# PeerId怎么用?C# PeerId使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PeerId类属于MonoTorrent.Client命名空间,在下文中一共展示了PeerId类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:26,代码来源:EndGamePickerTests.cs
示例2: EncryptorAsyncResult
public EncryptorAsyncResult(PeerId id, AsyncCallback callback, object state)
: base(callback, state)
{
Id = id;
Decryptor = new PlainTextEncryption();
Encryptor = new PlainTextEncryption();
}
开发者ID:SamirHafez,项目名称:MonoTorrent.PCL,代码行数:7,代码来源:EncryptorFactory.cs
示例3: 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
示例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;
}
开发者ID:rajkosto,项目名称:DayZeroLauncher,代码行数:12,代码来源:MessageEventArgs.cs
示例5: PeerConnectionEventArgs
internal PeerConnectionEventArgs(TorrentManager manager, PeerId id, Direction direction, String message)
: base(manager)
{
peerConnectionId = id;
connectionDirection = direction;
this.message = message;
}
开发者ID:rajkosto,项目名称:DayZeroLauncher,代码行数:7,代码来源:PeerConnectionEventArgs.cs
示例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));
}
开发者ID:Cyarix,项目名称:monotorrent,代码行数:7,代码来源:InitialSeedingMode.cs
示例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;
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:60,代码来源:EndGamePicker.cs
示例8: SeededPiece
public SeededPiece(PeerId peer, int index, int totalBlocks)
{
Index = index;
Peer = peer;
SeededAt = DateTime.Now;
TotalBlocks = totalBlocks;
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:7,代码来源:InitialSeedUnchoker.cs
示例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);
}
开发者ID:Cyarix,项目名称:monotorrent,代码行数:33,代码来源:TestWebSeed.cs
示例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;
}
开发者ID:Cyarix,项目名称:monotorrent,代码行数:7,代码来源:RandomisedPickerTests.cs
示例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); });
}
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:30,代码来源:ListenManager.cs
示例12: PeerConnectionEventArgs
internal PeerConnectionEventArgs(TorrentManager manager, PeerId id, Direction direction, string message)
: base(manager)
{
PeerID = id;
ConnectionDirection = direction;
Message = message;
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:7,代码来源:PeerConnectionEventArgs.cs
示例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;
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:12,代码来源:MessageEventArgs.cs
示例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;
}
开发者ID:Cyarix,项目名称:monotorrent,代码行数:8,代码来源:PeerExchangePeersAdded.cs
示例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;
}
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:8,代码来源:EndGameSwitcher.cs
示例16: BeginCheckEncryption
internal static IAsyncResult BeginCheckEncryption(PeerId id, int bytesToReceive, AsyncCallback callback, object state, InfoHash[] sKeys)
{
EncryptorAsyncResult result = new EncryptorAsyncResult(id, callback, state);
result.SKeys = sKeys;
IConnection c = id.Connection;
ClientEngine.MainLoop.QueueTimeout(TimeSpan.FromSeconds(10), delegate {
if (id.Encryptor == null || id.Decryptor == null)
id.CloseConnection();
return false;
});
try
{
// If the connection is incoming, receive the handshake before
// trying to decide what encryption to use
if (id.Connection.IsIncoming)
{
result.Buffer = new byte[bytesToReceive];
NetworkIO.EnqueueReceive(c, result.Buffer, 0, result.Buffer.Length, null, null, null, HandshakeReceivedCallback, result);
}
else
{
EncryptionTypes usable = CheckRC4(id);
bool hasPlainText = Toolbox.HasEncryption(usable, EncryptionTypes.PlainText);
bool hasRC4 = Toolbox.HasEncryption(usable, EncryptionTypes.RC4Full) || Toolbox.HasEncryption(usable, EncryptionTypes.RC4Header);
if (id.Engine.Settings.PreferEncryption)
{
if (hasRC4)
{
result.EncSocket = new PeerAEncryption(id.TorrentManager.InfoHash, usable);
result.EncSocket.BeginHandshake(id.Connection, CompletedEncryptedHandshakeCallback, result);
}
else
{
result.Complete();
}
}
else
{
if (hasPlainText)
{
result.Complete();
}
else
{
result.EncSocket = new PeerAEncryption(id.TorrentManager.InfoHash, usable);
result.EncSocket.BeginHandshake(id.Connection, CompletedEncryptedHandshakeCallback, result);
}
}
}
}
catch (Exception ex)
{
result.Complete(ex);
}
return result;
}
开发者ID:ArsenShnurkov,项目名称:MonoTorrent,代码行数:58,代码来源:EncryptorFactory.cs
示例17: PeerExchangeManager
internal PeerExchangeManager(PeerId id)
{
this.id = id;
this.addedPeers = new List<Peer>();
this.droppedPeers = new List<Peer>();
id.TorrentManager.OnPeerFound += new EventHandler<PeerAddedEventArgs>(OnAdd);
Start();
}
开发者ID:Cyarix,项目名称:monotorrent,代码行数:9,代码来源:PeerExchangeManager.cs
示例18: PickPiece
public override MessageBundle PickPiece(PeerId id, BitField peerBitfield, List<PeerId> otherPeers, int count, int startIndex, int endIndex)
{
// Invert 'bitfield' and AND it with the peers bitfield
// Any pieces which are 'true' in the bitfield will not be downloaded
temp.From(peerBitfield).NAnd(bitfield);
if (temp.AllFalse)
return null;
return base.PickPiece(id, temp, otherPeers, count, startIndex, endIndex);
}
开发者ID:Cyarix,项目名称:monotorrent,代码行数:9,代码来源:IgnoringPicker.cs
示例19: PeerExchangeManager
internal PeerExchangeManager(PeerId id)
{
this.id = id;
addedPeers = new List<Peer>();
droppedPeers = new List<Peer>();
id.TorrentManager.OnPeerFound += OnAdd;
Start();
}
开发者ID:rajkosto,项目名称:DayZeroLauncher,代码行数:9,代码来源:PeerExchangeManager.cs
示例20: CancelRequest
public override void CancelRequest(PeerId peer, int piece, int startOffset, int length)
{
CancelWhere(delegate (Request r) {
return r.Block.PieceIndex == piece &&
r.Block.StartOffset == startOffset &&
r.Block.RequestLength == length &&
peer.Equals(r.Peer);
});
}
开发者ID:burris,项目名称:monotorrent,代码行数:9,代码来源:EndGamePicker.cs
注:本文中的MonoTorrent.Client.PeerId类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论