From 61d050024f58ce96ae418bd18fd6bef818369a8c Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 3 Oct 2019 16:15:59 -0700 Subject: [PATCH] modules/net_dns_cache: Fix room creation related; various. --- matrix/matrix.cc | 2 +- modules/Makefile.am | 3 ++- modules/net_dns.h | 11 ---------- modules/net_dns_cache.cc | 47 +++++++++++++++++++++++++--------------- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/matrix/matrix.cc b/matrix/matrix.cc index e6fe6c864..2a5c35cb9 100644 --- a/matrix/matrix.cc +++ b/matrix/matrix.cc @@ -35,7 +35,7 @@ IRCD_MODULE_EXPORT_DATA decltype(ircd::m::matrix::module_names) ircd::m::matrix::module_names { - //"net_dns", + "net_dns", "key_query", "key_server", "identity_pubkey", diff --git a/modules/Makefile.am b/modules/Makefile.am index 2df4d4f10..4f9954a81 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -40,10 +40,11 @@ AM_LDFLAGS = \ moduledir = @moduledir@ stats_la_SOURCES = stats.cc -net_dns_la_SOURCES = net_dns_cache.cc net_dns.cc +net_dns_la_SOURCES = net_dns.cc net_dns_cache.cc net_dns_la_CPPFLAGS = -include $(top_srcdir)/include/ircd/asio.h net_dns_la_CPPFLAGS += $(AM_CPPFLAGS) @BOOST_CPPFLAGS@ net_dns_la_LDFLAGS = $(AM_LDFLAGS) @BOOST_LDFLAGS@ +net_dns_la_LDFLAGS += -Wl,--no-gnu-unique console_la_SOURCES = console.cc web_root_la_SOURCES = web_root.cc web_hook_la_SOURCES = web_hook.cc diff --git a/modules/net_dns.h b/modules/net_dns.h index 2c84b8464..a7e8bfbd4 100644 --- a/modules/net_dns.h +++ b/modules/net_dns.h @@ -8,8 +8,6 @@ // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. -#include - namespace ircd::net::dns::cache { struct waiter; @@ -17,18 +15,9 @@ namespace ircd::net::dns::cache bool operator==(const waiter &, const waiter &); bool operator!=(const waiter &, const waiter &); - bool call_waiter(const string_view &, const string_view &, const json::array &, waiter &); - size_t call_waiters(const string_view &, const string_view &, const json::array &); - void handle(const m::event &, m::vm::eval &); - - bool put(const string_view &type, const string_view &state_key, const records &rrs); - bool put(const string_view &type, const string_view &state_key, const uint &code, const string_view &msg); - void fini(); void init(); - extern const m::room::id::buf room_id; - extern m::hookfn hook; extern std::list waiting; extern ctx::mutex mutex; extern ctx::dock dock; diff --git a/modules/net_dns_cache.cc b/modules/net_dns_cache.cc index e74bf9606..acf34ac96 100644 --- a/modules/net_dns_cache.cc +++ b/modules/net_dns_cache.cc @@ -10,19 +10,32 @@ #include "net_dns.h" -decltype(ircd::net::dns::cache::room_id) -ircd::net::dns::cache::room_id +namespace ircd::net::dns::cache { - "dns", my_host() + static bool call_waiter(const string_view &, const string_view &, const json::array &, waiter &); + static size_t call_waiters(const string_view &, const string_view &, const json::array &); + static void handle(const m::event &, m::vm::eval &); + + static bool put(const string_view &type, const string_view &state_key, const records &rrs); + static bool put(const string_view &type, const string_view &state_key, const uint &code, const string_view &msg); + + extern const m::room::id::buf dns_room_id; + extern m::hookfn hook; +} + +decltype(ircd::net::dns::cache::dns_room_id) +ircd::net::dns::cache::dns_room_id +{ + "dns", m::my_host() }; decltype(ircd::net::dns::cache::hook) ircd::net::dns::cache::hook { - handle, + ircd::net::dns::cache::handle, { - { "_site", "vm.effect" }, - { "room_id", string_view{room_id} }, + { "_site", "vm.effect" }, + { "room_id", string_view{dns_room_id} }, } }; @@ -153,11 +166,11 @@ try content.~object(); const m::room room { - room_id + dns_room_id }; if(unlikely(!exists(room))) - create(room); + create(room, m::me(), "internal"); send(room, m::me(), type, state_key, json::object(out.completed())); return true; @@ -286,13 +299,13 @@ try content.~object(); const m::room room { - room_id + dns_room_id }; if(unlikely(!exists(room))) - create(room); + create(room, m::me(), "internal"); - send(room_id, m::me(), type, state_key, json::object{out.completed()}); + send(room, m::me(), type, state_key, json::object{out.completed()}); return true; } catch(const http::error &e) @@ -364,7 +377,7 @@ ircd::net::dns::cache::get(const hostport &hp, const m::room::state state { - room_id + dns_room_id }; const m::event::idx &event_idx @@ -426,7 +439,7 @@ ircd::net::dns::cache::for_each(const hostport &hp, const m::room::state state { - room_id + dns_room_id }; const m::event::idx &event_idx @@ -472,7 +485,7 @@ ircd::net::dns::cache::for_each(const string_view &type, const m::room::state state { - room_id + dns_room_id }; return state.for_each(full_type, [&closure] @@ -690,13 +703,13 @@ try { const m::room room { - m::create(room_id, m::me(), "internal") + m::create(dns_room_id, m::me(), "internal") }; log::debug { m::log, "Created '%s' for the DNS cache module.", - string_view{room.room_id} + string_view{dns_room_id} }; } catch(const std::exception &e) @@ -704,7 +717,7 @@ catch(const std::exception &e) log::critical { m::log, "Creating the '%s' room failed :%s", - string_view{room_id}, + string_view{dns_room_id}, e.what() }; }