diff --git a/src/data_transfer.cpp b/src/data_transfer.cpp index f3c5221d5adb2dfe93bb0fd6e2cf2e658e7011e5..06c7055d17657bb46763c3ae9cbd6b4101731023 100644 --- a/src/data_transfer.cpp +++ b/src/data_transfer.cpp @@ -467,10 +467,12 @@ SubOutgoingFileTransfer::emit(DRing::DataTransferEventCode code) const if (code == DRing::DataTransferEventCode::wait_peer_acceptance) { if (timeoutTask_) timeoutTask_->cancel(); - timeoutTask_ = Manager::instance().scheduleTaskIn([this]() { - JAMI_WARN() << "FTP#" << getId() << ": timeout. Cancel"; - closeAndEmit(DRing::DataTransferEventCode::timeout_expired); - }, std::chrono::minutes(10)); + timeoutTask_ = Manager::instance().scheduleTaskIn( + [this]() { + JAMI_WARN() << "FTP#" << getId() << ": timeout. Cancel"; + closeAndEmit(DRing::DataTransferEventCode::timeout_expired); + }, + std::chrono::minutes(10)); } else if (timeoutTask_) { timeoutTask_->cancel(); timeoutTask_.reset(); @@ -818,7 +820,7 @@ DataTransferFacade::sendFile(const DRing::DataTransferInfo& info, out->linkTransfer(std::dynamic_pointer_cast<OutgoingFileTransfer>(transfer) ->startNewOutgoing(out->peer())); }, - [this, tid]() { + [this, tid](const std::string& device) { if (auto transfer = pimpl_->getTransfer(tid)) if (not transfer->hasBeenStarted()) { transfer->emit(DRing::DataTransferEventCode::unjoinable_peer); diff --git a/src/jamidht/connectionmanager.cpp b/src/jamidht/connectionmanager.cpp index 84d64fb46a8f766b01b5df1fe845ac925bdb0e05..686a9eca1068307ec8723dafda0f7bf29b728212 100644 --- a/src/jamidht/connectionmanager.cpp +++ b/src/jamidht/connectionmanager.cpp @@ -235,7 +235,7 @@ ConnectionManager::Impl::connectDeviceStartIce(const DeviceId& deviceId, const d auto onError = [&]() { ice.reset(); if (auto cb = getPendingCallback({deviceId, vid})) - cb(nullptr); + cb(nullptr, deviceId); }; if (!ice) { @@ -310,7 +310,7 @@ ConnectionManager::Impl::connectDeviceOnNegoDone( if (!ice || !ice->isRunning()) { JAMI_ERR("No ICE detected or not running"); if (auto cb = getPendingCallback({deviceId, vid})) - cb(nullptr); + cb(nullptr, deviceId); return; } @@ -338,7 +338,7 @@ ConnectionManager::Impl::connectDeviceOnNegoDone( if (!ok) { JAMI_ERR() << "TLS connection failure for peer " << deviceId; if (auto cb = sthis->getPendingCallback({deviceId, vid})) - cb(nullptr); + cb(nullptr, deviceId); } else { // The socket is ready, store it sthis->addNewMultiplexedSocket(deviceId, vid); @@ -355,7 +355,7 @@ ConnectionManager::Impl::connectDevice(const DeviceId& deviceId, ConnectCallback cb) { if (!account.dht()) { - cb(nullptr); + cb(nullptr, deviceId); return; } account.findCertificate( @@ -364,7 +364,7 @@ ConnectionManager::Impl::connectDevice(const DeviceId& deviceId, const std::shared_ptr<dht::crypto::Certificate>& cert) { if (!cert) { JAMI_ERR("Invalid certificate found for device %s", deviceId.to_c_str()); - cb(nullptr); + cb(nullptr, deviceId); return; } @@ -376,7 +376,7 @@ ConnectionManager::Impl::connectDevice(const DeviceId& deviceId, cb = std::move(cb)] { auto sthis = w.lock(); if (!sthis || sthis->isDestroying_) { - cb(nullptr); + cb(nullptr, deviceId); return; } auto vid = ValueIdDist()(sthis->account.rand); @@ -418,7 +418,7 @@ ConnectionManager::Impl::connectDevice(const DeviceId& deviceId, if (!ok) { JAMI_ERR("Cannot initialize ICE session."); if (auto cb = sthis->getPendingCallback(cbId)) - cb(nullptr); + cb(nullptr, deviceId); return; } @@ -440,7 +440,7 @@ ConnectionManager::Impl::connectDevice(const DeviceId& deviceId, if (!ok) { JAMI_ERR("ICE negotiation failed."); if (auto cb = sthis->getPendingCallback(cbId)) - cb(nullptr); + cb(nullptr, deviceId); return; } @@ -471,7 +471,7 @@ ConnectionManager::Impl::connectDevice(const DeviceId& deviceId, if (!info->ice_) { JAMI_ERR("Cannot initialize ICE session."); if (auto cb = sthis->getPendingCallback(cbId)) - cb(nullptr); + cb(nullptr, deviceId); return; } }); @@ -495,7 +495,7 @@ ConnectionManager::Impl::sendChannelRequest(std::shared_ptr<MultiplexedSocket>& sock->setOnChannelReady(channelSock->channel(), [channelSock, deviceId, vid, w = weak()]() { if (auto shared = w.lock()) { if (auto cb = shared->getPendingCallback({deviceId, vid})) - cb(channelSock); + cb(channelSock, deviceId); } }); std::error_code ec; @@ -812,7 +812,7 @@ ConnectionManager::Impl::addNewMultiplexedSocket(const DeviceId& deviceId, const } for (const auto& cbId : ids) { if (auto cb = sthis->getPendingCallback(cbId)) { - cb(nullptr); + cb(nullptr, deviceId); } } @@ -849,7 +849,7 @@ ConnectionManager::closeConnectionsWith(const DeviceId& deviceId) while (it != pimpl_->pendingCbs_.end()) { if (it->first.first == deviceId) { if (it->second) - it->second(nullptr); + it->second(nullptr, deviceId); it = pimpl_->pendingCbs_.erase(it); } else { ++it; diff --git a/src/jamidht/connectionmanager.h b/src/jamidht/connectionmanager.h index f54b041240f6924bbbb919124f8c82a0c56d8da9..112743b9049834e43f0cec2f26158519e2eb7dae 100644 --- a/src/jamidht/connectionmanager.h +++ b/src/jamidht/connectionmanager.h @@ -52,22 +52,20 @@ struct PeerConnectionRequest : public dht::EncryptedValue<PeerConnectionRequest> /** * Used to accept or not an incoming ICE connection (default accept) */ -using onICERequestCallback = std::function<bool(const dht::InfoHash& /* deviceId */)>; +using onICERequestCallback = std::function<bool(const DeviceId&)>; /** * Used to accept or decline an incoming channel request */ -using ChannelRequestCallback - = std::function<bool(const dht::InfoHash& /* deviceId */, const std::string& /* name */)>; +using ChannelRequestCallback = std::function<bool(const DeviceId&, const std::string& /* name */)>; /** * Used by connectDevice, when the socket is ready */ -using ConnectCallback = std::function<void(const std::shared_ptr<ChannelSocket>&)>; +using ConnectCallback = std::function<void(const std::shared_ptr<ChannelSocket>&, const DeviceId&)>; /** * Used when an incoming connection is ready */ -using ConnectionReadyCallback = std::function<void(const dht::InfoHash& /* deviceId */, - const std::string& /* channel_name */, - std::shared_ptr<ChannelSocket>)>; +using ConnectionReadyCallback = std::function< + void(const DeviceId&, const std::string& /* channel_name */, std::shared_ptr<ChannelSocket>)>; /** * Manages connections to other devices diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index c9169b5cdce3cb9578c0575bde19ee7c0404b606..141f690e9614f791c7a9fa55da582e44c7576f4c 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -2189,25 +2189,24 @@ JamiAccount::doRegister_() auto result = fut.get(); return result; }); - connectionManager_->onChannelRequest( - [this](const DeviceId& /* deviceId */, const std::string& name) { - auto isFile = name.substr(0, 7) == "file://"; - auto isVCard = name.substr(0, 8) == "vcard://"; - if (name == "sip") { + connectionManager_->onChannelRequest([this](const DeviceId&, const std::string& name) { + auto isFile = name.substr(0, 7) == "file://"; + auto isVCard = name.substr(0, 8) == "vcard://"; + if (name == "sip") { + return true; + } else if (isFile or isVCard) { + auto tid_str = isFile ? name.substr(7) : name.substr(8); + uint64_t tid; + std::istringstream iss(tid_str); + iss >> tid; + if (dhtPeerConnector_->onIncomingChannelRequest(tid)) { + std::lock_guard<std::mutex> lk(transfersMtx_); + incomingFileTransfers_.emplace(tid_str); return true; - } else if (isFile or isVCard) { - auto tid_str = isFile ? name.substr(7) : name.substr(8); - uint64_t tid; - std::istringstream iss(tid_str); - iss >> tid; - if (dhtPeerConnector_->onIncomingChannelRequest(tid)) { - std::lock_guard<std::mutex> lk(transfersMtx_); - incomingFileTransfers_.emplace(tid_str); - return true; - } } - return false; - }); + } + return false; + }); connectionManager_->onConnectionReady([this](const DeviceId& deviceId, const std::string& name, std::shared_ptr<ChannelSocket> channel) { @@ -2461,7 +2460,8 @@ JamiAccount::replyToIncomingIceMsg(const std::shared_ptr<SIPCall>& call, [w = weak(), callId = call->getCallId()]() { if (auto shared = w.lock()) shared->checkPendingCall(callId); - }, ICE_NEGOTIATION_TIMEOUT); + }, + ICE_NEGOTIATION_TIMEOUT); } void @@ -3234,7 +3234,8 @@ JamiAccount::sendTextMessage(const std::string& to, this_->messageEngine_.onMessageSent(to, token, false); } } - }, std::chrono::minutes(1)); + }, + std::chrono::minutes(1)); } void @@ -3298,10 +3299,10 @@ JamiAccount::requestPeerConnection( bool isVCard, const std::function<void(const std::shared_ptr<ChanneledOutgoingTransfer>&)>& channeledConnectedCb, - const std::function<void()>& onChanneledCancelled) + const std::function<void(const std::string&)>& onChanneledCancelled) { if (not dhtPeerConnector_) { - runOnMainThread([onChanneledCancelled] { onChanneledCancelled(); }); + runOnMainThread([onChanneledCancelled, peer_id] { onChanneledCancelled(peer_id); }); return; } dhtPeerConnector_->requestConnection(peer_id, @@ -3540,29 +3541,34 @@ JamiAccount::requestSIPConnection(const std::string& peerId, const DeviceId& dev JAMI_INFO("Ask %s for a new SIP channel", deviceId.to_c_str()); if (!connectionManager_) return; - connectionManager_ - ->connectDevice(deviceId, "sip", [w = weak(), id](std::shared_ptr<ChannelSocket> socket) { - auto shared = w.lock(); - if (!shared) - return; - // NOTE: No need to cache Connection there. - // OnConnectionReady is called before this callback, so - // the socket is already cached if succeed. We just need - // to remove the pending request. - if (!socket) { - // If this is triggered, this means that the connectDevice - // didn't get any response from the DHT. - // Stop searching pending call. - shared->callConnectionClosed(id.second, true); - shared->forEachPendingCall(id.second, [](const auto& pc) { pc->onFailure(); }); - } - - std::lock_guard<std::mutex> lk(shared->sipConnsMtx_); - auto it = shared->sipConns_.find(id); - if (it != shared->sipConns_.end() && it->second.empty()) { - shared->sipConns_.erase(it); - } - }); + connectionManager_->connectDevice(deviceId, + "sip", + [w = weak(), id](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { + auto shared = w.lock(); + if (!shared) + return; + // NOTE: No need to cache Connection there. + // OnConnectionReady is called before this callback, so + // the socket is already cached if succeed. We just need + // to remove the pending request. + if (!socket) { + // If this is triggered, this means that the + // connectDevice didn't get any response from the DHT. + // Stop searching pending call. + shared->callConnectionClosed(id.second, true); + shared->forEachPendingCall(id.second, + [](const auto& pc) { + pc->onFailure(); + }); + } + + std::lock_guard<std::mutex> lk(shared->sipConnsMtx_); + auto it = shared->sipConns_.find(id); + if (it != shared->sipConns_.end() && it->second.empty()) { + shared->sipConns_.erase(it); + } + }); } bool @@ -3610,8 +3616,7 @@ JamiAccount::sendSIPMessage(SipConnection& conn, pjsip_tx_data* tdata; // Build SIP message - constexpr pjsip_method msg_method = {PJSIP_OTHER_METHOD, - sip_utils::CONST_PJ_STR("MESSAGE")}; + constexpr pjsip_method msg_method = {PJSIP_OTHER_METHOD, sip_utils::CONST_PJ_STR("MESSAGE")}; pj_str_t pjFrom = sip_utils::CONST_PJ_STR(from); pj_str_t pjTo = sip_utils::CONST_PJ_STR(toURI); diff --git a/src/jamidht/jamiaccount.h b/src/jamidht/jamiaccount.h index 2c7a97427bacf76ce7397ca2303c897ae5c779e0..1195892aca22f568840350cf25e1655c574a8b54 100644 --- a/src/jamidht/jamiaccount.h +++ b/src/jamidht/jamiaccount.h @@ -366,7 +366,7 @@ public: bool isVCard, const std::function<void(const std::shared_ptr<ChanneledOutgoingTransfer>&)>& channeledConnectedCb, - const std::function<void()>& onChanneledCancelled); + const std::function<void(const std::string&)>& onChanneledCancelled); /// /// Close a E2E connection between a given peer and a given transfer id. diff --git a/src/jamidht/p2p.cpp b/src/jamidht/p2p.cpp index 183c27a503e3199cbbe0c5436e5b02ee413419f9..01e57c519881cc9856e53831e5172cac5d437902 100644 --- a/src/jamidht/p2p.cpp +++ b/src/jamidht/p2p.cpp @@ -186,7 +186,7 @@ DhtPeerConnector::requestConnection( bool isVCard, const std::function<void(const std::shared_ptr<ChanneledOutgoingTransfer>&)>& channeledConnectedCb, - const std::function<void()>& onChanneledCancelled) + const std::function<void(const std::string&)>& onChanneledCancelled) { auto acc = pimpl_->account.lock(); if (!acc) @@ -194,11 +194,15 @@ DhtPeerConnector::requestConnection( const auto peer_h = dht::InfoHash(peer_id); - auto channelReadyCb = [this, tid, peer_id, channeledConnectedCb, onChanneledCancelled]( - const std::shared_ptr<ChannelSocket>& channel) { + auto channelReadyCb = [this, + tid, + peer_id, + channeledConnectedCb, + onChanneledCancelled](const std::shared_ptr<ChannelSocket>& channel, + const DeviceId&) { auto shared = pimpl_->account.lock(); if (!channel) { - onChanneledCancelled(); + onChanneledCancelled(""); return; } if (!shared) @@ -219,7 +223,7 @@ DhtPeerConnector::requestConnection( channel->onShutdown([this, tid, onChanneledCancelled, peer = outgoingFile->peer()]() { JAMI_INFO("Channel down for outgoing transfer with id(%lu)", tid); - onChanneledCancelled(); + onChanneledCancelled(""); dht::ThreadPool::io().run([w = pimpl_->weak(), tid, peer] { auto shared = w.lock(); if (!shared) @@ -284,7 +288,7 @@ DhtPeerConnector::requestConnection( [peer_h, onChanneledCancelled, accId = acc->getAccountID()](bool found) { if (!found) { JAMI_WARN() << accId << "[CNX] aborted, no devices for " << peer_h; - onChanneledCancelled(); + onChanneledCancelled(""); } }); } diff --git a/src/jamidht/p2p.h b/src/jamidht/p2p.h index cde1191ccca4914f9244ffd2dfd088c20fefc0d4..6ba4b2384d62a0e5650fa4cb7de96eda43db9a6e 100644 --- a/src/jamidht/p2p.h +++ b/src/jamidht/p2p.h @@ -45,7 +45,7 @@ public: bool isVCard, const std::function<void(const std::shared_ptr<ChanneledOutgoingTransfer>&)>& channeledConnectedCb, - const std::function<void()>& onChanneledCancelled); + const std::function<void(const std::string&)>& onChanneledCancelled); void closeConnection(const DRing::DataTransferId& tid); bool onIncomingChannelRequest(const DRing::DataTransferId& tid); void onIncomingConnection(const std::string& peer_id, diff --git a/test/unitTest/call/call.cpp b/test/unitTest/call/call.cpp index 857e075adba1ad6960346af11b3c39fa2558b237..b0a56cd0b0b0649ce96781940d626f13df50f696 100644 --- a/test/unitTest/call/call.cpp +++ b/test/unitTest/call/call.cpp @@ -228,14 +228,15 @@ CallTest::testCachedCall() DRing::registerSignalHandlers(confHandlers); JAMI_INFO("Connect Alice's device and Bob's device"); - aliceAccount->connectionManager().connectDevice(bobDeviceId, - "sip", - [&cv, &successfullyConnected]( - std::shared_ptr<ChannelSocket> socket) { - if (socket) - successfullyConnected = true; - cv.notify_one(); - }); + aliceAccount->connectionManager() + .connectDevice(bobDeviceId, + "sip", + [&cv, &successfullyConnected](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { + if (socket) + successfullyConnected = true; + cv.notify_one(); + }); CPPUNIT_ASSERT( cv.wait_for(lk, std::chrono::seconds(30), [&] { return successfullyConnected.load(); })); diff --git a/test/unitTest/connectionManager/connectionManager.cpp b/test/unitTest/connectionManager/connectionManager.cpp index 4c680fbc9a4c2311836a1074137a936ad97d7871..2bea90b5522b2fe8c4cf9d07073f05dc8e034594 100644 --- a/test/unitTest/connectionManager/connectionManager.cpp +++ b/test/unitTest/connectionManager/connectionManager.cpp @@ -184,15 +184,16 @@ ConnectionManagerTest::testConnectDevice() return true; }); - aliceAccount->connectionManager().connectDevice(bobDeviceId, - "git://*", - [&cv, &successfullyConnected]( - std::shared_ptr<ChannelSocket> socket) { - if (socket) { - successfullyConnected = true; - } - cv.notify_one(); - }); + aliceAccount->connectionManager() + .connectDevice(bobDeviceId, + "git://*", + [&cv, &successfullyConnected](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { + if (socket) { + successfullyConnected = true; + } + cv.notify_one(); + }); CPPUNIT_ASSERT( cvReceive.wait_for(lk, std::chrono::seconds(60), [&] { return successfullyReceive; })); CPPUNIT_ASSERT(cv.wait_for(lk, std::chrono::seconds(60), [&] { return successfullyConnected; })); @@ -228,15 +229,16 @@ ConnectionManagerTest::testAcceptConnection() receiverConnected = socket && (name == "git://*"); }); - aliceAccount->connectionManager().connectDevice(bobDeviceId, - "git://*", - [&cv, &successfullyConnected]( - std::shared_ptr<ChannelSocket> socket) { - if (socket) { - successfullyConnected = true; - } - cv.notify_one(); - }); + aliceAccount->connectionManager() + .connectDevice(bobDeviceId, + "git://*", + [&cv, &successfullyConnected](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { + if (socket) { + successfullyConnected = true; + } + cv.notify_one(); + }); CPPUNIT_ASSERT(cv.wait_for(lk, std::chrono::seconds(60), [&] { return successfullyReceive && successfullyConnected && receiverConnected; @@ -271,25 +273,27 @@ ConnectionManagerTest::testMultipleChannels() receiverConnected += 1; }); - aliceAccount->connectionManager().connectDevice(bobDeviceId, - "git://*", - [&cv, &successfullyConnected]( - std::shared_ptr<ChannelSocket> socket) { - if (socket) { - successfullyConnected = true; - } - cv.notify_one(); - }); - - aliceAccount->connectionManager().connectDevice(bobDeviceId, - "sip://*", - [&cv, &successfullyConnected2]( - std::shared_ptr<ChannelSocket> socket) { - if (socket) { - successfullyConnected2 = true; - } - cv.notify_one(); - }); + aliceAccount->connectionManager() + .connectDevice(bobDeviceId, + "git://*", + [&cv, &successfullyConnected](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { + if (socket) { + successfullyConnected = true; + } + cv.notify_one(); + }); + + aliceAccount->connectionManager() + .connectDevice(bobDeviceId, + "sip://*", + [&cv, &successfullyConnected2](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { + if (socket) { + successfullyConnected2 = true; + } + cv.notify_one(); + }); CPPUNIT_ASSERT(cv.wait_for(lk, std::chrono::seconds(60), [&] { return successfullyConnected && successfullyConnected2 && receiverConnected == 2; @@ -324,26 +328,28 @@ ConnectionManagerTest::testMultipleChannelsSameName() receiverConnected += 1; }); - aliceAccount->connectionManager().connectDevice(bobDeviceId, - "git://*", - [&cv, &successfullyConnected]( - std::shared_ptr<ChannelSocket> socket) { - if (socket) { - successfullyConnected = true; - } - cv.notify_one(); - }); + aliceAccount->connectionManager() + .connectDevice(bobDeviceId, + "git://*", + [&cv, &successfullyConnected](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { + if (socket) { + successfullyConnected = true; + } + cv.notify_one(); + }); // We can open two sockets with the same name, it will be two different channel - aliceAccount->connectionManager().connectDevice(bobDeviceId, - "git://*", - [&cv, &successfullyConnected2]( - std::shared_ptr<ChannelSocket> socket) { - if (socket) { - successfullyConnected2 = true; - } - cv.notify_one(); - }); + aliceAccount->connectionManager() + .connectDevice(bobDeviceId, + "git://*", + [&cv, &successfullyConnected2](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { + if (socket) { + successfullyConnected2 = true; + } + cv.notify_one(); + }); CPPUNIT_ASSERT(cv.wait_for(lk, std::chrono::seconds(60), [&] { return successfullyConnected && successfullyConnected2 && receiverConnected == 2; @@ -397,7 +403,8 @@ ConnectionManagerTest::testSendReceiveData() aliceAccount->connectionManager().connectDevice(bobDeviceId, "test", - [&](std::shared_ptr<ChannelSocket> socket) { + [&](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { if (socket) { successfullyConnected = true; std::error_code ec; @@ -409,7 +416,8 @@ ConnectionManagerTest::testSendReceiveData() aliceAccount->connectionManager().connectDevice(bobDeviceId, "other", - [&](std::shared_ptr<ChannelSocket> socket) { + [&](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { if (socket) { successfullyConnected2 = true; std::error_code ec; @@ -456,15 +464,16 @@ ConnectionManagerTest::testDeclineConnection() receiverConnected = true; }); - aliceAccount->connectionManager().connectDevice(bobDeviceId, - "git://*", - [&cv, &successfullyConnected]( - std::shared_ptr<ChannelSocket> socket) { - if (socket) { - successfullyConnected = true; - } - cv.notify_one(); - }); + aliceAccount->connectionManager() + .connectDevice(bobDeviceId, + "git://*", + [&cv, &successfullyConnected](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { + if (socket) { + successfullyConnected = true; + } + cv.notify_one(); + }); cv.wait_for(lk, std::chrono::seconds(30)); CPPUNIT_ASSERT(successfullyReceive); CPPUNIT_ASSERT(!successfullyConnected); @@ -501,15 +510,16 @@ ConnectionManagerTest::testAcceptsICERequest() receiverConnected = socket && (name == "git://*"); }); - aliceAccount->connectionManager().connectDevice(bobDeviceId, - "git://*", - [&cv, &successfullyConnected]( - std::shared_ptr<ChannelSocket> socket) { - if (socket) { - successfullyConnected = true; - } - cv.notify_one(); - }); + aliceAccount->connectionManager() + .connectDevice(bobDeviceId, + "git://*", + [&cv, &successfullyConnected](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { + if (socket) { + successfullyConnected = true; + } + cv.notify_one(); + }); CPPUNIT_ASSERT(cv.wait_for(lk, std::chrono::seconds(30), [&] { return successfullyReceive && successfullyConnected && receiverConnected; @@ -546,15 +556,16 @@ ConnectionManagerTest::testDeclineICERequest() receiverConnected = socket && (name == "git://*"); }); - aliceAccount->connectionManager().connectDevice(bobDeviceId, - "git://*", - [&cv, &successfullyConnected]( - std::shared_ptr<ChannelSocket> socket) { - if (socket) { - successfullyConnected = true; - } - cv.notify_one(); - }); + aliceAccount->connectionManager() + .connectDevice(bobDeviceId, + "git://*", + [&cv, &successfullyConnected](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { + if (socket) { + successfullyConnected = true; + } + cv.notify_one(); + }); cv.wait_for(lk, std::chrono::seconds(30)); CPPUNIT_ASSERT(successfullyReceive); @@ -595,7 +606,8 @@ ConnectionManagerTest::testChannelRcvShutdown() aliceAccount->connectionManager().connectDevice(bobDeviceId, "git://*", - [&](std::shared_ptr<ChannelSocket> socket) { + [&](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { if (socket) { socket->onShutdown([&] { shutdownReceived = true; @@ -650,7 +662,8 @@ ConnectionManagerTest::testChannelSenderShutdown() aliceAccount->connectionManager().connectDevice(bobDeviceId, "git://*", - [&](std::shared_ptr<ChannelSocket> socket) { + [&](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { if (socket) { successfullyConnected = true; rcv.notify_one(); @@ -703,7 +716,8 @@ ConnectionManagerTest::testCloseConnectionWithDevice() aliceAccount->connectionManager().connectDevice(bobDeviceId, "git://*", - [&](std::shared_ptr<ChannelSocket> socket) { + [&](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { if (socket) { socket->onShutdown([&] { events += 1; @@ -759,7 +773,8 @@ ConnectionManagerTest::testShutdownCallbacks() aliceAccount->connectionManager().connectDevice(bobDeviceId, "1", - [&](std::shared_ptr<ChannelSocket> socket) { + [&](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { if (socket) { successfullyConnected = true; rcv.notify_one(); @@ -774,7 +789,8 @@ ConnectionManagerTest::testShutdownCallbacks() bool channel2NotConnected = false; aliceAccount->connectionManager().connectDevice(bobDeviceId, "2", - [&](std::shared_ptr<ChannelSocket> socket) { + [&](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { channel2NotConnected = !socket; rcv.notify_one(); }); @@ -817,7 +833,8 @@ ConnectionManagerTest::testFloodSocket() }); aliceAccount->connectionManager().connectDevice(bobDeviceId, "1", - [&](std::shared_ptr<ChannelSocket> socket) { + [&](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { if (socket) { sendSock = socket; successfullyConnected = true; @@ -832,7 +849,8 @@ ConnectionManagerTest::testFloodSocket() receiverConnected = false; aliceAccount->connectionManager().connectDevice(bobDeviceId, "2", - [&](std::shared_ptr<ChannelSocket> socket) { + [&](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { if (socket) { sendSock2 = socket; successfullyConnected = true; @@ -846,7 +864,8 @@ ConnectionManagerTest::testFloodSocket() receiverConnected = false; aliceAccount->connectionManager().connectDevice(bobDeviceId, "3", - [&](std::shared_ptr<ChannelSocket> socket) { + [&](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { if (socket) { sendSock3 = socket; successfullyConnected = true; @@ -920,7 +939,8 @@ ConnectionManagerTest::testDestroyWhileSending() }); aliceAccount->connectionManager().connectDevice(bobDeviceId, "1", - [&](std::shared_ptr<ChannelSocket> socket) { + [&](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { if (socket) { sendSock = socket; successfullyConnected = true; @@ -934,7 +954,8 @@ ConnectionManagerTest::testDestroyWhileSending() receiverConnected = false; aliceAccount->connectionManager().connectDevice(bobDeviceId, "2", - [&](std::shared_ptr<ChannelSocket> socket) { + [&](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { if (socket) { sendSock2 = socket; successfullyConnected = true; @@ -948,7 +969,8 @@ ConnectionManagerTest::testDestroyWhileSending() receiverConnected = false; aliceAccount->connectionManager().connectDevice(bobDeviceId, "3", - [&](std::shared_ptr<ChannelSocket> socket) { + [&](std::shared_ptr<ChannelSocket> socket, + const DeviceId&) { if (socket) { sendSock3 = socket; successfullyConnected = true; @@ -962,9 +984,9 @@ ConnectionManagerTest::testDestroyWhileSending() std::string alphabet; for (int i = 0; i < 100; ++i) alphabet += "QWERTYUIOPASDFGHJKLZXCVBNM"; - rcvSock1->setOnRecv([&](const uint8_t* buf, size_t len) { return len; }); - rcvSock2->setOnRecv([&](const uint8_t* buf, size_t len) { return len; }); - rcvSock3->setOnRecv([&](const uint8_t* buf, size_t len) { return len; }); + rcvSock1->setOnRecv([&](const uint8_t*, size_t len) { return len; }); + rcvSock2->setOnRecv([&](const uint8_t*, size_t len) { return len; }); + rcvSock3->setOnRecv([&](const uint8_t*, size_t len) { return len; }); for (uint64_t i = 0; i < alphabet.size(); ++i) { auto send = std::string(8000, alphabet[i]); std::error_code ec;