Skip to content

Commit

Permalink
ConnectionManager: send beacon to existing device connections on connect
Browse files Browse the repository at this point in the history
Change-Id: I78c8b85a62172e8304b4bf21d4d3647f17aefbed
  • Loading branch information
aberaud committed Sep 26, 2024
1 parent 125f5b3 commit aca437e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/connectionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ struct DeviceInfo {
}
return {};
}
std::vector<std::shared_ptr<ConnectionInfo>> getConnectedInfos() const {
std::vector<std::shared_ptr<ConnectionInfo>> ret;
for (auto& [id, ci] : info) {
if (ci->socket_)
ret.emplace_back(ci);
}
return ret;
}

std::vector<PendingCb> extractPendingOperations(dht::Value::Id vid, const std::shared_ptr<ChannelSocket>& sock, bool accepted = true)
{
Expand Down Expand Up @@ -1202,11 +1210,23 @@ ConnectionManager::Impl::onTlsNegotiationDone(const std::shared_ptr<DeviceInfo>&
// Note: do not remove pending there it's done in sendChannelRequest
std::unique_lock lk2 {dinfo->mtx_};
auto pendingIds = dinfo->requestPendingOps();
auto previousConnections = dinfo->getConnectedInfos();
lk2.unlock();
std::unique_lock lk {info->mutex_};
addNewMultiplexedSocket(dinfo, deviceId, vid, info);
// Finally, open the channel and launch pending callbacks
lk.unlock();
// send beacon to existing connections for this device
if (config_->logger and not previousConnections.empty())
config_->logger->warn("[device {}] Sending beacon to {} existing connections",
deviceId,
previousConnections.size());
for (const auto& cinfo: previousConnections) {
std::lock_guard lk {cinfo->mutex_};
if (cinfo->socket_) {
cinfo->socket_->sendBeacon();
}
}
// Finally, launch pending callbacks
for (const auto& [id, name]: pendingIds) {
if (config_->logger)
config_->logger->debug("[device {}] Send request on TLS socket for channel {}",
Expand Down

0 comments on commit aca437e

Please sign in to comment.