Skip to content

Commit 1d0a365

Browse files
committed
Rename IPv4 addrs and add IPv6 addrs in CServerInfo
1 parent 2fbebc3 commit 1d0a365

6 files changed

Lines changed: 65 additions & 41 deletions

File tree

src/clientrpc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ CClientRpc::CClientRpc ( CClient* pClient, CClientSettings* pSettings, CRpcServe
137137
for ( const auto& serverInfo : vecServerInfo )
138138
{
139139
QJsonObject objServerInfo{
140-
{ "address", serverInfo.HostAddr.toString() },
140+
{ "address", serverInfo.HostAddr4.toString() },
141141
{ "name", serverInfo.strName },
142142
{ "countryId", serverInfo.eCountry },
143143
{ "country", QLocale::countryToString ( serverInfo.eCountry ) },
144144
{ "city", serverInfo.strCity },
145145
};
146146
arrServerInfo.append ( objServerInfo );
147-
pClient->CreateCLServerListPingMes ( serverInfo.HostAddr );
147+
pClient->CreateCLServerListPingMes ( serverInfo.HostAddr4 );
148148
}
149149
pRpcServer->BroadcastNotification ( "jamulusclient/serverListReceived",
150150
QJsonObject{

src/connectdlg.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, const CVector<CS
457457

458458
if ( iIdx > 0 )
459459
{
460-
CurHostAddress = vecServerInfo[iIdx].HostAddr;
460+
CurHostAddress = vecServerInfo[iIdx].HostAddr4;
461461
}
462462
else
463463
{
@@ -485,7 +485,7 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, const CVector<CS
485485
// IP address and port (use IP number without last byte)
486486
// Definition: If the port number is the default port number, we do
487487
// not show it.
488-
if ( vecServerInfo[iIdx].HostAddr.iPort == DEFAULT_PORT_NUMBER )
488+
if ( vecServerInfo[iIdx].HostAddr4.iPort == DEFAULT_PORT_NUMBER )
489489
{
490490
// only show IP number, no port number
491491
pNewListViewItem->setText ( LVC_NAME, CurHostAddress.toString ( CHostAddress::SM_IP_NO_LAST_BYTE ) );

src/protocol.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,11 +2109,11 @@ void CProtocol::CreateCLServerListMes ( const CHostAddress& InetAddr, const CVec
21092109

21102110
// IP address (4 bytes)
21112111
// note the Server List manager has put the internal details in HostAddr where required
2112-
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecServerInfo[i].HostAddr.InetAddr.toIPv4Address() ), 4 );
2112+
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecServerInfo[i].HostAddr4.InetAddr.toIPv4Address() ), 4 );
21132113

21142114
// port number (2 bytes)
21152115
// note the Server List manager has put the internal details in HostAddr where required
2116-
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecServerInfo[i].HostAddr.iPort ), 2 );
2116+
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecServerInfo[i].HostAddr4.iPort ), 2 );
21172117

21182118
// country (2 bytes)
21192119
PutCountryOnStream ( vecData, iPos, vecServerInfo[i].eCountry );
@@ -2232,11 +2232,11 @@ void CProtocol::CreateCLRedServerListMes ( const CHostAddress& InetAddr, const C
22322232

22332233
// IP address (4 bytes)
22342234
// note the Server List manager has put the internal details in HostAddr where required
2235-
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecServerInfo[i].HostAddr.InetAddr.toIPv4Address() ), 4 );
2235+
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecServerInfo[i].HostAddr4.InetAddr.toIPv4Address() ), 4 );
22362236

22372237
// port number (2 bytes)
22382238
// note the Server List manager has put the internal details in HostAddr where required
2239-
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecServerInfo[i].HostAddr.iPort ), 2 );
2239+
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecServerInfo[i].HostAddr4.iPort ), 2 );
22402240

22412241
// name (note that the string length indicator is 1 in this special case)
22422242
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name, 1 );

