Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix work with compat target issue #613

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void SendRpcWork::handleDoSendProtoMsg(const uint32 type, const QString appName,
{
if (_stoped)
return;
DLOG << "000000 " << appName.toStdString() << type << msg.toStdString();
DLOG << "compat: " << appName.toStdString() << " type:" << type << " msg:" << msg.toStdString();
auto sender = this->rpcSender(appName);

SendResult res;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/cooperation/core/net/helper/sharehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void ShareHelperPrivate::initConnect()
void ShareHelperPrivate::cancelShareApply()
{
taskDialog()->hide();
NetworkUtil::instance()->cancelApply("share");
NetworkUtil::instance()->cancelApply("share", targetDeviceInfo->ipAddress());
}

void ShareHelperPrivate::notifyMessage(const QString &body, const QStringList &actions, int expireTimeout)
Expand Down Expand Up @@ -159,9 +159,9 @@ void ShareHelperPrivate::onActionTriggered(const QString &action)
{
isReplied = true;
if (action == NotifyRejectAction) {
NetworkUtil::instance()->replyShareRequest(false, selfFingerPrint);
NetworkUtil::instance()->replyShareRequest(false, selfFingerPrint, senderDeviceIp);
} else if (action == NotifyAcceptAction) {
NetworkUtil::instance()->replyShareRequest(true, selfFingerPrint);
NetworkUtil::instance()->replyShareRequest(true, selfFingerPrint, senderDeviceIp);

auto client = ShareCooperationServiceManager::instance()->client();
// remove "--disable-crypto" if receive server has fingerprint.
Expand Down
14 changes: 8 additions & 6 deletions src/lib/cooperation/core/net/helper/transferhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ void TransferHelper::registBtn()
void TransferHelper::sendFiles(const QString &ip, const QString &devName, const QStringList &fileList)
{
d->who = devName;
d->targetDeviceIp = ip;
d->readyToSendFiles = fileList;
if (fileList.isEmpty())
return;
Expand Down Expand Up @@ -315,12 +316,12 @@ void TransferHelper::onActionTriggered(const QString &action)
d->transferInfo.clear();
if (action == NotifyCancelAction) {
cancelTransfer(true); // do UI first
NetworkUtil::instance()->cancelTrans();
NetworkUtil::instance()->cancelTrans(d->targetDeviceIp);
} else if (action == NotifyRejectAction) {
NetworkUtil::instance()->replyTransRequest(false);
NetworkUtil::instance()->replyTransRequest(false, d->targetDeviceIp);
} else if (action == NotifyAcceptAction) {
d->role = Client;
NetworkUtil::instance()->replyTransRequest(true);
NetworkUtil::instance()->replyTransRequest(true, d->targetDeviceIp);
} else if (action == NotifyCloseAction) {
#ifdef __linux__
d->notice->closeNotification();
Expand Down Expand Up @@ -354,6 +355,7 @@ void TransferHelper::notifyTransferRequest(const QString &nick, const QString &i

static QString msg(tr("\"%1\" send some files to you"));
d->who = nick;
d->targetDeviceIp = ip;
#ifdef __linux__

QStringList actions { NotifyRejectAction, tr("Reject"),
Expand Down Expand Up @@ -500,7 +502,7 @@ void TransferHelper::accepted()
d->role = Server;
d->status.storeRelease(Transfering);
updateProgress(1, tr("calculating"));
NetworkUtil::instance()->doSendFiles(d->readyToSendFiles);
NetworkUtil::instance()->doSendFiles(d->readyToSendFiles, d->targetDeviceIp);
}

void TransferHelper::rejected()
Expand Down Expand Up @@ -533,7 +535,7 @@ void TransferHelper::cancelTransferApply()
d->status.storeRelease(Idle);
d->confirmTimer.stop();
d->transDialog()->hide();
NetworkUtil::instance()->cancelApply("transfer");
NetworkUtil::instance()->cancelApply("transfer", d->targetDeviceIp);
}

// ----------compat the old protocol-----------
Expand Down Expand Up @@ -618,7 +620,7 @@ void TransferHelper::onTransferExcepted(int type, const QString &remote)

cancelTransfer(true); // hide dialog first and show exception
// cancel transfer and hide progress
NetworkUtil::instance()->cancelTrans();
NetworkUtil::instance()->cancelTrans(remote);

switch (type) {
case EX_NETWORK_PINGOUT:
Expand Down
2 changes: 2 additions & 0 deletions src/lib/cooperation/core/net/helper/transferhelper_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class TransferHelperPrivate : public QObject
QString recvFilesSavePath;

QTimer confirmTimer;
// 作为接收方时,发送方的ip; 作为发送方时,接收方的ip
QString targetDeviceIp;

#ifdef __linux__
NoticeUtil *notice { nullptr };
Expand Down
20 changes: 10 additions & 10 deletions src/lib/cooperation/core/net/networkutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,9 @@ void NetworkUtil::sendDisconnectShareEvents(const QString &ip)
}
}

void NetworkUtil::replyTransRequest(bool agree)
void NetworkUtil::replyTransRequest(bool agree, const QString &targetIp)
{
if (!d->confirmTargetAddress.isEmpty()) {
if (d->confirmTargetAddress == targetIp) {
// send transfer reply, skip result
ApplyMessage msg;
msg.flag = agree ? REPLY_ACCEPT : REPLY_REJECT;
Expand All @@ -699,9 +699,9 @@ void NetworkUtil::replyTransRequest(bool agree)
}
}

void NetworkUtil::replyShareRequest(bool agree, const QString &selfprint)
void NetworkUtil::replyShareRequest(bool agree, const QString &selfprint, const QString &targetIp)
{
if (!d->confirmTargetAddress.isEmpty()) {
if (d->confirmTargetAddress == targetIp) {
// send transfer reply, skip result
ApplyMessage msg;
msg.flag = agree ? REPLY_ACCEPT : REPLY_REJECT;
Expand All @@ -721,9 +721,9 @@ void NetworkUtil::replyShareRequest(bool agree, const QString &selfprint)
}
}

void NetworkUtil::cancelApply(const QString &type)
void NetworkUtil::cancelApply(const QString &type, const QString &targetIp)
{
if (!d->confirmTargetAddress.isEmpty()) {
if (d->confirmTargetAddress == targetIp) {
ApplyMessage msg;
msg.nick = type.toStdString();
QString jsonMsg = msg.as_json().serialize().c_str();
Expand All @@ -738,9 +738,9 @@ void NetworkUtil::cancelApply(const QString &type)
}
}

void NetworkUtil::cancelTrans()
void NetworkUtil::cancelTrans(const QString &targetIp)
{
if (!d->confirmTargetAddress.isEmpty()) {
if (d->confirmTargetAddress == targetIp) {
d->sessionManager->cancelSyncFile(d->confirmTargetAddress);
} else {
#ifdef ENABLE_COMPAT
Expand All @@ -753,9 +753,9 @@ void NetworkUtil::cancelTrans()
}
}

void NetworkUtil::doSendFiles(const QStringList &fileList)
void NetworkUtil::doSendFiles(const QStringList &fileList, const QString &targetIp)
{
if (!d->confirmTargetAddress.isEmpty()) {
if (d->confirmTargetAddress == targetIp) {
int ranport = deepin_cross::CommonUitls::getAvailablePort();
d->sessionManager->sendFiles(d->confirmTargetAddress, ranport, fileList);
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/cooperation/core/net/networkutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ class NetworkUtil : public QObject
//transfer
void tryTransApply(const QString &ip);
void sendTransApply(const QString &ip, bool compat);
void replyTransRequest(bool agree);
void cancelTrans();
void doSendFiles(const QStringList &fileList);
void replyTransRequest(bool agree, const QString &targetIp);
void cancelTrans(const QString &targetIp);
void doSendFiles(const QStringList &fileList, const QString &targetIp);

//Keymouse sharing
void tryShareApply(const QString &ip, const QString &selfprint);
void sendShareApply(const QString &ip, bool compat);
void sendDisconnectShareEvents(const QString &ip);
void replyShareRequest(bool agree, const QString &selfprint);
void cancelApply(const QString &type);
void replyShareRequest(bool agree, const QString &selfprint, const QString &targetIp);
void cancelApply(const QString &type, const QString &targetIp);

QString deviceInfoStr();

Expand Down