public FileReqMeta GenerateMetadataRequest() { //collect details from all fileTransRequests List <FileMeta> fileDetails = new List <FileMeta>(); foreach (FileTransReq fileTransReq in FileTransReqs) { fileDetails.Add(fileTransReq.FileDetails); } FileReqMeta fileSendMetadata = new FileReqMeta(fileDetails, bufferSize, targetIpAddress); return(fileSendMetadata); }
private async Task <FileReceiveReq> CreateFileReceiveReq(FileReqMeta fileRequest, Metadata mMetadata) { //open stream for all files being received List <FileTransReq> fileTrans = new List <FileTransReq>(); foreach (FileMeta file in fileRequest.Files) { FileTransReq fileTran = await SetupTransmitionForNewFile(file, fileRequest.BufferSize); fileTrans.Add(fileTran); } FileReceiveReq fileReceivedReq = new FileReceiveReq(fileTrans, mMetadata.SourceIp); return(fileReceivedReq); }
//TODO: update description /// <summary> /// send file to the peer with the given IP address via a reliable TCP connection. /// Works by breaking down the file into blocks each of length <C>bufferSize</C>. Each block is /// then compressed and sent one by one to the other peer. /// /// Note: can only send one file request at a time. Wait until This function has triggered an /// file received event before continuing /// </summary> /// <param name="ipAddress">The IP address of the peer to send the message to</param> /// <param name="filePath">The path to the file you want to send</param> /// <param name="bufferSize"> /// Using a small buffer size will trigger <c>FileProgUpdate</c>> more but /// will also increase buffer overhead. Buffer size is also the max amount of memory /// a file will occupy in RAM. /// </param> /// <returns></returns> public async Task SendFileAsync(string ipAddress, List <string> filePaths, int bufferSize = 100 * 1024) { //TODO: check if there is an active sendFile request to the target ip address //create a file send request FileSentReq fileSentRequest = await CreateFileSendReq(ipAddress, filePaths, bufferSize); sendFileRequests.Add(fileSentRequest); //send file request metadata to receiver FileReqMeta fileMetadata = fileSentRequest.GenerateMetadataRequest(); await ObjectManager.SendAsyncTCP(ipAddress, fileMetadata); //receiver will then send back a acceptance message which is proccessed in ProcessAckMessage() }
private async Task ProcessIncomingFilesRequest(FileReqMeta fileRequest, Metadata mMetadata) { //determine whether or not to accept the incoming file request bool validFileRequest = IsValidFileRequest(fileRequest, mMetadata); FileReceiveReq fileReceiveReq = null; if (validFileRequest) { //add to a file recieved request fileReceiveReq = await CreateFileReceiveReq(fileRequest, mMetadata); receivedFileRequests.Add(fileReceiveReq); } //send message back to sender ReqAck fileRequestResp = new ReqAck(validFileRequest); await ObjectManager.SendAsyncTCP(mMetadata.SourceIp, fileRequestResp); }
private async void ObjManager_objReceived(object sender, ObjReceivedEventArgs e) { BObject bObj = e.Obj; Metadata metadata = bObj.GetMetadata(); ObjReceived?.Invoke(this, e); string objType = bObj.GetType(); switch (objType) { case "FilePartObj": FilePartObj filePart = e.Obj.GetObject <FilePartObj>(); await ProcessFilePart(filePart, metadata); break; /* * case "FileAck": * FileAck ackMsg = e.Obj.GetObject<FileAck>(); * await ProcessAckMessage(ackMsg, metadata); * break; */ case "FileReqMeta": FileReqMeta fileRequestMetadata = e.Obj.GetObject <FileReqMeta>(); await ProcessIncomingFilesRequest(fileRequestMetadata, metadata); break; case "ReqAck": ReqAck fileReqAck = e.Obj.GetObject <ReqAck>(); await ProcessFileReqAck(fileReqAck, metadata); break; default: break; } }
private bool IsValidFileRequest(FileReqMeta fileRequest, Metadata metadata) { //TODO: check file metadata and then reject/Accept request //TODO: also reject request if there is already an activity request from the same peer return(true); }