src/serverlist.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ QString CServerListEntry::toCSV()
130130
{
131131
QStringList sl;
132132

133-
sl.append ( this->HostAddr.toString() );
134-
sl.append ( this->LHostAddr.toString() );
133+
sl.append ( this->HostAddr4.toString() );
134+
sl.append ( this->LHostAddr4.toString() );
135135
sl.append ( ToBase64 ( this->strName ) );
136136
sl.append ( ToBase64 ( this->strCity ) );
137137
sl.append ( QString::number ( this->eCountry ) );
@@ -543,7 +543,7 @@ void CServerListManager::OnTimerPingServerInList()
543543
for ( int iIdx = 1; iIdx < iCurServerListSize; iIdx++ )
544544
{
545545
// send empty message to keep NAT port open at registered server
546-
pConnLessProtocol->CreateCLEmptyMes ( ServerList[iIdx].HostAddr );
546+
pConnLessProtocol->CreateCLEmptyMes ( ServerList[iIdx].HostAddr4 );
547547
}
548548
}
549549

@@ -560,7 +560,7 @@ void CServerListManager::OnTimerPollList()
560560
if ( ServerList[iIdx].RegisterTime.elapsed() > ( SERVLIST_TIME_OUT_MINUTES * 60000 ) )
561561
{
562562
// remove this list entry
563-
vecRemovedHostAddr.Add ( ServerList[iIdx].HostAddr );
563+
vecRemovedHostAddr.Add ( ServerList[iIdx].HostAddr4 );
564564
ServerList.removeAt ( iIdx );
565565
}
566566
}
@@ -637,7 +637,7 @@ void CServerListManager::Append ( const CHostAddress& InetAddr,
637637
else
638638
{
639639
// update all data and call update registration function
640-
ServerList[iSelIdx].LHostAddr = LInetAddr;
640+
ServerList[iSelIdx].LHostAddr4 = LInetAddr;
641641
ServerList[iSelIdx].strName = ServerInfo.strName;
642642
ServerList[iSelIdx].eCountry = ServerInfo.eCountry;
643643
ServerList[iSelIdx].strCity = ServerInfo.strCity;
@@ -695,12 +695,12 @@ void CServerListManager::RetrieveAll ( const CHostAddress& InetAddr )
695695
bool clientIsInternal = NetworkUtil::IsPrivateNetworkIP ( InetAddr.InetAddr );
696696

697697
CHostAddress clientPublicAddr = InetAddr;
698-
if ( clientIsInternal && CHostAddress().InetAddr != ServerList[0].LHostAddr.InetAddr &&
699-
!NetworkUtil::IsPrivateNetworkIP ( ServerList[0].LHostAddr.InetAddr ) )
698+
if ( clientIsInternal && CHostAddress().InetAddr != ServerList[0].LHostAddr4.InetAddr &&
699+
!NetworkUtil::IsPrivateNetworkIP ( ServerList[0].LHostAddr4.InetAddr ) )
700700
{
701701
// client and directory on same LAN, directory has public IP set, that should be suitable for the
702702
// client, too (i.e. same router with same public IP will be used for both), so use it for client public IP
703-
clientPublicAddr.InetAddr = ServerList[0].LHostAddr.InetAddr;
703+
clientPublicAddr.InetAddr = ServerList[0].LHostAddr4.InetAddr;
704704
}
705705

706706
const ushort iCurServerListSize = static_cast<ushort> ( ServerList.size() );
@@ -709,8 +709,8 @@ void CServerListManager::RetrieveAll ( const CHostAddress& InetAddr )
709709
CVector<CServerInfo> vecServerInfo ( iCurServerListSize );
710710

711711
// copy list item for the directory and just let the protocol sort out the actual details
712-
vecServerInfo[0] = ServerList[0];
713-
vecServerInfo[0].HostAddr = CHostAddress();
712+
vecServerInfo[0] = ServerList[0];
713+
vecServerInfo[0].HostAddr4 = CHostAddress();
714714

715715
// copy the list (we have to copy it since the message requires a vector but the list is actually stored in a QList object
716716
// and not in a vector object)
@@ -719,25 +719,25 @@ void CServerListManager::RetrieveAll ( const CHostAddress& InetAddr )
719719
// copy list item
720720
CServerInfo& siCurListEntry = vecServerInfo[iIdx] = ServerList[iIdx];
721721

722-
bool serverIsInternal = NetworkUtil::IsPrivateNetworkIP ( siCurListEntry.HostAddr.InetAddr );
722+
bool serverIsInternal = NetworkUtil::IsPrivateNetworkIP ( siCurListEntry.HostAddr4.InetAddr );
723723

724-
bool wantHostAddr = clientIsInternal /* HostAddr is local IP if local server else external IP, so do not replace */ ||
724+
bool wantHostAddr = clientIsInternal /* HostAddr4 is local IP if local server else external IP, so do not replace */ ||
725725
( !serverIsInternal &&
726-
InetAddr.InetAddr != siCurListEntry.HostAddr.InetAddr /* external server and client have different public IPs */ );
726+
InetAddr.InetAddr != siCurListEntry.HostAddr4.InetAddr /* external server and client have different public IPs */ );
727727

728728
if ( !wantHostAddr )
729729
{
730-
vecServerInfo[iIdx].HostAddr = siCurListEntry.LHostAddr;
730+
vecServerInfo[iIdx].HostAddr4 = siCurListEntry.LHostAddr4;
731731
}
732732

733733
// do not send a "ping" to a server local to the directory (no need)
734734
if ( !serverIsInternal )
735735
{
736736
// create "send empty message" for all other registered servers
737-
// this causes the server (vecServerInfo[iIdx].HostAddr)
737+
// this causes the server (vecServerInfo[iIdx].HostAddr4)
738738
// to send a "reply" to the client (InetAddr or best guess public IP address if internal to directory)
739739
// - with the intent of opening the server firewall for the client
740-
pConnLessProtocol->CreateCLSendEmptyMesMes ( siCurListEntry.HostAddr, clientPublicAddr );
740+
pConnLessProtocol->CreateCLSendEmptyMesMes ( siCurListEntry.HostAddr4, clientPublicAddr );
741741
}
742742
}
743743

