Skip to content

Commit 7d9164a

Browse files
committed
Server list persistence for directory servers with --directoryfile command line option
1 parent 3601a10 commit 7d9164a

5 files changed

Lines changed: 361 additions & 115 deletions

File tree

src/main.cpp

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ int main ( int argc, char** argv )
9292
QString strLoggingFileName = "";
9393
QString strRecordingDirName = "";
9494
QString strCentralServer = "";
95+
QString strServerListFileName = "";
9596
QString strServerInfo = "";
9697
QString strServerPublicIP = "";
9798
QString strServerBindIP = "";
@@ -215,6 +216,21 @@ int main ( int argc, char** argv )
215216
continue;
216217
}
217218

219+
// Directory file ------------------------------------------------------
220+
if ( GetStringArgument ( argc,
221+
argv,
222+
i,
223+
"--directoryfile", // no short form
224+
"--directoryfile",
225+
strArgument ) )
226+
{
227+
strServerListFileName = strArgument;
228+
qInfo() << qUtf8Printable ( QString ( "- directory server persistence file: %1" ).arg ( strServerListFileName ) );
229+
CommandLineOptions << "--directoryfile";
230+
ServerOnlyOptions << "--directoryfile";
231+
continue;
232+
}
233+
218234
// Server list filter --------------------------------------------------
219235
if ( GetStringArgument ( argc, argv, i, "-f", "--listfilter", strArgument ) )
220236
{
@@ -587,6 +603,12 @@ int main ( int argc, char** argv )
587603
{
588604
// per definition, we must be a headless server and ignoring inifile, so we have all the information
589605

606+
if ( !strServerListFileName.isEmpty() )
607+
{
608+
qWarning() << "Server list persistence file will only take effect when running as a directory server.";
609+
strServerListFileName = "";
610+
}
611+
590612
if ( !strServerListFilter.isEmpty() )
591613
{
592614
qWarning() << "Server list filter will only take effect when running as a directory server.";
@@ -606,14 +628,48 @@ int main ( int argc, char** argv )
606628
// if we are not headless, certain checks cannot be made, as the inifile state is not yet known
607629
if ( !bUseGUI && strCentralServer.compare ( "localhost", Qt::CaseInsensitive ) != 0 && strCentralServer.compare ( "127.0.0.1" ) != 0 )
608630
{
631+
if ( !strServerListFileName.isEmpty() )
632+
{
633+
qWarning() << "Server list persistence file will only take effect when running as a directory server.";
634+
strServerListFileName = "";
635+
}
636+
609637
if ( !strServerListFilter.isEmpty() )
610638
{
611639
qWarning() << "Server list filter will only take effect when running as a directory server.";
612-
strServerListFilter = "";
640+
strServerListFileName = "";
613641
}
614642
}
615643
else
616644
{
645+
if ( !strServerListFileName.isEmpty() )
646+
{
647+
QFileInfo serverListFileInfo ( strServerListFileName );
648+
if ( !serverListFileInfo.exists() )
649+
{
650+
QFile strServerListFile ( strServerListFileName );
651+
if ( !strServerListFile.open ( QFile::OpenModeFlag::ReadWrite ) )
652+
{
653+
qWarning() << qUtf8Printable (
654+
QString ( "Cannot create %1 for reading and writing. Please check permissions." ).arg ( strServerListFileName ) );
655+
strServerListFileName = "";
656+
}
657+
}
658+
else if ( !serverListFileInfo.isFile() )
659+
{
660+
qWarning() << qUtf8Printable (
661+
QString ( "Server list file %1 must be a plain file. Please check the name." ).arg ( strServerListFileName ) );
662+
strServerListFileName = "";
663+
}
664+
else if ( !serverListFileInfo.isReadable() || !serverListFileInfo.isWritable() )
665+
{
666+
qWarning() << qUtf8Printable (
667+
QString ( "Server list file %1 must be readable and writeable. Please check the permissions." )
668+
.arg ( strServerListFileName ) );
669+
strServerListFileName = "";
670+
}
671+
}
672+
617673
if ( !strServerListFilter.isEmpty() )
618674
{
619675
QStringList slWhitelistAddresses = strServerListFilter.split ( ";" );
@@ -779,6 +835,7 @@ int main ( int argc, char** argv )
779835
iQosNumber,
780836
strHTMLStatusFileName,
781837
strCentralServer,
838+
strServerListFileName,
782839
strServerInfo,
783840
strServerPublicIP,
784841
strServerListFilter,
@@ -885,6 +942,7 @@ QString UsageArguments ( char** argv )
885942
" -d, --discononquit disconnect all clients on quit\n"
886943
" -e, --directoryserver address of the directory server with which to register\n"
887944
" (or 'localhost' to host a server list on this server)\n"
945+
" --directoryfile enable server list persistence, set file name\n"
888946
" -f, --listfilter server list whitelist filter. Format:\n"
889947
" [IP address 1];[IP address 2];[IP address 3]; ...\n"
890948
" -F, --fastupdate use 64 samples frame size mode\n"

src/server.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ CServer::CServer ( const int iNewMaxNumChan,
219219
const quint16 iQosNumber,
220220
const QString& strHTMLStatusFileName,
221221
const QString& strCentralServer,
222+
const QString& strServerListFileName,
222223
const QString& strServerInfo,
223224
const QString& strServerListFilter,
224225
const QString& strServerPublicIP,
@@ -239,7 +240,14 @@ CServer::CServer ( const int iNewMaxNumChan,
239240
bWriteStatusHTMLFile ( false ),
240241
strServerHTMLFileListName ( strHTMLStatusFileName ),
241242
HighPrecisionTimer ( bNUseDoubleSystemFrameSize ),
242-
ServerListManager ( iPortNumber, strCentralServer, strServerInfo, strServerPublicIP, strServerListFilter, iNewMaxNumChan, &ConnLessProtocol ),
243+
ServerListManager ( iPortNumber,
244+
strCentralServer,
245+
strServerListFileName,
246+
strServerInfo,
247+
strServerPublicIP,
248+
strServerListFilter,
249+
iNewMaxNumChan,
250+
&ConnLessProtocol ),
243251
JamController ( this ),
244252
bDisableRecording ( bDisableRecording ),
245253
bAutoRunMinimized ( false ),

src/server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class CServer : public QObject, public CServerSlots<MAX_NUM_CHANNELS>
159159
const quint16 iQosNumber,
160160
const QString& strHTMLStatusFileName,
161161
const QString& strCentralServer,
162+
const QString& strServerListFileName,
162163
const QString& strServerInfo,
163164
const QString& strServerListFilter,
164165
const QString& strServerPublicIP,

0 commit comments

Comments
 (0)