Commit 9a79d306 authored by Sébastien Blin's avatar Sébastien Blin

datatransfer: support timeout_expired status

The daemon recently introduced a new status for datatransfer:
timeout_expired, triggered when a outgoing file transfer got an
awaiting_peer status for too long and to release the TURN connection

Change-Id: I852289e47d34a8e82658a1171c31b68197b493fa
Reviewed-by: Philippe Gorley's avatarPhilippe Gorley <philippe.gorley@savoirfairelinux.com>
parent cae98b7d
......@@ -34,6 +34,7 @@ enum class Status {
stop_by_peer, // error: transfer terminated by peer
stop_by_host, // eror: transfer terminated by local host
unjoinable_peer, // error: (outgoing only) peer connection failed
timeout_expired, // error: (outgoing only) peer awaiting too long, close turn socket
invalid_pathname, // error: (file transfer only) given file is not a valid
unsupported, // error: unable to do the transfer (generic error)
INVALID
......@@ -55,6 +56,8 @@ to_string(const Status& status)
return "stop_by_host";
case Status::unjoinable_peer:
return "unjoinable_peer";
case Status::timeout_expired:
return "timeout_expired";
case Status::invalid_pathname:
return "invalid_pathname";
case Status::unsupported:
......@@ -80,6 +83,8 @@ to_status(const std::string& status)
return datatransfer::Status::stop_by_host;
else if (status == "unjoinable_peer")
return datatransfer::Status::unjoinable_peer;
else if (status == "timeout_expired")
return datatransfer::Status::timeout_expired;
else if (status == "invalid_pathname")
return datatransfer::Status::invalid_pathname;
else if (status == "unsupported")
......
......@@ -94,6 +94,7 @@ enum class Status {
TRANSFER_ONGOING,
TRANSFER_AWAITING_PEER,
TRANSFER_AWAITING_HOST,
TRANSFER_TIMEOUT_EXPIRED,
TRANSFER_FINISHED
};
......@@ -129,6 +130,8 @@ to_string(const Status& status)
return "TRANSFER_AWAITING_HOST";
case Status::TRANSFER_AWAITING_PEER:
return "TRANSFER_AWAITING_PEER";
case Status::TRANSFER_TIMEOUT_EXPIRED:
return "TRANSFER_TIMEOUT_EXPIRED";
case Status::TRANSFER_FINISHED:
return "TRANSFER_FINISHED";
case Status::INVALID:
......@@ -168,6 +171,8 @@ to_status(const std::string& status)
return interaction::Status::TRANSFER_AWAITING_HOST;
else if (status == "TRANSFER_AWAITING_PEER")
return interaction::Status::TRANSFER_AWAITING_PEER;
else if (status == "TRANSFER_TIMEOUT_EXPIRED")
return interaction::Status::TRANSFER_TIMEOUT_EXPIRED;
else if (status == "TRANSFER_FINISHED")
return interaction::Status::TRANSFER_FINISHED;
else
......
......@@ -318,6 +318,9 @@ CallbacksHandler::slotDataTransferEvent(qulonglong dringId, uint codeStatus)
case DRing::DataTransferEventCode::unsupported:
emit transferStatusError(static_cast<long long>(dringId), info);
break;
case DRing::DataTransferEventCode::timeout_expired:
emit transferStatusTimeoutExpired(static_cast<long long>(dringId), info);
break;
case DRing::DataTransferEventCode::unjoinable_peer:
emit transferStatusUnjoinable(static_cast<long long>(dringId), info);
break;
......
......@@ -168,6 +168,7 @@ Q_SIGNALS:
void transferStatusOngoing(long long dringId, api::datatransfer::Info info);
void transferStatusFinished(long long dringId, api::datatransfer::Info info);
void transferStatusError(long long dringId, api::datatransfer::Info info);
void transferStatusTimeoutExpired(long long dringId, api::datatransfer::Info info);
void transferStatusUnjoinable(long long dringId, api::datatransfer::Info info);
private Q_SLOTS:
......
......@@ -248,7 +248,9 @@ public Q_SLOTS:
void slotTransferStatusOngoing(long long dringId, api::datatransfer::Info info);
void slotTransferStatusFinished(long long dringId, api::datatransfer::Info info);
void slotTransferStatusError(long long dringId, api::datatransfer::Info info);
void slotTransferStatusTimeoutExpired(long long dringId, api::datatransfer::Info info);
void slotTransferStatusUnjoinable(long long dringId, api::datatransfer::Info info);
void updateTransferStatus(long long dringId, api::datatransfer::Info info, interaction::Status newStatus);
};
ConversationModel::ConversationModel(const account::Info& owner,
......@@ -872,6 +874,10 @@ ConversationModelPimpl::ConversationModelPimpl(const ConversationModel& linked,
&CallbacksHandler::transferStatusError,
this,
&ConversationModelPimpl::slotTransferStatusError);
connect(&callbacksHandler,
&CallbacksHandler::transferStatusTimeoutExpired,
this,
&ConversationModelPimpl::slotTransferStatusTimeoutExpired);
connect(&callbacksHandler,
&CallbacksHandler::transferStatusUnjoinable,
this,
......@@ -930,6 +936,8 @@ ConversationModelPimpl::~ConversationModelPimpl()
this, &ConversationModelPimpl::slotTransferStatusFinished);
disconnect(&callbacksHandler, &CallbacksHandler::transferStatusError,
this, &ConversationModelPimpl::slotTransferStatusError);
disconnect(&callbacksHandler, &CallbacksHandler::transferStatusTimeoutExpired,
this, &ConversationModelPimpl::slotTransferStatusTimeoutExpired);
disconnect(&callbacksHandler, &CallbacksHandler::transferStatusUnjoinable,
this, &ConversationModelPimpl::slotTransferStatusUnjoinable);
}
......@@ -1657,33 +1665,7 @@ ConversationModelPimpl::slotTransferStatusCreated(long long dringId, datatransfe
void
ConversationModelPimpl::slotTransferStatusAwaitingPeer(long long dringId, datatransfer::Info info)
{
int interactionId;
std::string convId;
if (not usefulDataFromDataTransfer(dringId, info, interactionId, convId))
return;
auto newStatus = interaction::Status::TRANSFER_AWAITING_PEER;
database::updateInteractionStatus(db, interactionId, newStatus);
auto conversationIdx = indexOf(convId);
if (conversationIdx != -1) {
bool emitUpdated = false;
interaction::Info itCopy;
{
std::lock_guard<std::mutex> lk(interactionsLocks[convId]);
auto& interactions = conversations[conversationIdx].interactions;
auto it = interactions.find(interactionId);
if (it != interactions.end()) {
emitUpdated = true;
it->second.status = newStatus;
itCopy = it->second;
}
}
if (emitUpdated) {
dirtyConversations = {true, true};
emit linked.interactionStatusUpdated(convId, interactionId, itCopy);
}
}
updateTransferStatus(dringId, info, interaction::Status::TRANSFER_AWAITING_PEER);
}
void
......@@ -1832,71 +1814,29 @@ ConversationModelPimpl::slotTransferStatusFinished(long long dringId, datatransf
void
ConversationModelPimpl::slotTransferStatusCanceled(long long dringId, datatransfer::Info info)
{
int interactionId;
std::string convId;
if (not usefulDataFromDataTransfer(dringId, info, interactionId, convId))
return;
auto newStatus = interaction::Status::TRANSFER_CANCELED;
database::updateInteractionStatus(db, interactionId, newStatus);
auto conversationIdx = indexOf(convId);
if (conversationIdx != -1) {
bool emitUpdated = false;
interaction::Info itCopy;
{
std::lock_guard<std::mutex> lk(interactionsLocks[convId]);
auto& interactions = conversations[conversationIdx].interactions;
auto it = interactions.find(interactionId);
if (it != interactions.end()) {
emitUpdated = true;
it->second.status = newStatus;
itCopy = it->second;
}
}
if (emitUpdated) {
dirtyConversations = {true, true};
emit linked.interactionStatusUpdated(convId, interactionId, itCopy);
}
}
updateTransferStatus(dringId, info, interaction::Status::TRANSFER_CANCELED);
}
void
ConversationModelPimpl::slotTransferStatusError(long long dringId, datatransfer::Info info)
{
int interactionId;
std::string convId;
if (not usefulDataFromDataTransfer(dringId, info, interactionId, convId))
return;
updateTransferStatus(dringId, info, interaction::Status::TRANSFER_ERROR);
}
// update information in the db
auto newStatus = interaction::Status::TRANSFER_ERROR;
database::updateInteractionStatus(db, interactionId, newStatus);
void
ConversationModelPimpl::slotTransferStatusUnjoinable(long long dringId, datatransfer::Info info)
{
updateTransferStatus(dringId, info, interaction::Status::TRANSFER_UNJOINABLE_PEER);
}
// prepare interaction Info and emit signal for the client
auto conversationIdx = indexOf(convId);
if (conversationIdx != -1) {
bool emitUpdated = false;
interaction::Info itCopy;
{
std::lock_guard<std::mutex> lk(interactionsLocks[convId]);
auto& interactions = conversations[conversationIdx].interactions;
auto it = interactions.find(interactionId);
if (it != interactions.end()) {
emitUpdated = true;
it->second.status = newStatus;
itCopy = it->second;
}
}
if (emitUpdated) {
dirtyConversations = {true, true};
emit linked.interactionStatusUpdated(convId, interactionId, itCopy);
}
}
void
ConversationModelPimpl::slotTransferStatusTimeoutExpired(long long dringId, datatransfer::Info info)
{
updateTransferStatus(dringId, info, interaction::Status::TRANSFER_TIMEOUT_EXPIRED);
}
void
ConversationModelPimpl::slotTransferStatusUnjoinable(long long dringId, datatransfer::Info info)
ConversationModelPimpl::updateTransferStatus(long long dringId, datatransfer::Info info, interaction::Status newStatus)
{
int interactionId;
std::string convId;
......@@ -1904,7 +1844,6 @@ ConversationModelPimpl::slotTransferStatusUnjoinable(long long dringId, datatran
return;
// update information in the db
auto newStatus = interaction::Status::TRANSFER_UNJOINABLE_PEER;
database::updateInteractionStatus(db, interactionId, newStatus);
// prepare interaction Info and emit signal for the client
......
......@@ -52,6 +52,7 @@ convertDataTransferEvent(DRing::DataTransferEventCode event)
case DRing::DataTransferEventCode::closed_by_peer: return datatransfer::Status::stop_by_peer;
case DRing::DataTransferEventCode::invalid_pathname: return datatransfer::Status::invalid_pathname;
case DRing::DataTransferEventCode::unjoinable_peer: return datatransfer::Status::unjoinable_peer;
case DRing::DataTransferEventCode::timeout_expired: return datatransfer::Status::timeout_expired;
}
throw std::runtime_error("BUG: broken convertDataTransferEvent() switch");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment