From 5d30846cee070f10ee784073e697d41238bed3b2 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Mon, 17 Feb 2020 17:59:01 -0400 Subject: [PATCH] Disable non-working self-connection inproc socket This was meant to be an optimization but doesn't actually work because we don't do a ZAP request at all when connecting inproc sockets, so the metadata we need never gets set. Remove it so a SN can still connect to itself. --- lokimq/lokimq.cpp | 7 +++++-- tests/CMakeLists.txt | 6 +++++- tests/test_connect.cpp | 38 +++++++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/lokimq/lokimq.cpp b/lokimq/lokimq.cpp index d1ebfbe..f138b08 100644 --- a/lokimq/lokimq.cpp +++ b/lokimq/lokimq.cpp @@ -608,7 +608,9 @@ LokiMQ::proxy_connect_sn(const std::string &remote, const std::string &connect_h // No connection so establish a new one LMQ_LOG(debug, "proxy establishing new outbound connection to ", to_hex(remote)); std::string addr; - if (remote == pubkey) { + bool to_self = false && remote == pubkey; // FIXME; need to use a separate listening socket for this, otherwise we can't easily + // tell it wasn't from a remote. + if (to_self) { // special inproc connection if self that doesn't need any external connection addr = SN_ADDR_SELF; } else { @@ -981,7 +983,8 @@ void LokiMQ::proxy_loop() { // Also add an internal connection to self so that calling code can avoid needing to // special-case rare situations where we are supposed to talk to a quorum member that happens to // be ourselves (which can happen, for example, with cross-quoum Blink communication) - listener.bind(SN_ADDR_SELF); + // FIXME: not working + //listener.bind(SN_ADDR_SELF); add_pollitem(listener); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1604ae7..c3d7497 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,7 +11,11 @@ set(LMQ_TEST_SRC add_executable(tests ${LMQ_TEST_SRC}) -target_link_libraries(tests Catch2::Catch2 lokimq) +find_package(Threads) +find_package(PkgConfig REQUIRED) +pkg_check_modules(SODIUM REQUIRED libsodium) + +target_link_libraries(tests Catch2::Catch2 lokimq ${SODIUM_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) set_property(TARGET tests PROPERTY CXX_STANDARD 14) set_property(TARGET tests PROPERTY CXX_STANDARD_REQUIRED ON) diff --git a/tests/test_connect.cpp b/tests/test_connect.cpp index 4319792..9c37eb7 100644 --- a/tests/test_connect.cpp +++ b/tests/test_connect.cpp @@ -1,7 +1,11 @@ #include "common.h" #include +extern "C" { +#include +} -TEST_CASE("connections", "[curve][connect]") { + +TEST_CASE("connections", "[connect][curve]") { std::string listen = "tcp://127.0.0.1:4455"; LokiMQ server{ "", "", // generate ephemeral keys @@ -46,3 +50,35 @@ TEST_CASE("connections", "[curve][connect]") { } +TEST_CASE("self-connection SN optimization", "[connect][self]") { + std::string pubkey, privkey; + pubkey.resize(crypto_box_PUBLICKEYBYTES); + privkey.resize(crypto_box_SECRETKEYBYTES); + crypto_box_keypair(reinterpret_cast(&pubkey[0]), reinterpret_cast(&privkey[0])); + LokiMQ sn{ + pubkey, privkey, + true, + {"tcp://127.0.0.1:5544"}, + [&](auto pk) { if (pk == pubkey) return "tcp://127.0.0.1:5544"; else return ""; }, + [&](auto ip, auto pk) { REQUIRE(ip == "127.0.0.1"); return Allow{AuthLevel::none, pk == pubkey}; }, + get_logger("S» ") + }; + + sn.add_category("a", Access{AuthLevel::none}); + bool invoked = false; + sn.add_command("a", "b", [&](const Message& m) { + invoked = true; + auto lock = catch_lock(); + REQUIRE(m.pubkey == pubkey); + REQUIRE(m.service_node); + REQUIRE(!m.data.empty()); + REQUIRE(m.data[0] == "my data"); + }); + sn.log_level(LogLevel::trace); + + sn.start(); + std::this_thread::sleep_for(50ms); + sn.send(pubkey, "a.b", "my data"); + std::this_thread::sleep_for(50ms); + REQUIRE(invoked); +}