Skip to content
Snippets Groups Projects
Commit a474c47c authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Fixes for net findOne missing results

parent c8a4d7b7
No related branches found
No related tags found
No related merge requests found
Pipeline #10498 passed
......@@ -298,7 +298,7 @@ int Peer::asyncCall(
// Register the CB
callbacks_[rpcid] = std::make_unique<caller<T>>(cb);
_send();
return rpcid;
}
......
......@@ -126,6 +126,8 @@ class Universe {
bool createResource(const std::string &uri);
std::optional<ftl::UUID> findOwner(const std::string &res);
void setLocalID(const ftl::UUID &u) { this_peer = u; };
private:
void _run();
......@@ -138,6 +140,7 @@ class Universe {
private:
bool active_;
ftl::UUID this_peer;
nlohmann::json config_;
std::mutex net_mutex_;
fd_set sfderror_;
......@@ -199,7 +202,7 @@ std::optional<R> Universe::findOne(const std::string &name, ARGS... args) {
std::map<Peer*, int> record;
for (auto p : peers_) {
record[p] = p->asyncCall<std::optional<R>>(name, handler, std::forward<ARGS>(args)...);
record[p] = p->asyncCall<std::optional<R>>(name, handler, args...);
}
{ // Block thread until async callback notifies us
......
......@@ -18,12 +18,12 @@ using std::optional;
using std::unique_lock;
using std::mutex;
Universe::Universe() : active_(true), thread_(Universe::__start, this) {
Universe::Universe() : active_(true), this_peer(ftl::net::this_peer), thread_(Universe::__start, this) {
_installBindings();
}
Universe::Universe(nlohmann::json &config) :
active_(true), config_(config), thread_(Universe::__start, this) {
active_(true), this_peer(ftl::net::this_peer), config_(config), thread_(Universe::__start, this) {
if (config["listen"].is_array()) {
for (auto &l : config["listen"]) {
listen(l);
......@@ -133,7 +133,7 @@ void Universe::_installBindings() {
bind("__owner__", [this](const std::string &res) -> optional<UUID> {
LOG(INFO) << "SOMEONE ASKS FOR " << res;
if (owned_.count(res) > 0) return ftl::net::this_peer;
if (owned_.count(res) > 0) return this_peer;
else return {};
});
}
......@@ -179,7 +179,7 @@ bool Universe::_subscribe(const std::string &res) {
optional<UUID> pid = findOwner(res);
if (pid) {
return call<bool>(*pid, "__subscribe__", ftl::net::this_peer, res);
return call<bool>(*pid, "__subscribe__", this_peer, res);
} else {
// No resource found
LOG(WARNING) << "Subscribe to unknown resource: " << res;
......@@ -219,7 +219,7 @@ void Universe::_run() {
//Some kind of error occured, it is usually possible to recover from this.
if (selres < 0) {
std::cout << "SELECT ERROR " << selres << std::endl;
std::cout << "SELECT ERROR " << selres << " - " << strerror(errno) << std::endl;
//return false;
continue;
} else if (selres == 0) {
......
......@@ -170,10 +170,23 @@ TEST_CASE("Universe::findOwner()", "") {
SECTION("three peers and one owner") {
Universe c;
c.connect("tcp://localhost:7077");
b.setLocalID(ftl::UUID(7));
while (a.numberOfPeers() < 2) sleep_for(milliseconds(20));
b.createResource("ftl://test");
REQUIRE( *(a.findOwner("ftl://test")) == ftl::net::this_peer );
REQUIRE( *(a.findOwner("ftl://test")) == ftl::UUID(7) );
}
SECTION("three peers and one owner (2)") {
Universe c;
c.connect("tcp://localhost:7077");
c.setLocalID(ftl::UUID(7));
while (a.numberOfPeers() < 2) sleep_for(milliseconds(20));
c.createResource("ftl://test");
auto r = a.findOwner("ftl://test");
REQUIRE( r );
REQUIRE( *r == ftl::UUID(7) );
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment