add: basic req trans.

This commit is contained in:
2025-06-18 13:18:31 +08:00
parent 280721f29b
commit 5dcf638e62
7 changed files with 121 additions and 12 deletions

View File

@@ -1,13 +1,81 @@
#include "FileTrans.h"
#include <QFileInfo>
FileTrans::FileTrans(ClientCore* clientCore) : clientCore_(clientCore)
{
RegisterFrameCall();
}
void FileTrans::SetTasks(const QVector<TransTask>& tasks)
/*
* When the local client actively sends a file, it cannot simultaneously perform download operations.
* Passive sending is an exception, primarily to monitor the sending progress. In contrast,
* the progress of passive sending is monitored by the requesting download side,
* so there is no need to track the progress locally.
*/
void FileTrans::ReqSendFile(const TransTask& task)
{
localTasks_ = tasks;
// TODO: check if running...
// start
InfoMsg info;
info.toPath = task.remotePath;
info.fromPath = task.localPath;
QFileInfo fileInfo(info.fromPath);
if (fileInfo.exists()) {
qint64 size = fileInfo.size();
info.permissions = static_cast<quint32>(fileInfo.permissions());
info.size = size;
} else {
sigError(QString(tr("File [%1] not exit.")).arg(info.fromPath));
return;
}
if (!clientCore_->Send<InfoMsg>(info, FBT_CLI_REQ_SEND, task.remoteId)) {
sigError(QString(tr("send req send failed: %1")).arg(info.msg));
sendTask_.state = TaskState::STATE_NONE;
return;
}
sendTask_.state = TaskState::STATE_RUNNING;
sendTask_.totalSize = info.size;
sendTask_.tranSize = 0;
}
void FileTrans::ReqDownFile(const TransTask& task)
{
// TODO: check if running...
// start
InfoMsg info;
info.toPath = task.localPath;
info.fromPath = task.remotePath;
if (!clientCore_->Send<InfoMsg>(info, FBT_CLI_REQ_DOWN, task.remoteId)) {
sigError(QString(tr("send req send failed: %1")).arg(info.msg));
sendTask_.state = TaskState::STATE_NONE;
return;
}
sendTask_.state = TaskState::STATE_RUNNING;
}
qint32 FileTrans::GetSendProgress()
{
if (sendTask_.state != TaskState::STATE_RUNNING) {
return -1;
}
double per = (sendTask_.tranSize * 100.0) / sendTask_.totalSize;
return per;
}
qint32 FileTrans::GetDownProgress()
{
if (downTask_.state != TaskState::STATE_RUNNING) {
return -1;
}
double per = (downTask_.tranSize * 100.0) / downTask_.totalSize;
return per;
}
void FileTrans::RegisterFrameCall()
@@ -152,7 +220,8 @@ void FileTrans::SendFile(const QSharedPointer<DoTransTask>& task)
auto* sendThread = new SendThread(clientCore_);
sendThread->setTask(task);
QMutexLocker locker(&sthMut_);
sendThreads_.push_back(sendThread);
// TODO: check if already exist
upTasks_[task->task.localId] = sendThread;
sendThread->run();
}

View File

@@ -52,12 +52,18 @@ private:
class FileTrans : public QObject
{
Q_OBJECT
public:
FileTrans(ClientCore* clientCore);
public:
void SetTasks(const QVector<TransTask>& tasks);
void RegisterFrameCall();
void ReqSendFile(const TransTask& task);
void ReqDownFile(const TransTask& task);
qint32 GetSendProgress();
qint32 GetDownProgress();
signals:
void sigError(const QString& err);
private:
void fbtReqSend(QSharedPointer<FrameBuffer> frame);
@@ -71,19 +77,18 @@ private:
void fbtTransFailed(QSharedPointer<FrameBuffer> frame);
private:
void RegisterFrameCall();
void SendFile(const QSharedPointer<DoTransTask>& task);
private:
DoTransTask downTask_;
DoTransTask sendTask_;
QMutex lMut_;
QMutex rMut_;
QVector<TransTask> localTasks_;
QVector<TransTask> remoteTasks_;
ClientCore* clientCore_;
QMutex sthMut_;
QVector<QThread*> sendThreads_;
QMap<QString, QThread*> upTasks_;
};

View File

@@ -33,7 +33,6 @@ void FileManager::SetModeStr(const QString& modeStr, int type, ClientCore* clien
remotePtr->registerPathCall([this](const QString& path) { ShowPath(path); });
remotePtr->registerFileCall([this](const DirFileInfoVec& info) { ShowFile(info); });
remotePtr->setClientCore(clientCore);
fileTrans_ = new FileTrans(clientCore);
fileHelper_ = remotePtr;
}
}

View File

@@ -6,7 +6,6 @@
#include <QWidget>
#include <Util.h>
#include <QMenu>
#include <FileTrans.h>
namespace Ui {
class FileManager;
@@ -39,7 +38,6 @@ private:
Ui::FileManager* ui;
QString curRoot_;
QMenu* menu_;
FileTrans* fileTrans_;
std::shared_ptr<DirFileHelper> fileHelper_;
};

View File

@@ -1,4 +1,5 @@
#include "Transform.h"
#include <QMessageBox>
#include "ui_Transform.h"
@@ -16,4 +17,23 @@ TransForm::~TransForm()
void TransForm::SetClientCore(ClientCore* clientCore)
{
clientCore_ = clientCore;
fileTrans_ = new FileTrans(clientCore_);
}
void TransForm::SetTasks(const QVector<TransTask>& tasks)
{
tasks_ = tasks;
}
void TransForm::startTask()
{
for (auto& task : tasks_) {
}
}
void TransForm::showEvent(QShowEvent* event)
{
QDialog::showEvent(event);
startTask();
}

View File

@@ -4,6 +4,7 @@
#include <ClientCore.h>
#include <QDialog>
#include <QFile>
#include <FileTrans.h>
namespace Ui {
class TransForm;
@@ -19,9 +20,18 @@ public:
public:
void SetClientCore(ClientCore* clientCore);
void SetTasks(const QVector<TransTask>& tasks);
private:
ClientCore* clientCore_;
void startTask();
protected:
void showEvent(QShowEvent* event) override;
private:
QVector<TransTask> tasks_;
FileTrans* fileTrans_{};
ClientCore* clientCore_{};
Ui::TransForm* ui;
};

View File

@@ -1,3 +1,11 @@
# frelay
A tool that uses a relay server to upload and download files from remote clients.
## Features
1. Minimal configuration—simply start a server, connect to it, and begin transferring files.
2. If you frequently transfer the same files repeatedly, frelay offers a local-remote file mapping feature for one-click transfers.
## Disclaimer
This tool is solely designed for simple file transmission between clients via a relay server. It does not include any security validation logic to prevent data attacks or similar threats. It is primarily intended for temporary, non-sensitive file transfers. Please close the software or disconnect from the relay server when not in use.