Commit 0a4764f3 authored by Dominik Charousset's avatar Dominik Charousset

Implement local path lookup into the registry

parent f76af85f
......@@ -26,6 +26,7 @@
#include "caf/byte.hpp"
#include "caf/defaults.hpp"
#include "caf/detail/network_order.hpp"
#include "caf/detail/parse.hpp"
#include "caf/error.hpp"
#include "caf/expected.hpp"
#include "caf/net/basp/constants.hpp"
......@@ -34,6 +35,7 @@
#include "caf/none.hpp"
#include "caf/sec.hpp"
#include "caf/serializer_impl.hpp"
#include "caf/string_algorithms.hpp"
#include "caf/type_erased_tuple.hpp"
namespace caf {
......@@ -49,7 +51,24 @@ expected<std::vector<byte>> application::serialize(actor_system& sys,
return result;
}
strong_actor_ptr application::resolve_local_path(string_view) {
strong_actor_ptr application::resolve_local_path(string_view path) {
// We currently support two path formats: `id/<actor_id>` and `name/<atom>`.
static constexpr string_view id_prefix = "id/";
if (starts_with(path, id_prefix)) {
path.remove_prefix(id_prefix.size());
actor_id aid;
if (auto err = detail::parse(path, aid))
return nullptr;
return system().registry().get(aid);
}
static constexpr string_view name_prefix = "name/";
if (starts_with(path, name_prefix)) {
path.remove_prefix(name_prefix.size());
atom_value name;
if (auto err = detail::parse(path, name))
return nullptr;
return system().registry().get(name);
}
return nullptr;
}
......
......@@ -203,7 +203,7 @@ CAF_TEST(resolve request without result) {
handle_handshake();
consume_handshake();
CAF_CHECK_EQUAL(app.state(), basp::connection_state::await_header);
MOCK(basp::message_type::resolve_request, 42, std::string{"/foo/bar"});
MOCK(basp::message_type::resolve_request, 42, std::string{"foo/bar"});
CAF_CHECK_EQUAL(app.state(), basp::connection_state::await_header);
actor_id aid;
std::set<std::string> ifs;
......@@ -212,6 +212,36 @@ CAF_TEST(resolve request without result) {
CAF_CHECK(ifs.empty());
}
CAF_TEST(resolve request on id with result) {
handle_handshake();
consume_handshake();
sys.registry().put(self->id(), self);
auto path = "id/" + std::to_string(self->id());
CAF_CHECK_EQUAL(app.state(), basp::connection_state::await_header);
MOCK(basp::message_type::resolve_request, 42, path);
CAF_CHECK_EQUAL(app.state(), basp::connection_state::await_header);
actor_id aid;
std::set<std::string> ifs;
RECEIVE(basp::message_type::resolve_response, 42u, aid, ifs);
CAF_CHECK_EQUAL(aid, self->id());
CAF_CHECK(ifs.empty());
}
CAF_TEST(resolve request on name with result) {
handle_handshake();
consume_handshake();
sys.registry().put(atom("foo"), self);
std::string path = "name/foo";
CAF_CHECK_EQUAL(app.state(), basp::connection_state::await_header);
MOCK(basp::message_type::resolve_request, 42, path);
CAF_CHECK_EQUAL(app.state(), basp::connection_state::await_header);
actor_id aid;
std::set<std::string> ifs;
RECEIVE(basp::message_type::resolve_response, 42u, aid, ifs);
CAF_CHECK_EQUAL(aid, self->id());
CAF_CHECK(ifs.empty());
}
CAF_TEST(heartbeat message) {
handle_handshake();
consume_handshake();
......
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