aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkenshi84 <kenshi84@protonmail.ch>2016-12-20 13:04:19 +0900
committerkenshi84 <kenshi84@protonmail.ch>2016-12-20 13:04:19 +0900
commit2ac80075444ebac2feef59f98c912342a708606d (patch)
tree3c91949940c438dea8c53b62ae5b1ee16c3f0ad1
parentmoved boost cpp into hpp since they're supposed to be header only (diff)
downloadmonero-2ac80075444ebac2feef59f98c912342a708606d.tar.xz
also use portable serializer for boost_serialization_helper.h and net_node.inl, completely adandon boost/archive/binary_oarchive.hpp
Diffstat (limited to '')
-rw-r--r--src/common/boost_serialization_helper.h25
-rw-r--r--src/cryptonote_core/account.cpp2
-rw-r--r--src/cryptonote_core/blockchain.cpp2
-rw-r--r--src/cryptonote_core/cryptonote_boost_serialization.h1
-rw-r--r--src/p2p/net_node.inl32
-rw-r--r--src/p2p/net_peerlist.h3
-rw-r--r--src/wallet/wallet2.cpp4
7 files changed, 50 insertions, 19 deletions
diff --git a/src/common/boost_serialization_helper.h b/src/common/boost_serialization_helper.h
index c640a1705..fe01532d8 100644
--- a/src/common/boost_serialization_helper.h
+++ b/src/common/boost_serialization_helper.h
@@ -30,8 +30,9 @@
#pragma once
-#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
+#include <boost/archive/portable_binary_oarchive.hpp>
+#include <boost/archive/portable_binary_iarchive.hpp>
namespace tools
@@ -76,7 +77,7 @@ namespace tools
return false;
#endif
- boost::archive::binary_oarchive a(data_file);
+ boost::archive::portable_binary_oarchive a(data_file);
a << obj;
if (data_file.fail())
return false;
@@ -101,9 +102,23 @@ namespace tools
data_file.open( file_path, std::ios_base::binary | std::ios_base::in);
if(data_file.fail())
return false;
- boost::archive::binary_iarchive a(data_file);
-
- a >> obj;
+ try
+ {
+ // first try reading in portable mode
+ boost::archive::portable_binary_iarchive a(data_file);
+ a >> obj;
+ }
+ catch(...)
+ {
+ // if failed, try reading in unportable mode
+ boost::filesystem::copy_file(file_path, file_path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
+ data_file.close();
+ data_file.open( file_path, std::ios_base::binary | std::ios_base::in);
+ if(data_file.fail())
+ return false;
+ boost::archive::binary_iarchive a(data_file);
+ a >> obj;
+ }
return !data_file.fail();
CATCH_ENTRY_L0("unserialize_obj_from_file", false);
}
diff --git a/src/cryptonote_core/account.cpp b/src/cryptonote_core/account.cpp
index c3f2b4446..89ad4184c 100644
--- a/src/cryptonote_core/account.cpp
+++ b/src/cryptonote_core/account.cpp
@@ -28,8 +28,6 @@
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
-#include <boost/archive/binary_oarchive.hpp>
-#include <boost/archive/binary_iarchive.hpp>
#include <fstream>
#include "include_base_utils.h"
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 70b2ccc79..ba369afbd 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -30,8 +30,6 @@
#include <algorithm>
#include <cstdio>
-#include <boost/archive/binary_oarchive.hpp>
-#include <boost/archive/binary_iarchive.hpp>
#include <boost/filesystem.hpp>
#include "include_base_utils.h"
diff --git a/src/cryptonote_core/cryptonote_boost_serialization.h b/src/cryptonote_core/cryptonote_boost_serialization.h
index 9a81ac307..7423b222a 100644
--- a/src/cryptonote_core/cryptonote_boost_serialization.h
+++ b/src/cryptonote_core/cryptonote_boost_serialization.h
@@ -38,7 +38,6 @@
#include <boost/foreach.hpp>
#include <boost/serialization/is_bitwise_serializable.hpp>
#include <boost/archive/binary_iarchive.hpp>
-#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/portable_binary_iarchive.hpp>
#include <boost/archive/portable_binary_oarchive.hpp>
#include "cryptonote_basic.h"
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);
diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h
index c19ecf65f..fa69abd6e 100644
--- a/src/p2p/net_peerlist.h
+++ b/src/p2p/net_peerlist.h
@@ -36,8 +36,9 @@
#include <boost/foreach.hpp>
//#include <boost/bimap.hpp>
//#include <boost/bimap/multiset_of.hpp>
-#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
+#include <boost/archive/portable_binary_oarchive.hpp>
+#include <boost/archive/portable_binary_iarchive.hpp>
#include <boost/serialization/version.hpp>
#include <boost/multi_index_container.hpp>
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index f22410563..e58c31156 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -2318,7 +2318,7 @@ void wallet2::load(const std::string& wallet_, const std::string& password)
catch (...)
{
LOG_PRINT_L0("Failed to open portable binary, trying unportable");
- boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".old", boost::filesystem::copy_option::overwrite_if_exists);
+ boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
iss.str("");
iss << cache_data;
boost::archive::binary_iarchive ar(iss);
@@ -2337,7 +2337,7 @@ void wallet2::load(const std::string& wallet_, const std::string& password)
catch (...)
{
LOG_PRINT_L0("Failed to open portable binary, trying unportable");
- boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".old", boost::filesystem::copy_option::overwrite_if_exists);
+ boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
iss.str("");
iss << buf;
boost::archive::binary_iarchive ar(iss);