Commit 52409b7e authored by Dominik Charousset's avatar Dominik Charousset

Reimplement node_id as opaque identifier

parent c58b6a08
...@@ -20,16 +20,16 @@ ...@@ -20,16 +20,16 @@
#include <atomic> #include <atomic>
#include "caf/fwd.hpp" #include "caf/config.hpp"
#include "caf/error.hpp" #include "caf/error.hpp"
#include "caf/node_id.hpp" #include "caf/fwd.hpp"
#include "caf/intrusive_ptr.hpp" #include "caf/intrusive_ptr.hpp"
#include "caf/weak_intrusive_ptr.hpp"
#include "caf/meta/type_name.hpp"
#include "caf/meta/save_callback.hpp"
#include "caf/meta/load_callback.hpp" #include "caf/meta/load_callback.hpp"
#include "caf/meta/omittable_if_none.hpp" #include "caf/meta/omittable_if_none.hpp"
#include "caf/meta/save_callback.hpp"
#include "caf/meta/type_name.hpp"
#include "caf/node_id.hpp"
#include "caf/weak_intrusive_ptr.hpp"
namespace caf { namespace caf {
......
...@@ -40,8 +40,12 @@ std::string to_string(const atom_value& what); ...@@ -40,8 +40,12 @@ std::string to_string(const atom_value& what);
/// @relates atom_value /// @relates atom_value
atom_value to_lowercase(atom_value x); atom_value to_lowercase(atom_value x);
/// @relates atom_value
atom_value atom_from_string(string_view x); atom_value atom_from_string(string_view x);
/// @relates atom_value
int compare(atom_value x, atom_value y);
/// Creates an atom from given string literal. /// Creates an atom from given string literal.
template <size_t Size> template <size_t Size>
constexpr atom_value atom(char const (&str)[Size]) { constexpr atom_value atom(char const (&str)[Size]) {
...@@ -219,4 +223,3 @@ struct hash<caf::atom_value> { ...@@ -219,4 +223,3 @@ struct hash<caf::atom_value> {
}; };
} // namespace std } // namespace std
This diff is collapsed.
...@@ -71,4 +71,8 @@ std::string to_string(const atom_value& x) { ...@@ -71,4 +71,8 @@ std::string to_string(const atom_value& x) {
return std::string(str.begin(), str.begin() + len); return std::string(str.begin(), str.begin() + len);
} }
int compare(atom_value x, atom_value y) {
return memcmp(&x, &y, sizeof(atom_value));
}
} // namespace caf } // namespace caf
This diff is collapsed.
...@@ -541,7 +541,7 @@ void basp_broker::set_context(connection_handle hdl) { ...@@ -541,7 +541,7 @@ void basp_broker::set_context(connection_handle hdl) {
invalid_actor_id}; invalid_actor_id};
i = ctx i = ctx
.emplace(hdl, basp::endpoint_context{basp::await_header, hdr, hdl, .emplace(hdl, basp::endpoint_context{basp::await_header, hdr, hdl,
none, 0, 0, none}) node_id{}, 0, 0, none})
.first; .first;
} }
this_context = &i->second; this_context = &i->second;
......
...@@ -384,8 +384,8 @@ void middleman::init(actor_system_config& cfg) { ...@@ -384,8 +384,8 @@ void middleman::init(actor_system_config& cfg) {
.add_message_type<connection_handle>("@connection_handle") .add_message_type<connection_handle>("@connection_handle")
.add_message_type<connection_passivated_msg>("@connection_passivated_msg") .add_message_type<connection_passivated_msg>("@connection_passivated_msg")
.add_message_type<acceptor_passivated_msg>("@acceptor_passivated_msg"); .add_message_type<acceptor_passivated_msg>("@acceptor_passivated_msg");
// compute and set ID for this network node // Compute and set ID for this network node.
node_id this_node{node_id::data::create_singleton()}; auto this_node = node_id::default_data::local(cfg);
system().node_.swap(this_node); system().node_.swap(this_node);
// give config access to slave mode implementation // give config access to slave mode implementation
cfg.slave_mode_fun = &middleman::exec_slave_mode; cfg.slave_mode_fun = &middleman::exec_slave_mode;
......
...@@ -62,7 +62,7 @@ node_id routing_table::lookup_direct(const connection_handle& hdl) const { ...@@ -62,7 +62,7 @@ node_id routing_table::lookup_direct(const connection_handle& hdl) const {
auto i = direct_by_hdl_.find(hdl); auto i = direct_by_hdl_.find(hdl);
if (i != direct_by_hdl_.end()) if (i != direct_by_hdl_.end())
return i->second; return i->second;
return none; return {};
} }
optional<connection_handle> optional<connection_handle>
...@@ -71,24 +71,24 @@ routing_table::lookup_direct(const node_id& nid) const { ...@@ -71,24 +71,24 @@ routing_table::lookup_direct(const node_id& nid) const {
auto i = direct_by_nid_.find(nid); auto i = direct_by_nid_.find(nid);
if (i != direct_by_nid_.end()) if (i != direct_by_nid_.end())
return i->second; return i->second;
return none; return {};
} }
node_id routing_table::lookup_indirect(const node_id& nid) const { node_id routing_table::lookup_indirect(const node_id& nid) const {
std::unique_lock<std::mutex> guard{mtx_}; std::unique_lock<std::mutex> guard{mtx_};
auto i = indirect_.find(nid); auto i = indirect_.find(nid);
if (i == indirect_.end()) if (i == indirect_.end())
return none; return {};
if (!i->second.empty()) if (!i->second.empty())
return *i->second.begin(); return *i->second.begin();
return none; return {};
} }
node_id routing_table::erase_direct(const connection_handle& hdl) { node_id routing_table::erase_direct(const connection_handle& hdl) {
std::unique_lock<std::mutex> guard{mtx_}; std::unique_lock<std::mutex> guard{mtx_};
auto i = direct_by_hdl_.find(hdl); auto i = direct_by_hdl_.find(hdl);
if (i == direct_by_hdl_.end()) if (i == direct_by_hdl_.end())
return none; return {};
direct_by_nid_.erase(i->second); direct_by_nid_.erase(i->second);
node_id result = std::move(i->second); node_id result = std::move(i->second);
direct_by_hdl_.erase(i->first); direct_by_hdl_.erase(i->first);
......
...@@ -129,12 +129,13 @@ public: ...@@ -129,12 +129,13 @@ public:
registry_ = &sys.registry(); registry_ = &sys.registry();
registry_->put((*self_)->id(), actor_cast<strong_actor_ptr>(*self_)); registry_->put((*self_)->id(), actor_cast<strong_actor_ptr>(*self_));
// first remote node is everything of this_node + 1, then +2, etc. // first remote node is everything of this_node + 1, then +2, etc.
auto pid = static_cast<node_id::default_data&>(*this_node_).process_id();
auto hid = static_cast<node_id::default_data&>(*this_node_).host_id();
for (uint32_t i = 0; i < num_remote_nodes; ++i) { for (uint32_t i = 0; i < num_remote_nodes; ++i) {
auto& n = nodes_[i]; auto& n = nodes_[i];
node_id::host_id_type tmp = this_node_.host_id(); for (auto& c : hid)
for (auto& c : tmp) ++c;
c = static_cast<uint8_t>(c + i + 1); n.id = make_node_id(++pid, hid);
n.id = node_id{this_node_.process_id() + i + 1, tmp};
n.connection = connection_handle::from_int(i + 1); n.connection = connection_handle::from_int(i + 1);
new (&n.dummy_actor) scoped_actor(sys); new (&n.dummy_actor) scoped_actor(sys);
// register all pseudo remote actors in the registry // register all pseudo remote actors in the registry
......
...@@ -84,8 +84,9 @@ struct fixture : test_coordinator_fixture<> { ...@@ -84,8 +84,9 @@ struct fixture : test_coordinator_fixture<> {
fixture() fixture()
: proxies_backend(sys), : proxies_backend(sys),
proxies(sys, proxies_backend), proxies(sys, proxies_backend) {
last_hop(123, "0011223344556677889900112233445566778899") { auto tmp = make_node_id(123, "0011223344556677889900112233445566778899");
last_hop = unbox(std::move(tmp));
testee = sys.spawn<lazy_init>(testee_impl); testee = sys.spawn<lazy_init>(testee_impl);
sys.registry().put(testee.id(), testee); sys.registry().put(testee.id(), testee);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment