@ -371,15 +371,17 @@ ArgsManager::ArgsManager() :
// nothing to do
}
void ArgsManager : : WarnForSectionOnlyArgs ( )
const std : : set < std : : string > ArgsManager : : GetUnsuitableSectionOnlyArgs ( ) const
{
std : : set < std : : string > unsuitables ;
LOCK ( cs_args ) ;
// if there's no section selected, don't worry
if ( m_network . empty ( ) ) return ;
if ( m_network . empty ( ) ) return std : : set < std : : string > { } ;
// if it's okay to use the default section for this network, don't worry
if ( m_network = = CBaseChainParams : : MAIN ) return ;
if ( m_network = = CBaseChainParams : : MAIN ) return std : : set < std : : string > { } ;
for ( const auto & arg : m_network_only_args ) {
std : : pair < bool , std : : string > found_result ;
@ -397,8 +399,28 @@ void ArgsManager::WarnForSectionOnlyArgs()
if ( ! found_result . first ) continue ;
// otherwise, issue a warning
LogPrintf( " Warning: Config setting for %s only applied on %s network when in [%s] section. \n " , arg , m_network , m_network ) ;
unsuitables. insert ( arg ) ;
}
return unsuitables ;
}
const std : : set < std : : string > ArgsManager : : GetUnrecognizedSections ( ) const
{
// Section names to be recognized in the config file.
static const std : : set < std : : string > available_sections {
CBaseChainParams : : REGTEST ,
CBaseChainParams : : TESTNET ,
CBaseChainParams : : MAIN
} ;
std : : set < std : : string > diff ;
LOCK ( cs_args ) ;
std : : set_difference (
m_config_sections . begin ( ) , m_config_sections . end ( ) ,
available_sections . begin ( ) , available_sections . end ( ) ,
std : : inserter ( diff , diff . end ( ) ) ) ;
return diff ;
}
void ArgsManager : : SelectConfigNetwork ( const std : : string & network )
@ -819,7 +841,7 @@ static std::string TrimString(const std::string& str, const std::string& pattern
return str . substr ( front , end - front + 1 ) ;
}
static bool GetConfigOptions ( std : : istream & stream , std : : string & error , std : : vector < std : : pair < std : : string , std : : string > > & op tions)
static bool GetConfigOptions ( std : : istream & stream , std : : string & error , std : : vector < std : : pair < std : : string , std : : string > > & op tions, std : : set < std : : string > & sec tions)
{
std : : string str , prefix ;
std : : string : : size_type pos ;
@ -834,7 +856,9 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
str = TrimString ( str , pattern ) ;
if ( ! str . empty ( ) ) {
if ( * str . begin ( ) = = ' [ ' & & * str . rbegin ( ) = = ' ] ' ) {
prefix = str . substr ( 1 , str . size ( ) - 2 ) + ' . ' ;
const std : : string section = str . substr ( 1 , str . size ( ) - 2 ) ;
sections . insert ( section ) ;
prefix = section + ' . ' ;
} else if ( * str . begin ( ) = = ' - ' ) {
error = strprintf ( " parse error on line %i: %s, options in configuration file must be specified without leading - " , linenr , str ) ;
return false ;
@ -846,6 +870,9 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
return false ;
}
options . emplace_back ( name , value ) ;
if ( ( pos = name . rfind ( ' . ' ) ) ! = std : : string : : npos ) {
sections . insert ( name . substr ( 0 , pos ) ) ;
}
} else {
error = strprintf ( " parse error on line %i: %s " , linenr , str ) ;
if ( str . size ( ) > = 2 & & str . substr ( 0 , 2 ) = = " no " ) {
@ -863,7 +890,8 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, std::string& error, boo
{
LOCK ( cs_args ) ;
std : : vector < std : : pair < std : : string , std : : string > > options ;
if ( ! GetConfigOptions ( stream , error , options ) ) {
m_config_sections . clear ( ) ;
if ( ! GetConfigOptions ( stream , error , options , m_config_sections ) ) {
return false ;
}
for ( const std : : pair < std : : string , std : : string > & option : options ) {