Class representing the queue of peer recognized as senders of a particular resource. It works to allow to balance load over peer while chosing every time the best peer to request to. This class is strictly connected to its foundamentals elements represented by theclass PeerQueueElement.
Ejemplo n.º 1
0
 /// <summary>
 /// Start method of the class. This method allows the thread to start the procedure of download of
 /// a remote resource in a separate thread. It initialize all attributes related to the resource.
 /// </summary>
 /// <param name="RID">Identificator of the resource</param>
 /// <param name="begin">Start point from the beginning of the file to begin download</param>
 /// <param name="length">>Total length in bytes of the resource</param>
 /// <param name="peerQueue">PeerQueue of peers containing the resource with a score associated to each peer</param>
 /// <param name="s">Stream where the resource is written</param>
 public void Start(string RID, int begin, long length, Dictionary <string, float> peerQueue, Stream s)
 {
     this.worker    = new Thread(() => doWork());
     this.RID       = RID;
     this.peerQueue = new PeerQueue(peerQueue);
     log.Info("Starting download of Resource identified by " + RID + " from " + begin + " with a len of " + length);
     this.maxNumber = System.Convert.ToInt32(
         Math.Floor((double)(length / (this.chunkLength * 1024)))
         );
     this.maxNumber -= begin;
     this.writer     = s;
     this.buffer     = new Dictionary <int, BufferChunk>();
     for (int i = begin; i < this.maxNumber; i++)
     {
         this.buffer[i] = new BufferChunk();
     }
     this.nextChunkToWrite = begin;
     this.started          = true;
     this.worker.Start();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Start method of the class. This method allows the thread to start the procedure of download of
 /// a remote resource in a separate thread. It initialize all attributes related to the resource.
 /// </summary>
 /// <param name="RID">Identificator of the resource</param>
 /// <param name="begin">Start point from the beginning of the file to begin download</param>
 /// <param name="length">>Total length in bytes of the resource</param>
 /// <param name="peerQueue">PeerQueue of peers containing the resource with a score associated to each peer</param>
 /// <param name="s">Stream where the resource is written</param>
 public void Start(string RID, int begin, long length, Dictionary<string, float> peerQueue, Stream s)
 {
     this.worker = new Thread(() => doWork());
     this.RID = RID;
     this.peerQueue = new PeerQueue(peerQueue);
     log.Info("Starting download of Resource identified by " + RID + " from " + begin + " with a len of " + length);
     this.maxNumber = System.Convert.ToInt32(
         Math.Floor((double)(length / (this.chunkLength * 1024)))
     );
     this.maxNumber -= begin;
     this.writer = s;
     this.buffer = new Dictionary<int, BufferChunk>();
     for (int i = begin; i < this.maxNumber; i++)
     {
         this.buffer[i] = new BufferChunk();
     }
     this.nextChunkToWrite = begin;
     this.started = true;
     this.worker.Start();
 }