commit ac82ae3: [Project] Allow offsets in the hyperscan cache

Vsevolod Stakhov vsevolod at rspamd.com
Tue Oct 25 02:14:04 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-10-24 17:53:10 +0100
URL: https://github.com/rspamd/rspamd/commit/ac82ae305135c1f5d760d522d66ce47c5ccd9cf4 (HEAD -> master)

[Project] Allow offsets in the hyperscan cache

---
 src/libserver/hyperscan_tools.cxx | 6 +++---
 src/libserver/hyperscan_tools.h   | 2 +-
 src/libserver/maps/map_helpers.c  | 2 +-
 src/libutil/multipattern.c        | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/libserver/hyperscan_tools.cxx b/src/libserver/hyperscan_tools.cxx
index 89cc4e23b..8e7fe6083 100644
--- a/src/libserver/hyperscan_tools.cxx
+++ b/src/libserver/hyperscan_tools.cxx
@@ -273,7 +273,7 @@ auto load_cached_hs_file(const char *fname, std::int64_t offset = 0) -> tl::expe
 	auto &hs_cache = hs_known_files_cache::get();
 	const auto *log_func = RSPAMD_LOG_FUNC;
 
-	return raii_mmaped_file::mmap_shared(fname, O_RDONLY, PROT_READ)
+	return raii_mmaped_file::mmap_shared(fname, O_RDONLY, PROT_READ, offset)
 		.and_then([&]<class T>(T &&cached_serialized) -> tl::expected<hs_shared_database, error> {
 #if defined(HS_MAJOR) && defined(HS_MINOR) && HS_MAJOR >= 5 && HS_MINOR >= 4
 			auto unserialized_fname = fmt::format("{}.unser", fname);
@@ -392,9 +392,9 @@ auto load_cached_hs_file(const char *fname, std::int64_t offset = 0) -> tl::expe
 #define C_DB_FROM_CXX(obj) (reinterpret_cast<rspamd_hyperscan_t *>(obj))
 
 rspamd_hyperscan_t *
-rspamd_hyperscan_maybe_load(const char *filename)
+rspamd_hyperscan_maybe_load(const char *filename, goffset offset)
 {
-	auto maybe_db = rspamd::util::load_cached_hs_file(filename);
+	auto maybe_db = rspamd::util::load_cached_hs_file(filename, offset);
 
 	if (maybe_db.has_value()) {
 		auto *ndb = new rspamd::util::hs_shared_database;
diff --git a/src/libserver/hyperscan_tools.h b/src/libserver/hyperscan_tools.h
index 5d50e07ec..e66e2ec91 100644
--- a/src/libserver/hyperscan_tools.h
+++ b/src/libserver/hyperscan_tools.h
@@ -34,7 +34,7 @@ typedef struct rspamd_hyperscan_s rspamd_hyperscan_t;
  * @param filename
  * @return cached database if available
  */
-rspamd_hyperscan_t *rspamd_hyperscan_maybe_load(const char *filename);
+rspamd_hyperscan_t *rspamd_hyperscan_maybe_load(const char *filename, goffset offset);
 
 /**
  * Creates a wrapper for a raw hs db. Ownership is transferred to the enclosing object returned
diff --git a/src/libserver/maps/map_helpers.c b/src/libserver/maps/map_helpers.c
index 8850d052c..9e649414a 100644
--- a/src/libserver/maps/map_helpers.c
+++ b/src/libserver/maps/map_helpers.c
@@ -1073,7 +1073,7 @@ rspamd_try_load_re_map_cache (struct rspamd_regexp_map_helper *re_map)
 			map->cfg->hs_cache_dir,
 			(gint)rspamd_cryptobox_HASHBYTES / 2, re_map->re_digest);
 
-	re_map->hs_db = rspamd_hyperscan_maybe_load(fp);
+	re_map->hs_db = rspamd_hyperscan_maybe_load(fp, 0);
 
 	return re_map->hs_db != NULL;
 }
diff --git a/src/libutil/multipattern.c b/src/libutil/multipattern.c
index dd9a37cec..489ac1beb 100644
--- a/src/libutil/multipattern.c
+++ b/src/libutil/multipattern.c
@@ -408,7 +408,7 @@ rspamd_multipattern_try_load_hs (struct rspamd_multipattern *mp,
 
 	rspamd_snprintf (fp, sizeof (fp), "%s/%*xs.hsmp", hs_cache_dir,
 			(gint)rspamd_cryptobox_HASHBYTES / 2, hash);
-	mp->hs_db = rspamd_hyperscan_maybe_load(fp);
+	mp->hs_db = rspamd_hyperscan_maybe_load(fp, 0);
 
 	return mp->hs_db != NULL;
 }


More information about the Commits mailing list