@@ -758,7 +758,7 @@ int CServerListManager::IndexOf ( const CHostAddress& haSearchTerm )
758758
// (i.e., this server).
759759
for ( int iIdx = ServerList.size() - 1; iIdx > 0; iIdx-- )
760760
{
761-
if ( ServerList[iIdx].HostAddr == haSearchTerm )
761+
if ( ServerList[iIdx].HostAddr4 == haSearchTerm )
762762
{
763763
return iIdx;
764764
}
@@ -847,15 +847,15 @@ bool CServerListManager::Load()
847847
pServer->IsIPv6Available() );
848848

849849
// We expect servers to have addresses...
850-
if ( ( CHostAddress() == serverListEntry.HostAddr ) )
850+
if ( ( CHostAddress() == serverListEntry.HostAddr4 ) )
851851
{
852852
qWarning() << qUtf8Printable ( QString ( "Could not parse '%1' successfully - invalid host" ).arg ( line ) );
853853
continue;
854854
}
855855

856856
qInfo() << qUtf8Printable ( QString ( "Loading registration for %1 (%2): %3" )
857-
.arg ( serverListEntry.HostAddr.toString() )
858-
.arg ( serverListEntry.LHostAddr.toString() )
857+
.arg ( serverListEntry.HostAddr4.toString() )
858+
.arg ( serverListEntry.LHostAddr4.toString() )
859859
.arg ( serverListEntry.strName ) );
860860
ServerList.append ( serverListEntry );
861861
}
@@ -889,8 +889,8 @@ void CServerListManager::Save()
889889
for ( int iIdx = ServerList.size() - 1; iIdx > 0; iIdx-- )
890890
{
891891
qInfo() << qUtf8Printable ( QString ( tr ( "Saving registration for %1 (%2): %3" ) )
892-
.arg ( ServerList[iIdx].HostAddr.toString() )
893-
.arg ( ServerList[iIdx].LHostAddr.toString() )
892+
.arg ( ServerList[iIdx].HostAddr4.toString() )
893+
.arg ( ServerList[iIdx].LHostAddr4.toString() )
894894
.arg ( ServerList[iIdx].strName ) );
895895
out << ServerList[iIdx].toCSV() << '\n';
896896
}

