mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
LED Device Features, Fixes and Refactoring (Resubmit PR855) (#875)
* Refactor LedDevices - Initial version * Small renamings * Add WLED as own device * Lpd8806 Remove open() method * remove dependency on Qt 5.10 * Lpd8806 Remove open() method * Update WS281x * Update WS2812SPI * Add writeBlack for WLED powerOff * WLED remove extra bracket * Allow different Nanoleaf panel numbering sequence (Feature req.#827) * build(deps): bump websocket-extensions from 0.1.3 to 0.1.4 in /docs (#826) * Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-node) from 0.1.3 to 0.1.4. - [Release notes](https://github.com/faye/websocket-extensions-node/releases) - [Changelog](https://github.com/faye/websocket-extensions-node/blob/master/CHANGELOG.md) - [Commits](https://github.com/faye/websocket-extensions-node/compare/0.1.3...0.1.4) * Fix typos * Nanoleaf clean-up * Yeelight support, generalize wizard elements * Update Yeelight to handle quota in music mode * Yeelight extend rage for extraTimeDarkness for testing * Clean-up - Add commentary, Remove development debug statements * Fix brightnessSwitchOffOnMinimum typo and default value * Yeelight support restoreOriginalState, additional Fixes * WLED - Remove UDP-Port, as it is not configurable * Fix merging issue * Remove QHostAddress::operator=(const QString&)' is deprecated * Windows compile errors and (Qt 5.15 deprecation) warnings * Fix order includes * LedDeviceFile Support Qt5.7 and greater * Windows compatibility and other Fixes * Fix Qt Version compatability * Rs232 - Resolve portname from unix /dev/ style, fix DMX sub-type support * Disable WLED Wizard Button (until Wizard is available) * Yeelight updates * Add wrong log-type as per #505 * Fixes and Clean-up after clang-tidy report * Fix udpe131 not enabled for generated CID * Change timer into dynamic for Qt Thread-Affinity * Hue clean-up and diyHue workaround * Updates after review feedback by m-seker * Add "chrono" includes
This commit is contained in:
@@ -12,6 +12,9 @@
|
||||
// Local Hyperion includes
|
||||
#include "ProviderUdpSSL.h"
|
||||
|
||||
const int MAX_RETRY = 5;
|
||||
const ushort MAX_PORT_SSL = 65535;
|
||||
|
||||
ProviderUdpSSL::ProviderUdpSSL()
|
||||
: LedDevice()
|
||||
, client_fd()
|
||||
@@ -29,16 +32,16 @@ ProviderUdpSSL::ProviderUdpSSL()
|
||||
, _server_name()
|
||||
, _psk()
|
||||
, _psk_identity()
|
||||
, _read_timeout(0)
|
||||
, _handshake_timeout_min(400)
|
||||
, _handshake_timeout_max(1000)
|
||||
, _read_timeout(STREAM_SSL_READ_TIMEOUT.count())
|
||||
, _handshake_timeout_min(STREAM_SSL_HANDSHAKE_TIMEOUT_MIN.count())
|
||||
, _handshake_timeout_max(STREAM_SSL_HANDSHAKE_TIMEOUT_MAX.count())
|
||||
, _handshake_attempts(5)
|
||||
, _retry_left(MAX_RETRY)
|
||||
, _stopConnection(true)
|
||||
, _debugStreamer(false)
|
||||
, _debugLevel(0)
|
||||
{
|
||||
_deviceReady = false;
|
||||
_isDeviceReady = false;
|
||||
_latchTime_ms = 1;
|
||||
}
|
||||
|
||||
@@ -48,114 +51,131 @@ ProviderUdpSSL::~ProviderUdpSSL()
|
||||
|
||||
bool ProviderUdpSSL::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
bool isInitOK = LedDevice::init(deviceConfig);
|
||||
bool isInitOK = false;
|
||||
|
||||
_debugStreamer = deviceConfig["debugStreamer"].toBool(false);
|
||||
_debugLevel = deviceConfig["debugLevel"].toString().toInt(0);
|
||||
|
||||
//PSK Pre Shared Key
|
||||
_psk = deviceConfig["psk"].toString();
|
||||
_psk_identity = deviceConfig["psk_identity"].toString();
|
||||
_port = deviceConfig["sslport"].toInt(2100);
|
||||
_server_name = deviceConfig["servername"].toString();
|
||||
|
||||
if( deviceConfig.contains("transport_type") ) _transport_type = deviceConfig["transport_type"].toString("DTLS");
|
||||
if( deviceConfig.contains("seed_custom") ) _custom = deviceConfig["seed_custom"].toString("dtls_client");
|
||||
if( deviceConfig.contains("retry_left") ) _retry_left = deviceConfig["retry_left"].toInt(MAX_RETRY);
|
||||
if( deviceConfig.contains("read_timeout") ) _read_timeout = deviceConfig["read_timeout"].toInt(0);
|
||||
if( deviceConfig.contains("hs_timeout_min") ) _handshake_timeout_min = deviceConfig["hs_timeout_min"].toInt(400);
|
||||
if( deviceConfig.contains("hs_timeout_max") ) _handshake_timeout_max = deviceConfig["hs_timeout_max"].toInt(1000);
|
||||
if( deviceConfig.contains("hs_attempts") ) _handshake_attempts = deviceConfig["hs_attempts"].toInt(5);
|
||||
|
||||
QString host = deviceConfig["host"].toString(_defaultHost);
|
||||
QStringList debugLevels = QStringList() << "No Debug" << "Error" << "State Change" << "Informational" << "Verbose";
|
||||
|
||||
configLog( "SSL Streamer Debug", "%s", ( _debugStreamer ) ? "yes" : "no" );
|
||||
configLog( "SSL DebugLevel", "[%d] %s", _debugLevel, QSTRING_CSTR( debugLevels[ _debugLevel ]) );
|
||||
|
||||
configLog( "SSL Servername", "%s", QSTRING_CSTR( _server_name ) );
|
||||
configLog( "SSL Host", "%s", QSTRING_CSTR( host ) );
|
||||
configLog( "SSL Port", "%d", _port );
|
||||
configLog( "PSK", "%s", QSTRING_CSTR( _psk ) );
|
||||
configLog( "PSK-Identity", "%s", QSTRING_CSTR( _psk_identity ) );
|
||||
configLog( "SSL Transport Type", "%s", QSTRING_CSTR( _transport_type ) );
|
||||
configLog( "SSL Seed Custom", "%s", QSTRING_CSTR( _custom ) );
|
||||
configLog( "SSL Retry Left", "%d", _retry_left );
|
||||
configLog( "SSL Read Timeout", "%d", _read_timeout );
|
||||
configLog( "SSL Handshake Timeout min", "%d", _handshake_timeout_min );
|
||||
configLog( "SSL Handshake Timeout max", "%d", _handshake_timeout_max );
|
||||
configLog( "SSL Handshake attempts", "%d", _handshake_attempts );
|
||||
|
||||
if ( _address.setAddress(host) )
|
||||
// Initialise sub-class
|
||||
if ( LedDevice::init(deviceConfig) )
|
||||
{
|
||||
Debug( _log, "Successfully parsed %s as an ip address.", QSTRING_CSTR( host ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug( _log, "Failed to parse [%s] as an ip address.", QSTRING_CSTR( host ) );
|
||||
QHostInfo info = QHostInfo::fromName(host);
|
||||
if ( info.addresses().isEmpty() )
|
||||
_debugStreamer = deviceConfig["debugStreamer"].toBool(false);
|
||||
_debugLevel = deviceConfig["debugLevel"].toString().toInt(0);
|
||||
|
||||
//PSK Pre Shared Key
|
||||
_psk = deviceConfig["psk"].toString();
|
||||
_psk_identity = deviceConfig["psk_identity"].toString();
|
||||
_port = deviceConfig["sslport"].toInt(2100);
|
||||
_server_name = deviceConfig["servername"].toString();
|
||||
|
||||
if( deviceConfig.contains("transport_type") ) _transport_type = deviceConfig["transport_type"].toString("DTLS");
|
||||
if( deviceConfig.contains("seed_custom") ) _custom = deviceConfig["seed_custom"].toString("dtls_client");
|
||||
if( deviceConfig.contains("retry_left") ) _retry_left = deviceConfig["retry_left"].toInt(MAX_RETRY);
|
||||
if( deviceConfig.contains("read_timeout") ) _read_timeout = deviceConfig["read_timeout"].toInt(0);
|
||||
if( deviceConfig.contains("hs_timeout_min") ) _handshake_timeout_min = deviceConfig["hs_timeout_min"].toInt(400);
|
||||
if( deviceConfig.contains("hs_timeout_max") ) _handshake_timeout_max = deviceConfig["hs_timeout_max"].toInt(1000);
|
||||
if( deviceConfig.contains("hs_attempts") ) _handshake_attempts = deviceConfig["hs_attempts"].toInt(5);
|
||||
|
||||
QString host = deviceConfig["host"].toString(_defaultHost);
|
||||
QStringList debugLevels = QStringList() << "No Debug" << "Error" << "State Change" << "Informational" << "Verbose";
|
||||
|
||||
configLog( "SSL Streamer Debug", "%s", ( _debugStreamer ) ? "yes" : "no" );
|
||||
configLog( "SSL DebugLevel", "[%d] %s", _debugLevel, QSTRING_CSTR( debugLevels[ _debugLevel ]) );
|
||||
|
||||
configLog( "SSL Servername", "%s", QSTRING_CSTR( _server_name ) );
|
||||
configLog( "SSL Host", "%s", QSTRING_CSTR( host ) );
|
||||
configLog( "SSL Port", "%d", _port );
|
||||
configLog( "PSK", "%s", QSTRING_CSTR( _psk ) );
|
||||
configLog( "PSK-Identity", "%s", QSTRING_CSTR( _psk_identity ) );
|
||||
configLog( "SSL Transport Type", "%s", QSTRING_CSTR( _transport_type ) );
|
||||
configLog( "SSL Seed Custom", "%s", QSTRING_CSTR( _custom ) );
|
||||
configLog( "SSL Retry Left", "%d", _retry_left );
|
||||
configLog( "SSL Read Timeout", "%d", _read_timeout );
|
||||
configLog( "SSL Handshake Timeout min", "%d", _handshake_timeout_min );
|
||||
configLog( "SSL Handshake Timeout max", "%d", _handshake_timeout_max );
|
||||
configLog( "SSL Handshake attempts", "%d", _handshake_attempts );
|
||||
|
||||
if ( _address.setAddress(host) )
|
||||
{
|
||||
Debug( _log, "Failed to parse [%s] as a hostname.", QSTRING_CSTR( host ) );
|
||||
QString errortext = QString("Invalid target address [%1]!").arg(host);
|
||||
Debug( _log, "Successfully parsed %s as an ip address.", QSTRING_CSTR( host ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug( _log, "Failed to parse [%s] as an ip address.", QSTRING_CSTR( host ) );
|
||||
QHostInfo info = QHostInfo::fromName(host);
|
||||
if ( info.addresses().isEmpty() )
|
||||
{
|
||||
Debug( _log, "Failed to parse [%s] as a hostname.", QSTRING_CSTR( host ) );
|
||||
QString errortext = QString("Invalid target address [%1]!").arg(host);
|
||||
this->setInError( errortext );
|
||||
isInitOK = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug( _log, "Successfully parsed %s as a hostname.", QSTRING_CSTR( host ) );
|
||||
_address = info.addresses().first();
|
||||
}
|
||||
}
|
||||
|
||||
int config_port = deviceConfig["sslport"].toInt(_port);
|
||||
|
||||
if ( config_port <= 0 || config_port > MAX_PORT_SSL )
|
||||
{
|
||||
QString errortext = QString ("Invalid target port [%1]!").arg(config_port);
|
||||
this->setInError( errortext );
|
||||
isInitOK = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug( _log, "Successfully parsed %s as a hostname.", QSTRING_CSTR( host ) );
|
||||
_address = info.addresses().first();
|
||||
_ssl_port = config_port;
|
||||
Debug( _log, "UDP SSL using %s:%u", QSTRING_CSTR( _address.toString() ), _ssl_port );
|
||||
isInitOK = true;
|
||||
}
|
||||
}
|
||||
|
||||
int config_port = deviceConfig["sslport"].toInt(_port);
|
||||
|
||||
if ( config_port <= 0 || config_port > MAX_PORT_SSL )
|
||||
{
|
||||
QString errortext = QString ("Invalid target port [%1]!").arg(config_port);
|
||||
this->setInError( errortext );
|
||||
isInitOK = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_ssl_port = config_port;
|
||||
Debug( _log, "UDP SSL using %s:%u", QSTRING_CSTR( _address.toString() ), _ssl_port );
|
||||
}
|
||||
return isInitOK;
|
||||
}
|
||||
|
||||
int ProviderUdpSSL::open()
|
||||
{
|
||||
int retval = -1;
|
||||
QString errortext;
|
||||
_deviceReady = false;
|
||||
_isDeviceReady = false;
|
||||
|
||||
if ( init(_devConfig) )
|
||||
// TODO: Question: Just checking .... Is this one time initialisation or required with every open request (during switch-off/switch-on)?
|
||||
// In case one time initialisation, it should go to the init method.
|
||||
// Everything that is required to pen a UDP-SSL connection again (after it maybe was closed remotely should go here)
|
||||
|
||||
if ( !initNetwork() )
|
||||
{
|
||||
if ( !initNetwork() )
|
||||
{
|
||||
this->setInError( "UDP SSL Network error!" );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Everything is OK -> enable device
|
||||
_deviceReady = true;
|
||||
setEnable(true);
|
||||
retval = 0;
|
||||
}
|
||||
this->setInError( "UDP SSL Network error!" );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Everything is OK -> enable device
|
||||
_isDeviceReady = true;
|
||||
retval = 0;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void ProviderUdpSSL::close()
|
||||
int ProviderUdpSSL::close()
|
||||
{
|
||||
LedDevice::close();
|
||||
closeSSLConnection();
|
||||
// LedDevice specific closing activities
|
||||
int retval = 0;
|
||||
_isDeviceReady = false;
|
||||
|
||||
// TODO: You may want to check, if the device is already closed or close it and return, if ok or not
|
||||
// Test, if device requires closing
|
||||
if ( true /*If device is still open*/ )
|
||||
{
|
||||
// Close device
|
||||
|
||||
LedDevice::close();
|
||||
closeSSLConnection();
|
||||
// Everything is OK -> device is closed
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void ProviderUdpSSL::closeSSLConnection()
|
||||
{
|
||||
if( _deviceReady && !_stopConnection )
|
||||
if( _isDeviceReady && !_stopConnection )
|
||||
{
|
||||
closeSSLNotify();
|
||||
freeSSLConnection();
|
||||
@@ -412,7 +432,7 @@ bool ProviderUdpSSL::startSSLHandshake()
|
||||
|
||||
void ProviderUdpSSL::freeSSLConnection()
|
||||
{
|
||||
sslLog( "SSL Connection cleanup..." );
|
||||
sslLog( "SSL Connection clean-up..." );
|
||||
|
||||
_stopConnection = true;
|
||||
|
||||
@@ -425,15 +445,15 @@ void ProviderUdpSSL::freeSSLConnection()
|
||||
mbedtls_x509_crt_free(&cacert);
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
sslLog( "SSL Connection cleanup...ok" );
|
||||
sslLog( "SSL Connection clean-up...ok" );
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
sslLog( QString("SSL Connection cleanup Error: %s").arg( e.what() ) );
|
||||
sslLog( QString("SSL Connection clean-up Error: %s").arg( e.what() ) );
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
sslLog( "SSL Connection cleanup Error: <unknown>" );
|
||||
sslLog( "SSL Connection clean-up Error: <unknown>" );
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user