diff options
author | Riccardo Spagni <ric@spagni.net> | 2016-12-20 17:40:11 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2016-12-20 17:40:11 +0200 |
commit | b9b9028e50e647073f55a8f32696ff593bc2fc16 (patch) | |
tree | 97376d7c253230f28821ddd9ccb2e3b65df29990 /src/p2p/net_node.inl | |
parent | Merge pull request #1464 (diff) | |
parent | support importing unportable outputs (diff) | |
download | monero-b9b9028e50e647073f55a8f32696ff593bc2fc16.tar.xz |
Merge pull request #1462
07b9138c support importing unportable outputs (kenshi84)
2ac80075 also use portable serializer for boost_serialization_helper.h and net_node.inl, completely adandon boost/archive/binary_oarchive.hpp (kenshi84)
d1d6e27a moved boost cpp into hpp since they're supposed to be header only (kenshi84)
66e6af89 added experimental boost::archive::portable_binary_{i|o}archive (kenshi84)
Diffstat (limited to 'src/p2p/net_node.inl')
-rw-r--r-- | src/p2p/net_node.inl | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 442c42517..f32e7a435 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -137,14 +137,34 @@ namespace nodetool { try { - boost::archive::binary_iarchive a(p2p_data); + // first try reading in portable mode + boost::archive::portable_binary_iarchive a(p2p_data); a >> *this; } - catch (const std::exception &e) + catch (...) { - LOG_ERROR("Failed to load p2p config file, falling back to default config"); - m_peerlist = peerlist_manager(); // it was probably half clobbered by the failed load - make_default_config(); + // if failed, try reading in unportable mode + boost::filesystem::copy_file(state_file_path, state_file_path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists); + p2p_data.close(); + p2p_data.open( state_file_path , std::ios_base::binary | std::ios_base::in); + if(!p2p_data.fail()) + { + try + { + boost::archive::binary_iarchive a(p2p_data); + a >> *this; + } + catch (const std::exception &e) + { + LOG_ERROR("Failed to load p2p config file, falling back to default config"); + m_peerlist = peerlist_manager(); // it was probably half clobbered by the failed load + make_default_config(); + } + } + else + { + make_default_config(); + } } }else { @@ -645,7 +665,7 @@ namespace nodetool return false; }; - boost::archive::binary_oarchive a(p2p_data); + boost::archive::portable_binary_oarchive a(p2p_data); a << *this; return true; CATCH_ENTRY_L0("blockchain_storage::save", false); |