diff --git a/nano/core_test/ipc.cpp b/nano/core_test/ipc.cpp index a60fc9273..668d706f2 100644 --- a/nano/core_test/ipc.cpp +++ b/nano/core_test/ipc.cpp @@ -86,3 +86,22 @@ TEST (ipc, synchronous) ASSERT_NO_ERROR (system.poll ()); } } + +TEST (ipc, config_upgrade_v0_v1) +{ + auto path1 (nano::unique_path ()); + auto path2 (nano::unique_path ()); + nano::ipc::ipc_config config1; + nano::ipc::ipc_config config2; + nano::jsonconfig tree; + config1.serialize_json (tree); + nano::jsonconfig local = tree.get_required_child ("local"); + local.erase ("version"); + local.erase ("allow_unsafe"); + bool upgraded (false); + ASSERT_FALSE (config2.deserialize_json (upgraded, tree)); + nano::jsonconfig local2 = tree.get_required_child ("local"); + ASSERT_TRUE (upgraded); + ASSERT_LE (1, local2.get ("version")); + ASSERT_FALSE (local2.get ("allow_unsafe")); +} diff --git a/nano/node/ipcconfig.cpp b/nano/node/ipcconfig.cpp index 7b5323c2b..7a5e337b1 100644 --- a/nano/node/ipcconfig.cpp +++ b/nano/node/ipcconfig.cpp @@ -15,6 +15,7 @@ nano::error nano::ipc::ipc_config::serialize_json (nano::jsonconfig & json) cons json.put_child ("tcp", tcp_l); nano::jsonconfig domain_l; + domain_l.put ("version", transport_domain.json_version ()); if (transport_domain.io_threads >= 0) { domain_l.put ("io_threads", transport_domain.io_threads); @@ -27,7 +28,7 @@ nano::error nano::ipc::ipc_config::serialize_json (nano::jsonconfig & json) cons return json.get_error (); } -nano::error nano::ipc::ipc_config::deserialize_json (nano::jsonconfig & json) +nano::error nano::ipc::ipc_config::deserialize_json (bool & upgraded_a, nano::jsonconfig & json) { auto tcp_l (json.get_optional_child ("tcp")); if (tcp_l) @@ -42,6 +43,15 @@ nano::error nano::ipc::ipc_config::deserialize_json (nano::jsonconfig & json) auto domain_l (json.get_optional_child ("local")); if (domain_l) { + auto version_l (domain_l->get_optional ("version")); + if (!version_l) + { + version_l = 1; + domain_l->put ("version", *version_l); + domain_l->put ("allow_unsafe", transport_domain.allow_unsafe); + upgraded_a = true; + } + domain_l->get_optional ("io_threads", transport_domain.io_threads, -1); domain_l->get_optional ("allow_unsafe", transport_domain.allow_unsafe); domain_l->get ("enable", transport_domain.enabled); diff --git a/nano/node/ipcconfig.hpp b/nano/node/ipcconfig.hpp index 6485a3fad..e1978e73b 100644 --- a/nano/node/ipcconfig.hpp +++ b/nano/node/ipcconfig.hpp @@ -30,6 +30,11 @@ namespace ipc * this value will be conditional on OS. */ std::string path{ "/tmp/nano" }; + + int json_version () const + { + return 1; + } }; /** TCP specific transport config */ @@ -49,7 +54,7 @@ namespace ipc class ipc_config { public: - nano::error deserialize_json (nano::jsonconfig & json_a); + nano::error deserialize_json (bool & upgraded_a, nano::jsonconfig & json_a); nano::error serialize_json (nano::jsonconfig & json) const; ipc_config_domain_socket transport_domain; ipc_config_tcp_socket transport_tcp; diff --git a/nano/node/nodeconfig.cpp b/nano/node/nodeconfig.cpp index a93aa5d0a..ac5e56e89 100644 --- a/nano/node/nodeconfig.cpp +++ b/nano/node/nodeconfig.cpp @@ -371,7 +371,7 @@ nano::error nano::node_config::deserialize_json (bool & upgraded_a, nano::jsonco auto ipc_config_l (json.get_optional_child ("ipc")); if (ipc_config_l) { - ipc_config.deserialize_json (ipc_config_l.get ()); + ipc_config.deserialize_json (upgraded_a, ipc_config_l.get ()); } auto websocket_config_l (json.get_optional_child ("websocket")); if (websocket_config_l)