Skip to content
Snippets Groups Projects
Commit a9ef2a5e authored by Adrien Béraud's avatar Adrien Béraud
Browse files

ConnectionManager: remove pending callback after success

Change-Id: I03cf7bead8bcf5760d035e32a82ec3412ef6fea9
parent f8b33b2f
Branches
No related tags found
No related merge requests found
...@@ -472,6 +472,7 @@ public: ...@@ -472,6 +472,7 @@ public:
* @param deviceId to identify the linked ConnectCallback * @param deviceId to identify the linked ConnectCallback
*/ */
void sendChannelRequest(const std::weak_ptr<DeviceInfo>& dinfo, void sendChannelRequest(const std::weak_ptr<DeviceInfo>& dinfo,
const std::weak_ptr<ConnectionInfo>& cinfo,
const std::shared_ptr<MultiplexedSocket>& sock, const std::shared_ptr<MultiplexedSocket>& sock,
const std::string& name, const std::string& name,
const dht::Value::Id& vid); const dht::Value::Id& vid);
...@@ -898,7 +899,7 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif ...@@ -898,7 +899,7 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif
lk.unlock(); lk.unlock();
if (sthis->config_->logger) if (sthis->config_->logger)
sthis->config_->logger->debug("[device {}] Peer already connected. Add a new channel", deviceId); sthis->config_->logger->debug("[device {}] Peer already connected. Add a new channel", deviceId);
sthis->sendChannelRequest(di, sock, name, vid); sthis->sendChannelRequest(di, info, sock, name, vid);
return; return;
} }
} }
...@@ -1035,7 +1036,8 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif ...@@ -1035,7 +1036,8 @@ ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certif
} }
void void
ConnectionManager::Impl::sendChannelRequest(const std::weak_ptr<DeviceInfo>& dinfo, ConnectionManager::Impl::sendChannelRequest(const std::weak_ptr<DeviceInfo>& dinfow,
const std::weak_ptr<ConnectionInfo>& cinfow,
const std::shared_ptr<MultiplexedSocket>& sock, const std::shared_ptr<MultiplexedSocket>& sock,
const std::string& name, const std::string& name,
const dht::Value::Id& vid) const dht::Value::Id& vid)
...@@ -1044,18 +1046,23 @@ ConnectionManager::Impl::sendChannelRequest(const std::weak_ptr<DeviceInfo>& din ...@@ -1044,18 +1046,23 @@ ConnectionManager::Impl::sendChannelRequest(const std::weak_ptr<DeviceInfo>& din
if (!channelSock) { if (!channelSock) {
if (config_->logger) if (config_->logger)
config_->logger->error("sendChannelRequest failed - cannot create channel"); config_->logger->error("sendChannelRequest failed - cannot create channel");
if (auto info = dinfo.lock()) if (auto info = dinfow.lock())
info->executePendingOperations(vid, nullptr); info->executePendingOperations(vid, nullptr);
return; return;
} }
channelSock->onShutdown([dinfo, name, vid] { channelSock->onShutdown([dinfow, name, vid] {
if (auto info = dinfo.lock()) if (auto info = dinfow.lock())
info->executePendingOperations(vid, nullptr); info->executePendingOperations(vid, nullptr);
}); });
channelSock->onReady( channelSock->onReady(
[dinfo, wSock = std::weak_ptr(channelSock), name, vid](bool accepted) { [dinfow, cinfow, wSock = std::weak_ptr(channelSock), name, vid](bool accepted) {
if (auto info = dinfo.lock()) if (auto dinfo = dinfow.lock()) {
info->executePendingOperations(vid, accepted ? wSock.lock() : nullptr, accepted); dinfo->executePendingOperations(vid, accepted ? wSock.lock() : nullptr, accepted);
if (auto cinfo = cinfow.lock()) {
std::lock_guard<std::mutex> lk(cinfo->mutex_);
cinfo->cbIds_.erase(vid);
}
}
}); });
ChannelRequest val; ChannelRequest val;
...@@ -1219,7 +1226,7 @@ ConnectionManager::Impl::onTlsNegotiationDone(const std::shared_ptr<DeviceInfo>& ...@@ -1219,7 +1226,7 @@ ConnectionManager::Impl::onTlsNegotiationDone(const std::shared_ptr<DeviceInfo>&
if (config_->logger) if (config_->logger)
config_->logger->debug("[device {}] Send request on TLS socket for channel {}", config_->logger->debug("[device {}] Send request on TLS socket for channel {}",
deviceId, name); deviceId, name);
sendChannelRequest(dinfo, info->socket_, name, id); sendChannelRequest(dinfo, info, info->socket_, name, id);
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment