commit cafe81d: [Minor] Save list of children for normal symbols with dependent virtual symbols

Vsevolod Stakhov vsevolod at rspamd.com
Tue Jul 5 19:35:03 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-07-05 20:08:22 +0100
URL: https://github.com/rspamd/rspamd/commit/cafe81d7579cdeb3507a0485dea42ef8ec27ec3d

[Minor] Save list of children for normal symbols with dependent virtual symbols

---
 src/libserver/symcache/symcache_impl.cxx     |  7 +++++++
 src/libserver/symcache/symcache_item.hxx     | 20 ++++++++++++++++++++
 src/libserver/symcache/symcache_periodic.hxx |  1 -
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/libserver/symcache/symcache_impl.cxx b/src/libserver/symcache/symcache_impl.cxx
index 52a2042b1..7a6878faa 100644
--- a/src/libserver/symcache/symcache_impl.cxx
+++ b/src/libserver/symcache/symcache_impl.cxx
@@ -688,12 +688,19 @@ auto symcache::add_virtual_symbol(std::string_view name, int parent_id, enum rsp
 		return -1;
 	}
 
+	if (items_by_id.size() < parent_id) {
+		msg_err_cache("parent id %d is out of bounds for virtual symbol %s", parent_id, name.data());
+		return -1;
+	}
+
 	auto id = items_by_id.size();
 
 	auto item = cache_item::create_with_virtual(static_pool,
 			id,
 			std::string{name},
 			parent_id, real_type_pair.first, real_type_pair.second);
+	auto &parent = items_by_id[parent_id];
+	parent->add_child(item);
 	items_by_symbol[item->get_name()] = item;
 	get_item_specific_vector(*item).push_back(item);
 	items_by_id.push_back(item);
diff --git a/src/libserver/symcache/symcache_item.hxx b/src/libserver/symcache/symcache_item.hxx
index 70203770a..2c2072fd3 100644
--- a/src/libserver/symcache/symcache_item.hxx
+++ b/src/libserver/symcache/symcache_item.hxx
@@ -110,6 +110,7 @@ class normal_item {
 private:
 	symbol_func_t func;
 	void *user_data;
+	std::vector<cache_item_ptr> virtual_children;
 	std::vector<item_condition> conditions;
 public:
 	explicit normal_item(symbol_func_t _func, void *_user_data) : func(_func), user_data(_user_data)
@@ -134,6 +135,10 @@ public:
 	auto get_cbdata() const -> auto {
 		return user_data;
 	}
+
+	auto add_child(const cache_item_ptr &ptr) -> void {
+		virtual_children.push_back(ptr);
+	}
 };
 
 class virtual_item {
@@ -395,6 +400,21 @@ public:
 	 */
 	auto get_augmentation_weight() const -> int;
 
+	/**
+	 * Add a virtual symbol as a child of some normal symbol
+	 * @param ptr
+	 */
+	auto add_child(const cache_item_ptr &ptr) -> void {
+		if (std::holds_alternative<normal_item>(specific)) {
+			auto &filter_data = std::get<normal_item>(specific);
+
+			filter_data.add_child(ptr);
+		}
+		else {
+			g_assert("add child is called for a virtual symbol!");
+		}
+	}
+
 private:
 	/**
 	 * Constructor for a normal symbols with callback
diff --git a/src/libserver/symcache/symcache_periodic.hxx b/src/libserver/symcache/symcache_periodic.hxx
index 2719fca25..31c94c413 100644
--- a/src/libserver/symcache/symcache_periodic.hxx
+++ b/src/libserver/symcache/symcache_periodic.hxx
@@ -63,7 +63,6 @@ public:
 
 	static void resort_cb(EV_P_ ev_timer *w, int _revents) {
 		auto *cbdata = (struct cache_refresh_cbdata *)w->data;
-		static const double decay_rate = 0.25;
 
 		auto log_tag = [&]() { return cbdata->cache->log_tag(); };
 


More information about the Commits mailing list