MCPcopy Create free account
hub / github.com/bitshares/bitshares-core / load_configuration

Method load_configuration

libraries/net/node.cpp:4202–4278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4200 }
4201
4202 void node_impl::load_configuration( const fc::path& configuration_directory )
4203 {
4204 VERIFY_CORRECT_THREAD();
4205 _node_configuration_directory = configuration_directory;
4206 fc::path configuration_file_name( _node_configuration_directory / NODE_CONFIGURATION_FILENAME );
4207 bool node_configuration_loaded = false;
4208 if( fc::exists(configuration_file_name ) )
4209 {
4210 try
4211 {
4212 _node_configuration = fc::json::from_file( configuration_file_name ).as<detail::node_configuration>(GRAPHENE_NET_MAX_NESTED_OBJECTS);
4213 ilog( "Loaded configuration from file ${filename}", ("filename", configuration_file_name ) );
4214
4215 if( _node_configuration.private_key == fc::ecc::private_key() )
4216 _node_configuration.private_key = fc::ecc::private_key::generate();
4217
4218 node_configuration_loaded = true;
4219 }
4220 catch ( fc::parse_error_exception& parse_error )
4221 {
4222 elog( "malformed node configuration file ${filename}: ${error}",
4223 ( "filename", configuration_file_name )("error", parse_error.to_detail_string() ) );
4224 }
4225 catch ( fc::exception& except )
4226 {
4227 elog( "unexpected exception while reading configuration file ${filename}: ${error}",
4228 ( "filename", configuration_file_name )("error", except.to_detail_string() ) );
4229 }
4230 }
4231
4232 if( !node_configuration_loaded )
4233 {
4234 _node_configuration = detail::node_configuration();
4235
4236#ifdef GRAPHENE_TEST_NETWORK
4237 uint32_t port = GRAPHENE_NET_TEST_P2P_PORT;
4238#else
4239 uint32_t port = GRAPHENE_NET_DEFAULT_P2P_PORT;
4240#endif
4241 _node_configuration.listen_endpoint.set_port( port );
4242
4243 ilog( "generating new private key for this node" );
4244 _node_configuration.private_key = fc::ecc::private_key::generate();
4245 save_node_configuration();
4246 }
4247
4248 _node_public_key = _node_configuration.private_key.get_public_key().serialize();
4249
4250 fc::path potential_peer_database_file_name(_node_configuration_directory / POTENTIAL_PEER_DATABASE_FILENAME);
4251 try
4252 {
4253 _potential_peer_db.open(potential_peer_database_file_name);
4254
4255 // push back the time on all peers loaded from the database so we will be able to retry them immediately
4256 // Note: this step is almost useless because we didn't multiply _peer_connection_retry_timeout
4257 // by number_of_failed_connection_attempts. However, it is probably desired as we don't want
4258 // to try to connect to a large number of dead nodes at startup.
4259 // As of writing, _peer_connection_retry_timeout is 30 seconds, pushing the time back that much

Callers 1

application.cppFile · 0.80

Calls 6

serializeMethod · 0.80
update_entryMethod · 0.80
get_public_keyMethod · 0.45
openMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected