From c5b971d6eacc32114fe9ae0f156a37ed56c4a194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Tue, 13 Jun 2023 19:41:25 -0400 Subject: [PATCH] connectionmanager: do not cancel all waiting channel if first is declined backport of 22d5417da3023095695d3b9655403b5632f528db in jami-daemon Change-Id: I865617ff71d1a5fc96fd075b23cd8f85dc7e6599 --- include/multiplexed_socket.h | 4 ++-- src/connectionmanager.cpp | 2 +- src/multiplexed_socket.cpp | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/multiplexed_socket.h b/include/multiplexed_socket.h index d8e6e16..9e254bb 100644 --- a/include/multiplexed_socket.h +++ b/include/multiplexed_socket.h @@ -48,7 +48,7 @@ using OnConnectionRequestCb const std::string& /* name */)>; using OnConnectionReadyCb = std::function<void(const DeviceId& /* deviceId */, const std::shared_ptr<ChannelSocket>&)>; -using ChannelReadyCb = std::function<void(void)>; +using ChannelReadyCb = std::function<void(bool)>; using OnShutdownCb = std::function<void(void)>; static constexpr auto SEND_BEACON_TIMEOUT = std::chrono::milliseconds(3000); @@ -298,7 +298,7 @@ public: */ void shutdown() override; - void ready(); + void ready(bool accepted); /** * Triggered when a specific channel is ready * Used by ConnectionManager::connectDevice() diff --git a/src/connectionmanager.cpp b/src/connectionmanager.cpp index 03e4c65..17206d3 100644 --- a/src/connectionmanager.cpp +++ b/src/connectionmanager.cpp @@ -642,7 +642,7 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif const auto& pendings = pendingsIt->second; while (pendings.connecting.find(vid) != pendings.connecting.end() && pendings.waiting.find(vid) != pendings.waiting.end()) { - vid = ValueIdDist(1, JAMI_ID_MAX_VAL)(sthis->account.rand); + vid = ValueIdDist(1, ID_MAX_VAL)(sthis->rand); } } // Check if already connecting diff --git a/src/multiplexed_socket.cpp b/src/multiplexed_socket.cpp index 5abf742..dd6c298 100644 --- a/src/multiplexed_socket.cpp +++ b/src/multiplexed_socket.cpp @@ -283,7 +283,7 @@ MultiplexedSocket::Impl::onAccept(const std::string& name, uint16_t channel) } onChannelReady_(deviceId, socket); - socket->ready(); + socket->ready(true); // Due to the callbacks that can take some time, onAccept can arrive after // receiving all the data. In this case, the socket should be removed here // as handle by onChannelReady_ @@ -420,7 +420,7 @@ MultiplexedSocket::Impl::onRequest(const std::string& name, uint16_t channel) if (accept) { onChannelReady_(deviceId, channelSocket); - channelSocket->ready(); + channelSocket->ready(true); } } @@ -448,6 +448,7 @@ MultiplexedSocket::Impl::handleControlPacket(std::vector<uint8_t>&& pkt) std::lock_guard<std::mutex> lkSockets(pimpl.socketsMutex); auto channel = pimpl.sockets.find(req.channel); if (channel != pimpl.sockets.end()) { + channel->second->ready(false); channel->second->stop(); pimpl.sockets.erase(channel); } @@ -1074,10 +1075,10 @@ ChannelSocket::isAnswered() const } void -ChannelSocket::ready() +ChannelSocket::ready(bool accepted) { if (pimpl_->readyCb_) - pimpl_->readyCb_(); + pimpl_->readyCb_(accepted); } void -- GitLab