@@ -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 "
0 commit comments