]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Allow offsets in the hyperscan cache
authorVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 24 Oct 2022 16:53:10 +0000 (17:53 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 24 Oct 2022 16:53:10 +0000 (17:53 +0100)
src/libserver/hyperscan_tools.cxx
src/libserver/hyperscan_tools.h
src/libserver/maps/map_helpers.c
src/libutil/multipattern.c

index 89cc4e23bccda539a10037d6af5f48286cbb598b..8e7fe6083b6860ff38673235ffc007dd8ccfbe5b 100644 (file)
@@ -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;
index 5d50e07ec9ed00e3bd634f24fc45ae8b657a54fe..e66e2ec91eb9afd0372c8be17c4883e29630bc1d 100644 (file)
@@ -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
index 8850d052ce765556d75f4e45eeafe363144c2a8f..9e649414abca497fee2c541caea7e20b63ba917f 100644 (file)
@@ -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;
 }
index dd9a37cec486f44e827d5092e64cc14b1d0c4475..489ac1beb7949075c0b46b8a4bd79f43be4d2bdc 100644 (file)
@@ -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;
 }