Version and allow_unsafe upgrade in ipc config (#1970)
* Version and allow_unsafe upgrade in ipc config * Make test check handle future version upgrades
This commit is contained in:
		
					parent
					
						
							
								0c4fc6e4d9
							
						
					
				
			
			
				commit
				
					
						06a93517d1
					
				
			
		
					 4 changed files with 37 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -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<int> ("version"));
 | 
			
		||||
	ASSERT_FALSE (local2.get<bool> ("allow_unsafe"));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<unsigned> ("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<long> ("io_threads", transport_domain.io_threads, -1);
 | 
			
		||||
		domain_l->get_optional<bool> ("allow_unsafe", transport_domain.allow_unsafe);
 | 
			
		||||
		domain_l->get<bool> ("enable", transport_domain.enabled);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue