public void SaveLoadSvFileTransferRequest() { // arrange const string refUsername = "******"; const string refFileName = "crown.png"; byte[] refFileHash = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; const long refFileSize = 420042; const int refBlockSize = 8192; var refSid = new FileTransferId(81289); var msg = new SvFileTransferRequest { Username = refUsername, FileName = refFileName, FileHash = refFileHash, FileSize = refFileSize, BlockSize = refBlockSize, SessionId = refSid, }; // act MultiprotocolSaveLoad(msg, () => { // assert Assert.AreEqual(msg.Username, refUsername); Assert.AreEqual(msg.FileName, refFileName); Assert.AreEqual(msg.FileHash, refFileHash); Assert.AreEqual(msg.FileSize, refFileSize); Assert.AreEqual(msg.BlockSize, refBlockSize); Assert.AreEqual(msg.SessionId, refSid); }); }
private void OnClFileTransferRequest(ClFileTransferRequest msg, ClientId id) { var sender = clients[id]; SocketClientBase receiver; if (!nameToClient.TryGetValue(msg.Username, out receiver)) { Root.Log(LogLevel.Warning, "Server: client {0} requested file transfer " + "to unknown client {1}", id, msg.Username); var result = new SvFileTransferResult { Result = FileTransferRequestResult.Rejected, SessionId = FileTransferId.InvalidId, Token = msg.Token }; SendTo(id, result); return; } var ft = ftsContainer.CreateSession(msg.Token, sender.Login, receiver.Login, msg.FileHash, msg.FileSize); ft.SrcName = msg.FileName; ft.BlockSize = SelectBlockSize(msg.BlockSize); var request = new SvFileTransferRequest { Username = sender.Login, FileName = Path.GetFileName(msg.FileName), FileHash = msg.FileHash, FileSize = msg.FileSize, BlockSize = ft.BlockSize, SessionId = ft.Id }; SendTo(receiver.Id, request); }
private void OnSvFileTransferRequest(SvFileTransferRequest msg) { var info = new IncomingFileTransferInfo { Id = msg.SessionId, Sender = msg.Username, Name = msg.FileName, Size = msg.FileSize, Hash = msg.FileHash, InitBlockSize = Math.Min(blockSize, msg.BlockSize) }; var ft = new IncomingFileTransfer(this, info); // XXX: check key presence assignedFts.Add(ft.Id, ft); Root.Log(LogLevel.Info, "FileTransferManager: created incoming session [file='{0}', sid={1}]", msg.FileName, msg.SessionId); OnTransferRequestReceived(ft); }