diff --git a/lokimq/lokimq.cpp b/lokimq/lokimq.cpp index c1d23e6..d1ebfbe 100644 --- a/lokimq/lokimq.cpp +++ b/lokimq/lokimq.cpp @@ -178,8 +178,8 @@ void extract_pubkey(zmq::message_t& msg, std::string& pubkey, bool& service_node if (pubkey_hex.size() != 64) throw std::logic_error("bad user-id"); assert(is_hex(pubkey_hex.begin(), pubkey_hex.end())); - pubkey.reserve(32); - from_hex(pubkey_hex.begin() + 2, pubkey_hex.end(), std::back_inserter(pubkey)); + pubkey.resize(32, 0); + from_hex(pubkey_hex.begin(), pubkey_hex.end(), pubkey.begin()); service_node = false; try { @@ -439,6 +439,8 @@ void LokiMQ::worker_thread(unsigned int index) { message.service_node = run.service_node; message.data.clear(); + LMQ_TRACE("Got incoming command from pubkey ", to_hex(message.pubkey), " (SN=", (int) message.service_node, ")"); + if (run.callback->second /*is_request*/) { message.reply_tag = {run.data_parts[0].data(), run.data_parts[0].size()}; for (auto it = run.data_parts.begin() + 1; it != run.data_parts.end(); ++it) @@ -1568,7 +1570,7 @@ void LokiMQ::process_zap_requests(zmq::socket_t &zap_auth) { } LMQ_LOG(info, "Accepted incoming ", (sn ? "service node" : "non-SN client"), " connection with authentication level ", to_string(result.auth), - " from ", string_view{&user_id[2], user_id.size()-2}, " at ", ip); + " from ", user_id, " at ", ip); auto& metadata = response_vals[5]; if (result.remote_sn) diff --git a/tests/test_commands.cpp b/tests/test_commands.cpp index 0f72462..37d7533 100644 --- a/tests/test_commands.cpp +++ b/tests/test_commands.cpp @@ -23,6 +23,11 @@ TEST_CASE("basic commands", "[commands]") { if (hellos++ % 2 == 0) m.send_back("public.hi"); }); + std::string client_pubkey; + server.add_command("public", "client.pubkey", [&](Message& m) { + client_pubkey = m.pubkey; + }); + server.start(); LokiMQ client{ @@ -54,9 +59,12 @@ TEST_CASE("basic commands", "[commands]") { REQUIRE( pubkey == server.get_pubkey() ); client.send(pubkey, "public.hello"); + client.send(pubkey, "public.client.pubkey"); + std::this_thread::sleep_for(50ms); REQUIRE( hellos == 1 ); REQUIRE( his == 1 ); + REQUIRE( client_pubkey == client.get_pubkey() ); for (int i = 0; i < 50; i++) client.send(pubkey, "public.hello");