src/testbench.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ public slots:
234234
case 19: // PROTMESSID_CLM_SERVER_LIST
235235
vecServerInfo[0].bPermanentOnline = static_cast<bool> ( GenRandomIntInRange ( 0, 1 ) );
236236
vecServerInfo[0].eCountry = static_cast<QLocale::Country> ( GenRandomIntInRange ( 0, 100 ) );
237-
vecServerInfo[0].HostAddr = CurHostAddress;
238-
vecServerInfo[0].LHostAddr = CurLocalAddress;
237+
vecServerInfo[0].HostAddr4 = CurHostAddress;
238+
vecServerInfo[0].LHostAddr4 = CurLocalAddress;
239239
vecServerInfo[0].iMaxNumClients = GenRandomIntInRange ( -2, 10000 );
240240
vecServerInfo[0].strCity = GenRandomString();
241241
vecServerInfo[0].strName = GenRandomString();

src/util.h

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ class CServerCoreInfo
10351035
class CServerInfo : public CServerCoreInfo
10361036
{
10371037
public:
1038-
CServerInfo() : HostAddr ( CHostAddress() ), LHostAddr ( CHostAddress() ) {}
1038+
CServerInfo() : HostAddr4 ( CHostAddress() ), LHostAddr4 ( CHostAddress() ), HostAddr6 ( CHostAddress() ), LHostAddr6 ( CHostAddress() ) {}
10391039

10401040
CServerInfo ( const CHostAddress& NHAddr,
10411041
const CHostAddress& NLAddr,
@@ -1044,16 +1044,40 @@ class CServerInfo : public CServerCoreInfo
10441044
const QString& NsCity,
10451045
const int NiMaxNumClients,
10461046
const bool NbPermOnline ) :
1047-
CServerCoreInfo ( NsName, NeCountry, NsCity, NiMaxNumClients, NbPermOnline ),
1048-
HostAddr ( NHAddr ),
1049-
LHostAddr ( NLAddr )
1050-
{}
1047+
CServerCoreInfo ( NsName, NeCountry, NsCity, NiMaxNumClients, NbPermOnline )
1048+
{
1049+
if ( NHAddr.InetAddr.protocol() == QAbstractSocket::IPv4Protocol )
1050+
{
1051+
HostAddr4 = NHAddr;
1052+
}
1053+
1054+
if ( NLAddr.InetAddr.protocol() == QAbstractSocket::IPv4Protocol )
1055+
{
1056+
LHostAddr4 = NLAddr;
1057+
}
1058+
1059+
if ( NHAddr.InetAddr.protocol() == QAbstractSocket::IPv6Protocol )
1060+
{
1061+
HostAddr6 = NHAddr;
1062+
}
1063+
1064+
if ( NLAddr.InetAddr.protocol() == QAbstractSocket::IPv6Protocol )
1065+
{
1066+
LHostAddr6 = NLAddr;
1067+
}
1068+
}
1069+
1070+
// IPv4 address of the server
1071+
CHostAddress HostAddr4;
1072+
1073+
// IPv4 internal address of the server
1074+
CHostAddress LHostAddr4;
10511075

1052-
// internet address of the server
1053-
CHostAddress HostAddr;
1076+
// IPv6 address of the server
1077+
CHostAddress HostAddr6;
10541078

1055-
// server internal address
1056-
CHostAddress LHostAddr;
1079+
// IPv6 internal address of the server
1080+
CHostAddress LHostAddr6;
10571081
};
10581082

10591083
// Network transport properties ------------------------------------------------

0 commit comments

Comments
 (0)