Skip to content
Snippets Groups Projects
Commit 0cf544d4 authored by Amna Snene's avatar Amna Snene
Browse files

ConnectionManager: add connectDevice(InfoHash)

Change-Id: I5179a05b63b4576f468d76c00f1aa9fe3c2e4083
parent e5f2506a
Branches
No related tags found
No related merge requests found
......@@ -72,6 +72,8 @@ using ChannelRequestCallback = std::function<bool(const std::shared_ptr<dht::cry
* Used by connectDevice, when the socket is ready
*/
using ConnectCallback = std::function<void(const std::shared_ptr<ChannelSocket>&, const DeviceId&)>;
using ConnectCallbackLegacy = std::function<void(const std::shared_ptr<ChannelSocket>&, const dht::InfoHash&)>;
/**
* Used when an incoming connection is ready
*/
......@@ -111,6 +113,13 @@ public:
bool noNewSocket = false,
bool forceNewSocket = false,
const std::string& connType = "");
void connectDevice(const dht::InfoHash& deviceId,
const std::string& name,
ConnectCallbackLegacy cb,
bool noNewSocket = false,
bool forceNewSocket = false,
const std::string& connType = "");
void connectDevice(const std::shared_ptr<dht::crypto::Certificate>& cert,
const std::string& name,
ConnectCallback cb,
......
......@@ -148,6 +148,13 @@ public:
bool noNewSocket = false,
bool forceNewSocket = false,
const std::string& connType = "");
void connectDevice(const dht::InfoHash& deviceId,
const std::string& uri,
ConnectCallbackLegacy cb,
bool noNewSocket = false,
bool forceNewSocket = false,
const std::string& connType = "");
void connectDevice(const std::shared_ptr<dht::crypto::Certificate>& cert,
const std::string& name,
ConnectCallback cb,
......@@ -602,6 +609,53 @@ ConnectionManager::Impl::connectDevice(const DeviceId& deviceId,
});
}
void
ConnectionManager::Impl::connectDevice(const dht::InfoHash& deviceId,
const std::string& name,
ConnectCallbackLegacy cb,
bool noNewSocket,
bool forceNewSocket,
const std::string& connType)
{
if (!dht()) {
cb(nullptr, deviceId);
return;
}
if (deviceId.toString() == identity().second->getLongId().toString()) {
cb(nullptr, deviceId);
return;
}
findCertificate(deviceId,
[w = weak(),
deviceId,
name,
cb = std::move(cb),
noNewSocket,
forceNewSocket,
connType](const std::shared_ptr<dht::crypto::Certificate>& cert) {
if (!cert) {
if (auto shared = w.lock())
if (shared->config_->logger)
shared->config_->logger->error(
"No valid certificate found for device {}",
deviceId);
cb(nullptr, deviceId);
return;
}
if (auto shared = w.lock()) {
shared->connectDevice(cert,
name,
[cb, deviceId](const std::shared_ptr<ChannelSocket>& sock, const DeviceId& did){
cb(sock, deviceId);
},
noNewSocket,
forceNewSocket,
connType);
} else
cb(nullptr, deviceId);
});
}
void
ConnectionManager::Impl::connectDevice(const std::shared_ptr<dht::crypto::Certificate>& cert,
const std::string& name,
......@@ -1534,6 +1588,18 @@ ConnectionManager::connectDevice(const DeviceId& deviceId,
pimpl_->connectDevice(deviceId, name, std::move(cb), noNewSocket, forceNewSocket, connType);
}
void
ConnectionManager::connectDevice(const dht::InfoHash& deviceId,
const std::string& name,
ConnectCallbackLegacy cb,
bool noNewSocket,
bool forceNewSocket,
const std::string& connType)
{
pimpl_->connectDevice(deviceId, name, std::move(cb), noNewSocket, forceNewSocket, connType);
}
void
ConnectionManager::connectDevice(const std::shared_ptr<dht::crypto::Certificate>& cert,
const std::string& name,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment