-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for central servers behind NAT #954
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,6 +303,9 @@ CONNECTION LESS MESSAGES | |
NOTE: In the PROTMESSID_CLM_SERVER_LIST list, this field will be empty | ||
as only the initial IP address should be used by the client. Where | ||
necessary, that value will contain the server internal address. | ||
When running a central server and a slave server behind the same NAT, | ||
this field is used the other way round: It will contain the public | ||
IP in this case which will be served to clients from the Internet. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a certain natural flow to that which I like :) |
||
|
||
|
||
- PROTMESSID_CLM_REGISTER_SERVER_EX: Register a server, providing extended server | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ CServerListManager::CServerListManager ( const quint16 iNPortNum, | |
const QString& sNCentServAddr, | ||
const QString& strServerInfo, | ||
const QString& strServerListFilter, | ||
const QString& strServerPublicIP, | ||
const int iNumChannels, | ||
CProtocol* pNConLProt ) | ||
: eCentralServerAddressType ( AT_CUSTOM ), // must be AT_CUSTOM for the "no GUI" case | ||
|
@@ -41,7 +42,18 @@ CServerListManager::CServerListManager ( const quint16 iNPortNum, | |
SetCentralServerAddress ( sNCentServAddr ); | ||
|
||
// set the server internal address, including internal port number | ||
SlaveCurLocalHostAddress = CHostAddress( NetworkUtil::GetLocalAddress().InetAddr, iNPortNum ); | ||
QHostAddress qhaServerPublicIP; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There generally isn't consistent Microsoft-style class name initial prefixing of variable names. So these aren't inherently "right" (and I bristle against them) but there are enough type-prefixed names in the code to make them not inherently "wrong", either. |
||
if ( strServerPublicIP == "" ) | ||
{ | ||
// No user-supplied override via --serverpublicip -> use auto-detection | ||
qhaServerPublicIP = NetworkUtil::GetLocalAddress().InetAddr; | ||
} | ||
else | ||
{ | ||
// User-supplied --serverpublicip | ||
qhaServerPublicIP = QHostAddress ( strServerPublicIP ); | ||
} | ||
SlaveCurLocalHostAddress = CHostAddress ( qhaServerPublicIP, iNPortNum ); | ||
|
||
// prepare the server info information | ||
QStringList slServInfoSeparateParams; | ||
|
@@ -443,6 +455,20 @@ void CServerListManager::CentralServerQueryServerList ( const CHostAddress& Inet | |
{ | ||
vecServerInfo[iIdx].HostAddr = ServerList[iIdx].LHostAddr; | ||
} | ||
else if ( !NetworkUtil::IsPrivateNetworkIP ( InetAddr.InetAddr ) && | ||
NetworkUtil::IsPrivateNetworkIP ( vecServerInfo[iIdx].HostAddr.InetAddr ) && | ||
!NetworkUtil::IsPrivateNetworkIP ( ServerList[iIdx].LHostAddr.InetAddr ) ) | ||
{ | ||
// We've got a request from a public client, the server | ||
// list's entry's primary address is a private address, | ||
// but it supplied an additional public address using | ||
// --serverpublicip. | ||
// In this case, use the latter. | ||
// This is common when running a central server with slave | ||
// servers behind a NAT and dealing with external, public | ||
// clients. | ||
vecServerInfo[iIdx].HostAddr = ServerList[iIdx].LHostAddr; | ||
} | ||
else | ||
{ | ||
// create "send empty message" for all registered servers | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1059,6 +1059,28 @@ QString NetworkUtil::FixAddress ( const QString& strAddress ) | |
return strAddress.simplified().replace ( " ", "" ); | ||
} | ||
|
||
// Return whether the given HostAdress is within a private IP range | ||
// as per RFC 1918 & RFC 5735. | ||
bool NetworkUtil::IsPrivateNetworkIP ( const QHostAddress &qhAddr ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
{ | ||
// https://www.rfc-editor.org/rfc/rfc1918 | ||
// https://www.rfc-editor.org/rfc/rfc5735 | ||
static QList<QPair<QHostAddress, int>> addresses = | ||
{ | ||
QPair<QHostAddress, int> ( QHostAddress ( "10.0.0.0" ), 8 ), | ||
QPair<QHostAddress, int> ( QHostAddress ( "127.0.0.0" ), 8 ), | ||
QPair<QHostAddress, int> ( QHostAddress ( "172.16.0.0" ), 12 ), | ||
QPair<QHostAddress, int> ( QHostAddress ( "192.168.0.0" ), 16 ), | ||
}; | ||
|
||
foreach ( auto item, addresses ) { | ||
if ( qhAddr.isInSubnet ( item ) ) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
|
||
// Instrument picture data base ------------------------------------------------ | ||
CVector<CInstPictures::CInstPictProps>& CInstPictures::GetTable ( const bool bReGenerateTable ) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have any other suggestions how the flag should be called, let me know.