Exemplo n.º 1
0
        /// <summary>
        /// Processes the Data Carrying Packet and delivers it to the correct process
        /// </summary>
        /// <param name="dcp"></param>
        /// <param name="ep"></param>
        private static void ProcessDataCarryingPacket(DataCarryPacket dcp, IPEndPoint ep)
        {
            int id = dcp.GetReceiverTransferID();


            if (ActiveInboundTransferProcesses[id] != null)
            {
                ActiveInboundTransferProcesses[id].ReceivePacket(dcp);
            }
            else
            {
                SendTransferTermination(ep, id);
            }
        }
Exemplo n.º 2
0
 private DataCarryPacket CreateDataPacket()
 {
     if (IsLastChunk())
     {
         LastChunkSent = true;
         //DataCarryPacket dcp = new DataCarryPacket(ChunkNumber, RemoteTransferID, true, GetChunk(FileBuffer.Length - ReadIndex));
         DataCarryPacket dcp = new DataCarryPacket(ChunkNumber, RemoteTransferID, true, GetChunk(SelectedFileStructure.FileSize - ReadIndex));
         return(dcp);
     }
     else
     {
         DataCarryPacket dcp = new DataCarryPacket(ChunkNumber, RemoteTransferID, false, GetChunk(ChunkSize));
         return(dcp);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Sends a packet with the new chunk
        /// </summary>
        private void SendChunk()
        {
            // Update progress
            //decimal pp = (decimal)ReadIndex / (decimal)FileBuffer.Length;
            decimal pp      = (decimal)ReadIndex / (decimal)SelectedFileStructure.FileSize;
            int     percent = (int)Math.Round(pp * 100);

            if (percent > DownloadProgressNextTick)
            {
                FileTransferProgressEventArgs args = new FileTransferProgressEventArgs();
                args.PercentProgress = percent;
                args.ID       = LocalTransferID;
                args.FileName = SelectedFileStructure.FullName;
                OutTransferProgress?.Invoke(null, args);
                DownloadProgressNextTick = percent + DownloadProgressTreshold;
            }

            DataCarryPacket dcp = CreateDataPacket();

            NetComm.SendByteArray(dcp.ToByteArray(), TargetEndPoint);
            LastActionSnapshot = timer.ElapsedMilliseconds;
            //DataCarryPacket dcp = new DataCarryPacket(NextBlockNumber, TransferID, )
        }