private async Task <bool> ReceivePacketAsync_Plaintext() { CryptoAlgorithm alg = CryptoAlgorithm.None; byte id; // read packet id byte[] buffer = new byte[1]; if (!await channel.ReceiveAsync(buffer, 0, 1)) { return(false); } id = buffer[0]; if (!AssertInternal(id, alg) || !handler.ValidatePacket(id, alg, out PacketRule rule)) { return(false); } uint length; // read packet length if (rule.Packet.ConstantLength.HasValue) { length = rule.Packet.ConstantLength.Value; } else { buffer = new byte[4]; if (!await channel.ReceiveAsync(buffer, 0, 4)) { return(false); } length = BitConverter.ToUInt32(buffer, 0); if (!AssertSize(settings.MaxPacketSize, (int)length)) { return(false); } } buffer = new byte[length]; if (!await channel.ReceiveAsync(buffer, 0, (int)length)) // read packet content { return(false); } #if DEBUG parent.Log($"Received internal plaintext packet: ID={id} Length={length}"); #endif return(await handler.HandleInternalPacketAsync(rule, buffer)); }
private void OnFinished() { parent.ThreadManager.Post(() => Finished?.Invoke(this, null)); #if DEBUG parent.Log($"Successfully transfered file with id {Identifier} and {Mode}{Environment.NewLine}" + $"to \"{Path}\" using ContentAlgorithm.{FileMeta.Algorithm}"); #endif }
internal Task <bool> OnPacketReceivedAsync(P07OpenFileTransfer packet) { if (currentItem == null) { FTEventArgs e = new FTEventArgs(packet.Identifier, packet.StreamMode); currentItem = e; parent.ThreadManager.Post(() => Request?.Invoke(this, e)); #if DEBUG parent.Log($"FileTransfer with {e.Mode} and Identifier {e.Identifier} requested"); #endif return(Task.FromResult(true)); } else // It may be more efficient not to close the connection but only to cancel the file transfer. { parent.ExceptionHandler.CloseConnection("InvalidRequest", "A new file transfer was requested before the last one was finished or aborted.", nameof(FTSocket), "OnPacketReceivedAsync(P07OpenFileTransfer)"); return(Task.FromResult(false)); } }