diff --git a/src/ringdht/p2p.cpp b/src/ringdht/p2p.cpp index 049acdf488e2073f6cb3db8210f92f7a1b32786d..6f6e09633143edd9c274140f7f2e4f3b3f96aa4c 100644 --- a/src/ringdht/p2p.cpp +++ b/src/ringdht/p2p.cpp @@ -743,9 +743,9 @@ DhtPeerConnector::requestConnection(const std::string& peer_id, }); }, - [this, peer_h, connect_cb](bool found) { + [this, peer_h, connect_cb](const std::shared_ptr<RingAccount>& account, bool found) { if (!found) { - RING_WARN() << pimpl_->account << "[CNX] aborted, no devices for " << peer_h; + RING_WARN() << account << "[CNX] aborted, no devices for " << peer_h; connect_cb(nullptr); } }); @@ -775,9 +775,9 @@ DhtPeerConnector::closeConnection(const std::string& peer_id, const DRing::DataT pimpl_->ctrl << makeMsg<CtrlMsgType::CANCEL>(dev_h, tid); }, - [this, peer_h](bool found) { + [peer_h](const std::shared_ptr<RingAccount>& account, bool found) { if (!found) { - RING_WARN() << pimpl_->account << "[CNX] aborted, no devices for " << peer_h; + RING_WARN() << account << "[CNX] aborted, no devices for " << peer_h; } }); } diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp index cc44b0343c5d3df8cd8f60fecbece4a65bc2b2b8..110b9c4b644665da808bdc592a72a1a49f4d15bc 100644 --- a/src/ringdht/ringaccount.cpp +++ b/src/ringdht/ringaccount.cpp @@ -490,7 +490,7 @@ RingAccount::startOutgoingCall(const std::shared_ptr<SIPCall>& call, const std:: }); return false; }); - }, [=](bool ok){ + }, [wCall](const std::shared_ptr<RingAccount>& sthis, bool ok){ if (not ok) { if (auto call = wCall.lock()) { RING_WARN("[call:%s] no devices found", call->getCallId().c_str()); @@ -1956,20 +1956,18 @@ RingAccount::trackBuddyPresence(const std::string& buddy_id) buddy_info.updateInfo = Manager::instance().scheduleTask([h,weak_this]() { if (auto shared_this = weak_this.lock()) { /* ::forEachDevice call will update buddy info accordingly. */ - shared_this->forEachDevice(h, {}, [h, weak_this] (bool /* ok */) { - if (auto shared_this = weak_this.lock()) { - std::lock_guard<std::recursive_mutex> lock(shared_this->buddyInfoMtx); - auto buddy_info_it = shared_this->trackedBuddies_.find(h); - if (buddy_info_it == shared_this->trackedBuddies_.end()) return; - - auto& buddy_info = buddy_info_it->second; - if (buddy_info.updateInfo) { - auto cb = buddy_info.updateInfo; - Manager::instance().scheduleTask( - std::move(cb), - std::chrono::steady_clock::now() + DeviceAnnouncement::TYPE.expiration - ); - } + shared_this->forEachDevice(h, {}, [h] (const std::shared_ptr<RingAccount>& shared_this, bool /* ok */) { + std::lock_guard<std::recursive_mutex> lock(shared_this->buddyInfoMtx); + auto buddy_info_it = shared_this->trackedBuddies_.find(h); + if (buddy_info_it == shared_this->trackedBuddies_.end()) return; + + auto& buddy_info = buddy_info_it->second; + if (buddy_info.updateInfo) { + auto cb = buddy_info.updateInfo; + Manager::instance().scheduleTask( + std::move(cb), + std::chrono::steady_clock::now() + DeviceAnnouncement::TYPE.expiration + ); } }); } @@ -2092,8 +2090,10 @@ RingAccount::doRegister_() if (not config.proxy_server.empty()) RING_WARN("[Account %s] using proxy server %s", getAccountID().c_str(), config.proxy_server.c_str()); - if (not deviceKey_.empty()) + if (not deviceKey_.empty()) { + RING_WARN("[Account %s] using push notifications", getAccountID().c_str()); dht_.setPushNotificationToken(deviceKey_); + } dht_.run((in_port_t)dhtPortUsed_, config); @@ -3233,7 +3233,7 @@ void RingAccount::forEachDevice(const dht::InfoHash& to, std::function<void(const std::shared_ptr<RingAccount>&, const dht::InfoHash&)> op, - std::function<void(bool)> end) + std::function<void(const std::shared_ptr<RingAccount>&, bool)> end) { auto shared = std::static_pointer_cast<RingAccount>(shared_from_this()); auto treatedDevices = std::make_shared<std::set<dht::InfoHash>>(); @@ -3261,7 +3261,7 @@ RingAccount::forEachDevice(const dht::InfoHash& to, } RING_DBG("[Account %s] found %lu devices for %s", getAccountID().c_str(), treatedDevices->size(), to.to_c_str()); - if (end) end(not treatedDevices->empty()); + if (end) end(shared, not treatedDevices->empty()); }); } @@ -3357,6 +3357,10 @@ RingAccount::sendTextMessage(const std::string& to, const std::map<std::string, }); RING_DBG("[Account %s] [message %" PRIx64 "] sending message for device %s", shared->getAccountID().c_str(), token, dev.toString().c_str()); + }, [token](const std::shared_ptr<RingAccount>& shared, bool ok) { + if (not ok) { + shared->messageEngine_.onMessageSent(token, false); + } }); // Timeout cleanup diff --git a/src/ringdht/ringaccount.h b/src/ringdht/ringaccount.h index 455b97d29e02168f46add1a3ae54fddfd2e014df..5d9c8907ab51c50cbcabff171bda7f6127c214ec 100644 --- a/src/ringdht/ringaccount.h +++ b/src/ringdht/ringaccount.h @@ -352,7 +352,8 @@ class RingAccount : public SIPAccountBase { void forEachDevice(const dht::InfoHash& to, std::function<void(const std::shared_ptr<RingAccount>&, const dht::InfoHash&)> op, - std::function<void(bool)> end = {}); + std::function<void(const std::shared_ptr<RingAccount>&, + bool)> end = {}); /** * Inform that a potential peer device have been found.