Also handle loopback connections in bearer management
This commit is contained in:
parent
ab2f247c76
commit
3e2f82e5a6
@ -124,6 +124,10 @@ void NymeaDiscovery::cacheHost(NymeaHost *host)
|
||||
if (remoteConnection) {
|
||||
connections.append(remoteConnection);
|
||||
}
|
||||
Connection *loopbackConnection = host->connections()->bestMatch(Connection::BearerTypeLoopback);
|
||||
if (loopbackConnection) {
|
||||
connections.append(loopbackConnection);
|
||||
}
|
||||
Connection *lanConnection = host->connections()->bestMatch(Connection::BearerTypeLan);
|
||||
if (lanConnection) {
|
||||
connections.append(lanConnection);
|
||||
|
||||
@ -254,7 +254,8 @@ void UpnpDiscovery::networkReplyFinished(QNetworkReply *reply)
|
||||
qDebug() << "UPnP: Adding new connection to host:" << device->name() << url;
|
||||
bool sslEnabled = url.scheme() == "nymeas" || url.scheme() == "wss";
|
||||
QString displayName = QString("%1:%2").arg(url.host()).arg(url.port());
|
||||
Connection *conn = new Connection(url, Connection::BearerTypeLan, sslEnabled, displayName);
|
||||
Connection::BearerType bearerType = QHostAddress(url.host()).isLoopback() ? Connection::BearerTypeLoopback : Connection::BearerTypeLan;
|
||||
Connection *conn = new Connection(url, bearerType, sslEnabled, displayName);
|
||||
conn->setOnline(true);
|
||||
device->connections()->addConnection(conn);
|
||||
}
|
||||
|
||||
@ -126,7 +126,8 @@ void ZeroconfDiscovery::serviceEntryAdded(const QZeroConfService &entry)
|
||||
if (!connection) {
|
||||
// qDebug() << "Zeroconf: Adding new connection to host:" << host->name() << url.toString();
|
||||
QString displayName = QString("%1:%2").arg(url.host()).arg(url.port());
|
||||
connection = new Connection(url, Connection::BearerTypeLan, sslEnabled, displayName);
|
||||
Connection::BearerType bearerType = QHostAddress(url.host()).isLoopback() ? Connection::BearerTypeLoopback : Connection::BearerTypeLan;
|
||||
connection = new Connection(url, bearerType, sslEnabled, displayName);
|
||||
connection->setOnline(true);
|
||||
host->connections()->addConnection(connection);
|
||||
} else {
|
||||
|
||||
@ -387,10 +387,10 @@ void NymeaConnection::onDisconnected()
|
||||
void NymeaConnection::updateActiveBearers()
|
||||
{
|
||||
NymeaConnection::BearerTypes availableBearerTypes;
|
||||
QList<QNetworkConfiguration> configs = m_networkConfigManager->allConfigurations(QNetworkConfiguration::Active);
|
||||
// qDebug() << "Network configuations:" << configs.count();
|
||||
QList<QNetworkConfiguration> configs = m_networkConfigManager->allConfigurations();
|
||||
qDebug() << "Network configuations:" << configs.count();
|
||||
foreach (const QNetworkConfiguration &config, configs) {
|
||||
// qDebug() << "Candidate network config:" << config.name() << config.bearerTypeFamily() << config.bearerTypeName();
|
||||
qDebug() << "Candidate network config:" << config.name() << config.bearerTypeFamily() << config.bearerTypeName();
|
||||
|
||||
// NOTE: iOS doesn't correctly report bearer types. It'll be Unknown all the time. Let's hardcode it to WiFi for that...
|
||||
#if defined(Q_OS_IOS)
|
||||
@ -399,7 +399,6 @@ void NymeaConnection::updateActiveBearers()
|
||||
availableBearerTypes.setFlag(qBearerTypeToNymeaBearerType(config.bearerType()));
|
||||
#endif
|
||||
}
|
||||
// qDebug() << "Available bearers:" << availableBearerTypes;
|
||||
if (m_availableBearerTypes != availableBearerTypes) {
|
||||
qDebug() << "Available Bearer Types changed:" << availableBearerTypes;
|
||||
m_availableBearerTypes = availableBearerTypes;
|
||||
@ -487,21 +486,21 @@ void NymeaConnection::connect(NymeaHost *nymeaHost, Connection *connection)
|
||||
|
||||
void NymeaConnection::connectInternal(NymeaHost *host)
|
||||
{
|
||||
qDebug() << "Connecting. Available bearer types:" << m_availableBearerTypes;
|
||||
if (m_availableBearerTypes == NymeaConnection::BearerTypeNone) {
|
||||
qDebug() << "No available bearer. Not connecting...";
|
||||
m_connectionStatus = ConnectionStatusNoBearerAvailable;
|
||||
emit connectionStatusChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_preferredConnection) {
|
||||
qDebug() << "Preferred connection is set. Using" << m_preferredConnection->url();
|
||||
connectInternal(m_preferredConnection);
|
||||
return;
|
||||
if (isConnectionBearerAvailable(m_preferredConnection->bearerType())) {
|
||||
qDebug() << "Preferred connection is set. Using" << m_preferredConnection->url();
|
||||
connectInternal(m_preferredConnection);
|
||||
return;
|
||||
}
|
||||
qDebug() << "Preferred connection set but no bearer available for it.";
|
||||
}
|
||||
|
||||
if (m_availableBearerTypes.testFlag(NymeaConnection::BearerTypeWiFi)
|
||||
Connection *loopbackConnection = host->connections()->bestMatch(Connection::BearerTypeLoopback);
|
||||
if (loopbackConnection) {
|
||||
qDebug() << "Best candidate Loopback connection:" << loopbackConnection->url();
|
||||
connectInternal(loopbackConnection);
|
||||
|
||||
} else if (m_availableBearerTypes.testFlag(NymeaConnection::BearerTypeWiFi)
|
||||
|| m_availableBearerTypes.testFlag(NymeaConnection::BearerTypeEthernet)) {
|
||||
Connection* lanConnection = host->connections()->bestMatch(Connection::BearerTypeLan | Connection::BearerTypeWan);
|
||||
if (lanConnection) {
|
||||
@ -510,6 +509,7 @@ void NymeaConnection::connectInternal(NymeaHost *host)
|
||||
} else {
|
||||
qDebug() << "No available LAN/WAN connection to" << host->name();
|
||||
}
|
||||
|
||||
} else if (m_availableBearerTypes.testFlag(NymeaConnection::BearerTypeMobileData)) {
|
||||
Connection* wanConnection = host->connections()->bestMatch(Connection::BearerTypeWan);
|
||||
if (wanConnection) {
|
||||
@ -597,6 +597,27 @@ NymeaConnection::BearerType NymeaConnection::qBearerTypeToNymeaBearerType(QNetwo
|
||||
return BearerTypeAll;
|
||||
}
|
||||
|
||||
bool NymeaConnection::isConnectionBearerAvailable(Connection::BearerType connectionBearerType) const
|
||||
{
|
||||
switch (connectionBearerType) {
|
||||
case Connection::BearerTypeLan:
|
||||
return m_availableBearerTypes.testFlag(BearerTypeEthernet)
|
||||
|| m_availableBearerTypes.testFlag(BearerTypeWiFi);
|
||||
case Connection::BearerTypeWan:
|
||||
case Connection::BearerTypeCloud:
|
||||
return m_availableBearerTypes.testFlag(BearerTypeEthernet)
|
||||
|| m_availableBearerTypes.testFlag(BearerTypeWiFi)
|
||||
|| m_availableBearerTypes.testFlag(BearerTypeMobileData);
|
||||
case Connection::BearerTypeBluetooth:
|
||||
return m_availableBearerTypes.testFlag(BearerTypeBluetooth);
|
||||
case Connection::BearerTypeUnknown:
|
||||
return true;
|
||||
case Connection::BearerTypeNone:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void NymeaConnection::disconnect()
|
||||
{
|
||||
setCurrentHost(nullptr);
|
||||
|
||||
@ -98,6 +98,8 @@ private:
|
||||
|
||||
NymeaConnection::BearerType qBearerTypeToNymeaBearerType(QNetworkConfiguration::BearerType type) const;
|
||||
|
||||
bool isConnectionBearerAvailable(Connection::BearerType connectionBearerType) const;
|
||||
|
||||
private:
|
||||
ConnectionStatus m_connectionStatus = ConnectionStatusUnconnected;
|
||||
QNetworkConfigurationManager *m_networkConfigManager = nullptr;
|
||||
|
||||
@ -46,6 +46,7 @@ public:
|
||||
BearerTypeWan = 0x02,
|
||||
BearerTypeCloud = 0x04,
|
||||
BearerTypeBluetooth = 0x08,
|
||||
BearerTypeLoopback = 0x10,
|
||||
BearerTypeUnknown = 0xFF,
|
||||
BearerTypeAll = 0xFF
|
||||
};
|
||||
|
||||
@ -91,6 +91,9 @@ NymeaHost *NymeaHosts::createCloudHost(const QString &name, const QUrl &url)
|
||||
|
||||
NymeaHost *NymeaHosts::createLanHost(const QString &name, const QUrl &url)
|
||||
{
|
||||
if (QHostAddress(url.host()).isLoopback()) {
|
||||
return createHost(name, url, Connection::BearerTypeLoopback);
|
||||
}
|
||||
return createHost(name, url, Connection::BearerTypeLan);
|
||||
}
|
||||
|
||||
|
||||
@ -26,6 +26,8 @@ Page {
|
||||
return "../images/network-wifi.svg";
|
||||
case Connection.BearerTypeCloud:
|
||||
return "../images/cloud.svg"
|
||||
case Connection.BearerTypeLoopback:
|
||||
return "qrc:/styles/%1/logo.svg".arg(styleController.currentStyle)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user