mirror of https://github.com/oxen-io/oxen-mq.git
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.
This commit is contained in:
parent
58e45db996
commit
5d30846cee
|
@ -608,7 +608,9 @@ LokiMQ::proxy_connect_sn(const std::string &remote, const std::string &connect_h
|
||||||
// No connection so establish a new one
|
// No connection so establish a new one
|
||||||
LMQ_LOG(debug, "proxy establishing new outbound connection to ", to_hex(remote));
|
LMQ_LOG(debug, "proxy establishing new outbound connection to ", to_hex(remote));
|
||||||
std::string addr;
|
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
|
// special inproc connection if self that doesn't need any external connection
|
||||||
addr = SN_ADDR_SELF;
|
addr = SN_ADDR_SELF;
|
||||||
} else {
|
} else {
|
||||||
|
@ -981,7 +983,8 @@ void LokiMQ::proxy_loop() {
|
||||||
// Also add an internal connection to self so that calling code can avoid needing to
|
// 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
|
// 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)
|
// 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);
|
add_pollitem(listener);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,11 @@ set(LMQ_TEST_SRC
|
||||||
|
|
||||||
add_executable(tests ${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 14)
|
||||||
set_property(TARGET tests PROPERTY CXX_STANDARD_REQUIRED ON)
|
set_property(TARGET tests PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include <future>
|
#include <future>
|
||||||
|
extern "C" {
|
||||||
|
#include <sodium.h>
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("connections", "[curve][connect]") {
|
|
||||||
|
TEST_CASE("connections", "[connect][curve]") {
|
||||||
std::string listen = "tcp://127.0.0.1:4455";
|
std::string listen = "tcp://127.0.0.1:4455";
|
||||||
LokiMQ server{
|
LokiMQ server{
|
||||||
"", "", // generate ephemeral keys
|
"", "", // 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<unsigned char*>(&pubkey[0]), reinterpret_cast<unsigned char*>(&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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue