Skip to content

Commit cb5e436

Browse files
authored
Merge pull request #3556 from rdica/SRV-directoryaddress
Provides SRV support for connecting to directories from client or server
2 parents a4efd8c + 1718187 commit cb5e436

10 files changed

Lines changed: 48 additions & 25 deletions

File tree

Jamulus.pro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,12 @@ contains(CONFIG, "disable_version_check") {
11821182
DEFINES += DISABLE_VERSION_CHECK
11831183
}
11841184

1185+
# disable SRV resolution in DNS if requested (#3556)
1186+
contains(CONFIG, "disable_srv_dns") {
1187+
message(The use of SRV records in DNS is disabled.)
1188+
DEFINES += DISABLE_SRV_DNS
1189+
}
1190+
11851191
# Enable formatting all code via `make clang_format`.
11861192
# Note: When extending the list of file extensions or when adding new code directories,
11871193
# be sure to update .github/workflows/coding-style-check.yml and .clang-format-ignore as well.

src/client.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,7 @@ void CClient::SetRemoteChanPan ( const int iId, const float fPan )
570570
bool CClient::SetServerAddr ( QString strNAddr )
571571
{
572572
CHostAddress HostAddress;
573-
#ifdef CLIENT_NO_SRV_CONNECT
574-
if ( NetworkUtil().ParseNetworkAddress ( strNAddr, HostAddress, bEnableIPv6 ) )
575-
#else
576-
if ( NetworkUtil().ParseNetworkAddressWithSrvDiscovery ( strNAddr, HostAddress, bEnableIPv6 ) )
577-
#endif
573+
if ( NetworkUtil::ParseNetworkAddress ( strNAddr, HostAddress, bEnableIPv6 ) )
578574
{
579575
// apply address to the channel
580576
Channel.SetAddress ( HostAddress );

src/clientdlg.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,12 +588,14 @@ CClientDlg::CClientDlg ( CClient* pNCliP,
588588
// Send the request to two servers for redundancy if either or both of them
589589
// has a higher release version number, the reply will trigger the notification.
590590

591-
if ( NetworkUtil().ParseNetworkAddress ( UPDATECHECK1_ADDRESS, UpdateServerHostAddress, bEnableIPv6 ) )
591+
// Don't use SRV resolution when resolving update servers.
592+
593+
if ( NetworkUtil::ParseNetworkAddressBare ( UPDATECHECK1_ADDRESS, UpdateServerHostAddress, bEnableIPv6 ) )
592594
{
593595
pClient->CreateCLServerListReqVerAndOSMes ( UpdateServerHostAddress );
594596
}
595597

596-
if ( NetworkUtil().ParseNetworkAddress ( UPDATECHECK2_ADDRESS, UpdateServerHostAddress, bEnableIPv6 ) )
598+
if ( NetworkUtil::ParseNetworkAddressBare ( UPDATECHECK2_ADDRESS, UpdateServerHostAddress, bEnableIPv6 ) )
597599
{
598600
pClient->CreateCLServerListReqVerAndOSMes ( UpdateServerHostAddress );
599601
}

src/clientrpc.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
164164
}
165165

166166
CHostAddress haDirectoryAddress;
167-
if ( NetworkUtil().ParseNetworkAddress ( jsonDirectoryIp.toString(), haDirectoryAddress, false ) )
167+
168+
// Allow IPv4 only for communicating with Directories
169+
if ( NetworkUtil::ParseNetworkAddress ( jsonDirectoryIp.toString(), haDirectoryAddress, false ) )
168170
{
169171
// send the request for the server list
170172
pClient->CreateCLReqServerListMes ( haDirectoryAddress );

src/connectdlg.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,13 @@ void CConnectDlg::RequestServerList()
318318
}
319319
cbxDirectory->blockSignals ( false );
320320

321-
// Get the IP address of the directory server (using the ParseNetworAddress
321+
// Get the IP address of the directory server (using the ParseNetworkAddress
322322
// function) when the connect dialog is opened, this seems to be the correct
323323
// time to do it. Note that in case of custom directories we
324324
// use iCustomDirectoryIndex as an index into the vector.
325325

326326
// Allow IPv4 only for communicating with Directories
327-
if ( NetworkUtil().ParseNetworkAddress (
327+
if ( NetworkUtil::ParseNetworkAddress (
328328
NetworkUtil::GetDirectoryAddress ( pSettings->eDirectoryType, pSettings->vstrDirectoryAddress[pSettings->iCustomDirectoryIndex] ),
329329
haDirectoryAddress,
330330
false ) )
@@ -856,7 +856,8 @@ void CConnectDlg::OnTimerPing()
856856

857857
// try to parse host address string which is stored as user data
858858
// in the server list item GUI control element
859-
if ( NetworkUtil().ParseNetworkAddress ( pCurListViewItem->data ( LVC_NAME, Qt::UserRole ).toString(), haServerAddress, bEnableIPv6 ) )
859+
// the data to be parsed is just IP:port, so no SRV discovery is needed
860+
if ( NetworkUtil::ParseNetworkAddressBare ( pCurListViewItem->data ( LVC_NAME, Qt::UserRole ).toString(), haServerAddress, bEnableIPv6 ) )
860861
{
861862
// if address is valid, send ping message using a new thread
862863
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )

src/global.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ LED bar: lbr
9696
#define MAX_DELAY_PANNING_SAMPLES 64
9797

9898
// default server address and port numbers
99-
#define DEFAULT_QOS_NUMBER 128 // CS4 (Quality of Service)
100-
#define DEFAULT_SERVER_ADDRESS "anygenre1.jamulus.io"
99+
#define DEFAULT_QOS_NUMBER 128 // CS4 (Quality of Service)
100+
#define DEFAULT_SERVER_ADDRESS "anygenre1.jamulus.io:22124" // default port explicit to avoid unneeded SRV lookup
101101
#define DEFAULT_PORT_NUMBER 22124
102102
#define CENTSERV_ANY_GENRE2 "anygenre2.jamulus.io:22224"
103103
#define CENTSERV_ANY_GENRE3 "anygenre3.jamulus.io:22624"

src/serverdlg.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,14 @@ CServerDlg::CServerDlg ( CServer* pNServP, CServerSettings* pNSetP, const bool b
482482
// Send the request to two servers for redundancy if either or both of them
483483
// has a higher release version number, the reply will trigger the notification.
484484

485-
if ( NetworkUtil().ParseNetworkAddress ( UPDATECHECK1_ADDRESS, UpdateServerHostAddress, pServer->IsIPv6Enabled() ) )
485+
// Don't use SRV resolution when resolving update servers.
486+
487+
if ( NetworkUtil::ParseNetworkAddressBare ( UPDATECHECK1_ADDRESS, UpdateServerHostAddress, pServer->IsIPv6Enabled() ) )
486488
{
487489
pServer->CreateCLServerListReqVerAndOSMes ( UpdateServerHostAddress );
488490
}
489491

490-
if ( NetworkUtil().ParseNetworkAddress ( UPDATECHECK2_ADDRESS, UpdateServerHostAddress, pServer->IsIPv6Enabled() ) )
492+
if ( NetworkUtil::ParseNetworkAddressBare ( UPDATECHECK2_ADDRESS, UpdateServerHostAddress, pServer->IsIPv6Enabled() ) )
491493
{
492494
pServer->CreateCLServerListReqVerAndOSMes ( UpdateServerHostAddress );
493495
}

src/serverlist.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,9 @@ bool CServerListManager::Load()
805805
continue;
806806
}
807807

808-
NetworkUtil::ParseNetworkAddress ( slLine[0], haServerHostAddr, bEnableIPv6 );
808+
// This uses ParseNetworkAddressBare because it is just parsing ip:host that was saved to the file.
809+
// Therefore no SRV lookup is appropriate.
810+
NetworkUtil::ParseNetworkAddressBare ( slLine[0], haServerHostAddr, bEnableIPv6 );
809811
int iIdx = IndexOf ( haServerHostAddr );
810812
if ( iIdx != INVALID_INDEX )
811813
{
@@ -969,13 +971,23 @@ void CServerListManager::SetRegistered ( const bool bIsRegister )
969971
return;
970972
}
971973

974+
// It is very important to unlock the Mutex before doing address resolution,
975+
// so that the event loop can run and any other timers that need the mutex
976+
// can obtain it. Otherwise there is the possibility of deadlock when doing
977+
// the SRV lookup, if another timer fires that needs the same mutex.
978+
locker.unlock();
979+
972980
// get the correct directory address
973981
// Note that we always have to parse the server address again since if
974982
// it is an URL of a dynamic IP address, the IP address might have
975983
// changed in the meanwhile.
976984
// Allow IPv4 only for communicating with Directories
985+
// Use SRV DNS discovery for directory connections, fallback to A/AAAA if none.
977986
const QString strNetworkAddress = NetworkUtil::GetDirectoryAddress ( DirectoryType, strDirectoryAddress );
978-
const bool bDirectoryAddressValid = NetworkUtil().ParseNetworkAddress ( strNetworkAddress, DirectoryAddress, false );
987+
const bool bDirectoryAddressValid = NetworkUtil::ParseNetworkAddress ( strNetworkAddress, DirectoryAddress, false );
988+
989+
// lock the mutex again now that the address has been resolved.
990+
locker.relock();
979991

980992
if ( bIsRegister )
981993
{

src/util.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ bool NetworkUtil::ParseNetworkAddressString ( QString strAddress, QHostAddress&
750750
return false;
751751
}
752752

753-
#ifndef CLIENT_NO_SRV_CONNECT
753+
#ifndef DISABLE_SRV_DNS
754754
bool NetworkUtil::ParseNetworkAddressSrv ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 )
755755
{
756756
// init requested host address with invalid address first
@@ -806,20 +806,22 @@ bool NetworkUtil::ParseNetworkAddressSrv ( QString strAddress, CHostAddress& Hos
806806
}
807807
return false;
808808
}
809+
#endif
809810

810-
bool NetworkUtil::ParseNetworkAddressWithSrvDiscovery ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 )
811+
bool NetworkUtil::ParseNetworkAddress ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 )
811812
{
813+
#ifndef DISABLE_SRV_DNS
812814
// Try SRV-based discovery first:
813815
if ( ParseNetworkAddressSrv ( strAddress, HostAddress, bEnableIPv6 ) )
814816
{
815817
return true;
816818
}
819+
#endif
817820
// Try regular connect via plain IP or host name lookup (A/AAAA):
818-
return ParseNetworkAddress ( strAddress, HostAddress, bEnableIPv6 );
821+
return ParseNetworkAddressBare ( strAddress, HostAddress, bEnableIPv6 );
819822
}
820-
#endif
821823

822-
bool NetworkUtil::ParseNetworkAddress ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 )
824+
bool NetworkUtil::ParseNetworkAddressBare ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 )
823825
{
824826
QHostAddress InetAddr;
825827
unsigned int iNetPort = DEFAULT_PORT_NUMBER;

src/util.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#include <QElapsedTimer>
5454
#include <QTextBoundaryFinder>
5555
#include <QTimer>
56-
#ifndef CLIENT_NO_SRV_CONNECT
56+
#ifndef DISABLE_SRV_DNS
5757
# include <QDnsLookup>
5858
#endif
5959
#ifndef _WIN32
@@ -1055,11 +1055,11 @@ class NetworkUtil
10551055
public:
10561056
static bool ParseNetworkAddressString ( QString strAddress, QHostAddress& InetAddr, bool bEnableIPv6 );
10571057

1058-
#ifndef CLIENT_NO_SRV_CONNECT
1058+
#ifndef DISABLE_SRV_DNS
10591059
static bool ParseNetworkAddressSrv ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 );
1060-
static bool ParseNetworkAddressWithSrvDiscovery ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 );
10611060
#endif
10621061
static bool ParseNetworkAddress ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 );
1062+
static bool ParseNetworkAddressBare ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 );
10631063

10641064
static QString FixAddress ( const QString& strAddress );
10651065
static CHostAddress GetLocalAddress();

0 commit comments

Comments
 (0)