diff --git a/src/client.cpp b/src/client.cpp index 9e8ee9da1e..1046d3206b 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -570,11 +570,7 @@ void CClient::SetRemoteChanPan ( const int iId, const float fPan ) bool CClient::SetServerAddr ( QString strNAddr ) { CHostAddress HostAddress; -#ifdef CLIENT_NO_SRV_CONNECT - if ( NetworkUtil().ParseNetworkAddress ( strNAddr, HostAddress, bEnableIPv6 ) ) -#else - if ( NetworkUtil().ParseNetworkAddressWithSrvDiscovery ( strNAddr, HostAddress, bEnableIPv6 ) ) -#endif + if ( NetworkUtil::ParseNetworkAddress ( strNAddr, HostAddress, bEnableIPv6 ) ) { // apply address to the channel Channel.SetAddress ( HostAddress ); diff --git a/src/clientdlg.cpp b/src/clientdlg.cpp index 0c7d3af859..3a9a119f6c 100644 --- a/src/clientdlg.cpp +++ b/src/clientdlg.cpp @@ -588,12 +588,12 @@ CClientDlg::CClientDlg ( CClient* pNCliP, // Send the request to two servers for redundancy if either or both of them // has a higher release version number, the reply will trigger the notification. - if ( NetworkUtil().ParseNetworkAddress ( UPDATECHECK1_ADDRESS, UpdateServerHostAddress, bEnableIPv6 ) ) + if ( NetworkUtil::ParseNetworkAddress ( UPDATECHECK1_ADDRESS, UpdateServerHostAddress, bEnableIPv6 ) ) { pClient->CreateCLServerListReqVerAndOSMes ( UpdateServerHostAddress ); } - if ( NetworkUtil().ParseNetworkAddress ( UPDATECHECK2_ADDRESS, UpdateServerHostAddress, bEnableIPv6 ) ) + if ( NetworkUtil::ParseNetworkAddress ( UPDATECHECK2_ADDRESS, UpdateServerHostAddress, bEnableIPv6 ) ) { pClient->CreateCLServerListReqVerAndOSMes ( UpdateServerHostAddress ); } diff --git a/src/clientrpc.cpp b/src/clientrpc.cpp index 3d92d54713..f2c3f53cc3 100644 --- a/src/clientrpc.cpp +++ b/src/clientrpc.cpp @@ -164,7 +164,9 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare } CHostAddress haDirectoryAddress; - if ( NetworkUtil().ParseNetworkAddress ( jsonDirectoryIp.toString(), haDirectoryAddress, false ) ) + + // Allow IPv4 only for communicating with Directories + if ( NetworkUtil::ParseNetworkAddress ( jsonDirectoryIp.toString(), haDirectoryAddress, false ) ) { // send the request for the server list pClient->CreateCLReqServerListMes ( haDirectoryAddress ); diff --git a/src/connectdlg.cpp b/src/connectdlg.cpp index cbdf289376..c0a2b8c17f 100644 --- a/src/connectdlg.cpp +++ b/src/connectdlg.cpp @@ -318,13 +318,13 @@ void CConnectDlg::RequestServerList() } cbxDirectory->blockSignals ( false ); - // Get the IP address of the directory server (using the ParseNetworAddress + // Get the IP address of the directory server (using the ParseNetworkAddress // function) when the connect dialog is opened, this seems to be the correct // time to do it. Note that in case of custom directories we // use iCustomDirectoryIndex as an index into the vector. // Allow IPv4 only for communicating with Directories - if ( NetworkUtil().ParseNetworkAddress ( + if ( NetworkUtil::ParseNetworkAddress ( NetworkUtil::GetDirectoryAddress ( pSettings->eDirectoryType, pSettings->vstrDirectoryAddress[pSettings->iCustomDirectoryIndex] ), haDirectoryAddress, false ) ) @@ -856,7 +856,8 @@ void CConnectDlg::OnTimerPing() // try to parse host address string which is stored as user data // in the server list item GUI control element - if ( NetworkUtil().ParseNetworkAddress ( pCurListViewItem->data ( LVC_NAME, Qt::UserRole ).toString(), haServerAddress, bEnableIPv6 ) ) + // the data to be parsed is just IP:port, so no SRV discovery is needed + if ( NetworkUtil::ParseNetworkAddressBare ( pCurListViewItem->data ( LVC_NAME, Qt::UserRole ).toString(), haServerAddress, bEnableIPv6 ) ) { // if address is valid, send ping message using a new thread #if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) diff --git a/src/global.h b/src/global.h index 03ec70b81d..872d09f37d 100644 --- a/src/global.h +++ b/src/global.h @@ -96,8 +96,8 @@ LED bar: lbr #define MAX_DELAY_PANNING_SAMPLES 64 // default server address and port numbers -#define DEFAULT_QOS_NUMBER 128 // CS4 (Quality of Service) -#define DEFAULT_SERVER_ADDRESS "anygenre1.jamulus.io" +#define DEFAULT_QOS_NUMBER 128 // CS4 (Quality of Service) +#define DEFAULT_SERVER_ADDRESS "anygenre1.jamulus.io:22124" // default port explicit to avoid unneeded SRV lookup #define DEFAULT_PORT_NUMBER 22124 #define CENTSERV_ANY_GENRE2 "anygenre2.jamulus.io:22224" #define CENTSERV_ANY_GENRE3 "anygenre3.jamulus.io:22624" diff --git a/src/serverdlg.cpp b/src/serverdlg.cpp index 086060a4f1..e1a5785b77 100644 --- a/src/serverdlg.cpp +++ b/src/serverdlg.cpp @@ -482,12 +482,12 @@ CServerDlg::CServerDlg ( CServer* pNServP, CServerSettings* pNSetP, const bool b // Send the request to two servers for redundancy if either or both of them // has a higher release version number, the reply will trigger the notification. - if ( NetworkUtil().ParseNetworkAddress ( UPDATECHECK1_ADDRESS, UpdateServerHostAddress, pServer->IsIPv6Enabled() ) ) + if ( NetworkUtil::ParseNetworkAddress ( UPDATECHECK1_ADDRESS, UpdateServerHostAddress, pServer->IsIPv6Enabled() ) ) { pServer->CreateCLServerListReqVerAndOSMes ( UpdateServerHostAddress ); } - if ( NetworkUtil().ParseNetworkAddress ( UPDATECHECK2_ADDRESS, UpdateServerHostAddress, pServer->IsIPv6Enabled() ) ) + if ( NetworkUtil::ParseNetworkAddress ( UPDATECHECK2_ADDRESS, UpdateServerHostAddress, pServer->IsIPv6Enabled() ) ) { pServer->CreateCLServerListReqVerAndOSMes ( UpdateServerHostAddress ); } diff --git a/src/serverlist.cpp b/src/serverlist.cpp index 0488aa28d3..4dabe4c7ef 100644 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -805,7 +805,9 @@ bool CServerListManager::Load() continue; } - NetworkUtil::ParseNetworkAddress ( slLine[0], haServerHostAddr, bEnableIPv6 ); + // This uses ParseNetworkAddressBare because it is just parsing ip:host that was saved to the file. + // Therefore no SRV lookup is appropriate. + NetworkUtil::ParseNetworkAddressBare ( slLine[0], haServerHostAddr, bEnableIPv6 ); int iIdx = IndexOf ( haServerHostAddr ); if ( iIdx != INVALID_INDEX ) { @@ -969,13 +971,23 @@ void CServerListManager::SetRegistered ( const bool bIsRegister ) return; } + // It is very important to unlock the Mutex before doing address resolution, + // so that the event loop can run and any other timers that need the mutex + // can obtain it. Otherwise there is the possibility of deadlock when doing + // the SRV lookup, if another timer fires that needs the same mutex. + locker.unlock(); + // get the correct directory address // Note that we always have to parse the server address again since if // it is an URL of a dynamic IP address, the IP address might have // changed in the meanwhile. // Allow IPv4 only for communicating with Directories + // Use SRV DNS discovery for directory connections, fallback to A/AAAA if none. const QString strNetworkAddress = NetworkUtil::GetDirectoryAddress ( DirectoryType, strDirectoryAddress ); - const bool bDirectoryAddressValid = NetworkUtil().ParseNetworkAddress ( strNetworkAddress, DirectoryAddress, false ); + const bool bDirectoryAddressValid = NetworkUtil::ParseNetworkAddress ( strNetworkAddress, DirectoryAddress, false ); + + // lock the mutex again now that the address has been resolved. + locker.relock(); if ( bIsRegister ) { diff --git a/src/util.cpp b/src/util.cpp index e81f1b41da..4fd1f3af59 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -750,7 +750,7 @@ bool NetworkUtil::ParseNetworkAddressString ( QString strAddress, QHostAddress& return false; } -#ifndef CLIENT_NO_SRV_CONNECT +#ifndef DISABLE_SRV_DNS bool NetworkUtil::ParseNetworkAddressSrv ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 ) { // init requested host address with invalid address first @@ -806,20 +806,22 @@ bool NetworkUtil::ParseNetworkAddressSrv ( QString strAddress, CHostAddress& Hos } return false; } +#endif -bool NetworkUtil::ParseNetworkAddressWithSrvDiscovery ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 ) +bool NetworkUtil::ParseNetworkAddress ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 ) { +#ifndef DISABLE_SRV_DNS // Try SRV-based discovery first: if ( ParseNetworkAddressSrv ( strAddress, HostAddress, bEnableIPv6 ) ) { return true; } +#endif // Try regular connect via plain IP or host name lookup (A/AAAA): - return ParseNetworkAddress ( strAddress, HostAddress, bEnableIPv6 ); + return ParseNetworkAddressBare ( strAddress, HostAddress, bEnableIPv6 ); } -#endif -bool NetworkUtil::ParseNetworkAddress ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 ) +bool NetworkUtil::ParseNetworkAddressBare ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 ) { QHostAddress InetAddr; unsigned int iNetPort = DEFAULT_PORT_NUMBER; diff --git a/src/util.h b/src/util.h index 5fabfe7c4b..e83e1f764a 100644 --- a/src/util.h +++ b/src/util.h @@ -53,7 +53,7 @@ #include #include #include -#ifndef CLIENT_NO_SRV_CONNECT +#ifndef DISABLE_SRV_DNS # include #endif #ifndef _WIN32 @@ -1055,11 +1055,11 @@ class NetworkUtil public: static bool ParseNetworkAddressString ( QString strAddress, QHostAddress& InetAddr, bool bEnableIPv6 ); -#ifndef CLIENT_NO_SRV_CONNECT +#ifndef DISABLE_SRV_DNS static bool ParseNetworkAddressSrv ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 ); - static bool ParseNetworkAddressWithSrvDiscovery ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 ); #endif static bool ParseNetworkAddress ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 ); + static bool ParseNetworkAddressBare ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 ); static QString FixAddress ( const QString& strAddress ); static CHostAddress GetLocalAddress();