Ejemplo n.º 1
0
 public InboundTransferEventArgs(int _transferID, bool _successful, byte[] _fileBuffer, LocalFileStructure _fileStructure)
 {
     TransferID    = _transferID;
     IsSuccessful  = _successful;
     FileBuffer    = _fileBuffer;
     FileStructure = _fileStructure;
 }
Ejemplo n.º 2
0
        public TransferRequestPacket(LocalFileStructure fStruct, int localID)
        {
            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteInteger(localID);
            buffer.WriteLong(fStruct.FileSize);
            buffer.WriteString(fStruct.FileName);
            buffer.WriteString(fStruct.FileExtension);
            PacketData = buffer.ToArray();
            PacketType = "_TFR";
        }
Ejemplo n.º 3
0
        public OutBoundTransferProcess(LocalFileStructure _file, IPEndPoint _endPoint, UInt32 _chunkSize, int _localID)
        {
            TargetEndPoint        = _endPoint;
            SelectedFileStructure = _file;
            ChunkSize             = _chunkSize;
            ReadIndex             = 0;
            ChunkNumber           = 0;
            timer           = new Stopwatch();
            LocalTransferID = _localID;
            ProcessState    = SendProcessState.Inactive;
            Terminated      = false;

            DownloadProgressTreshold = 5; // Update progress every 5%
        }
 public bool Equals(LocalFileStructure other)
 {
     if (ReferenceEquals(other, null))
     {
         return(false);
     }
     if (ReferenceEquals(other, this))
     {
         return(true);
     }
     return(string.Equals(FileName, other.FileName) &&
            string.Equals(FileExtension, other.FileExtension) &&
            FileSize == other.FileSize);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Attempts to start the process of sending a file, returning the ID of the slot. If unsuccessful, returns -1
        /// </summary>
        /// <param name="fStruct"></param>
        /// <param name="endPoint"></param>
        /// <returns></returns>
        private static bool SendFile(LocalFileStructure fStruct)
        {
            if (ActiveOutboundTransferProcess != null)
            {
                return(false);
            }

            ActiveOutboundTransferProcess = new OutBoundTransferProcess(fStruct, TargetEndPoint, MaxChunkSize, fStruct.FileID);
            ActiveOutboundTransferProcess.OutTransferFinished += OutTransferFinished;
            ActiveOutboundTransferProcess.OutTransferStarted  += OutTransferStarted;
            ActiveOutboundTransferProcess.OutTransferProgress += OutTransferProgress;
            ActiveOutboundTransferProcess.Start();

            return(true);
        }
        public InboundTransferProcess(int _transferID, LocalFileStructure _fileStructure, IPEndPoint _senderEP, IFileHandler handler)
        {
            ExpectedNextChunkNumber = 0;
            ReceivedChunksCount     = 0;
            IncomingFileStructure   = _fileStructure;
            SenderEndPoint          = _senderEP;
            TransferID   = _transferID;
            _fileHandler = handler;

            TempFilePath = _fileHandler.GetValidPath(Path.Combine(ProgramSettings.StorageFolderPath, _fileStructure.FileName + ".fjtemp"));

            var f = File.Create(TempFilePath);

            f.Close();

            fStream = new FileStream(TempFilePath, FileMode.Append, FileAccess.Write);
        }
Ejemplo n.º 7
0
        private static void ProcessFileTransferRequest(IPEndPoint ep, TransferRequestPacket packet)
        {
            LocalFileStructure fStruct = packet.GetFileStructure();

            if (fStruct == null)
            {
                // Send error
                return;
            }
            // Check that its ok

            //if(fStruct.FileSize > 500000000) // Refuse if over 500mb
            //{
            //    // Send transfer refusal

            //    return;
            //}


            // set up

            int slot = GetAviableInboundTransferProcessID();

            if (slot == -1)
            {
                // Send transfer refusal. No slots aviable
                return;
            }

            // Create a new inbound process
            ActiveInboundTransferProcesses[slot] = new InboundTransferProcess(packet.GetSenderTransferID(),
                                                                              fStruct,
                                                                              ep,
                                                                              _fileHandler);

            ActiveInboundTransferProcesses[slot].OnTransferFinished += InboundTransferFinished;

            // Send Transfer acceptal
            TransferAcceptPacket ta = new TransferAcceptPacket(slot, packet.GetSenderTransferID());

            NetComm.SendByteArray(ta.ToByteArray(), ep);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns a FileStructure object containing the information
        /// </summary>
        /// <returns></returns>
        public LocalFileStructure GetFileStructure()
        {
            if (PacketData == null || PacketData.Length < 12)
            {
                return(null);
            }

            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteBytes(PacketData);

            LocalFileStructure fStruct = new LocalFileStructure();

            buffer.ReadInteger(); // Ignore the local ID
            fStruct.FileSize      = buffer.ReadLong();
            fStruct.FileName      = buffer.ReadString();
            fStruct.FileExtension = buffer.ReadString();
            fStruct.FullName      = fStruct.FileName + fStruct.FileExtension;

            buffer.Dispose();

            return(fStruct);
        }