SOCK_STREAM /* TCP socket */
};
+const static gdouble default_max_time = 1.0;
+
/*
* Worker's context
*/
struct hs_helper_ctx {
gchar *hs_dir;
+ gdouble max_time;
struct rspamd_config *cfg;
struct event_base *ev_base;
};
ctx->cfg = cfg;
ctx->hs_dir = RSPAMD_DBDIR "/";
+ ctx->max_time = default_max_time;
rspamd_rcl_register_worker_option (cfg, type, "cache_dir",
rspamd_rcl_parse_struct_string, ctx,
G_STRUCT_OFFSET (struct hs_helper_ctx, hs_dir), 0);
+ rspamd_rcl_register_worker_option (cfg, type, "max_time",
+ rspamd_rcl_parse_struct_time, ctx,
+ G_STRUCT_OFFSET (struct hs_helper_ctx, max_time),
+ RSPAMD_CL_FLAG_TIME_FLOAT);
return ctx;
}
}
if ((ncompiled = rspamd_re_cache_compile_hyperscan (ctx->cfg->re_cache,
- ctx->hs_dir,
+ ctx->hs_dir, ctx->max_time,
&err)) == -1) {
msg_err ("failed to compile re cache: %e", err);
g_error_free (err);
#ifdef WITH_HYPERSCAN
static gboolean
rspamd_re_cache_is_finite (struct rspamd_re_cache *cache,
- rspamd_regexp_t *re, gint flags)
+ rspamd_regexp_t *re, gint flags, gdouble max_time)
{
pid_t cld;
gint status;
struct timespec ts;
hs_compile_error_t *hs_errors;
hs_database_t *test_db;
- const double wait_time = 0.1;
+ gdouble wait_time;
const gint max_tries = 10;
gint tries = 0, rc;
+ wait_time = max_time / max_tries;
/* We need to restore SIGCHLD processing */
signal (SIGCHLD, SIG_DFL);
cld = fork ();
gint
rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache,
- const char *cache_dir,
+ const char *cache_dir, gdouble max_time,
GError **err)
{
g_assert (cache != NULL);
&cache->plt,
&test_db,
&hs_errors) != HS_SUCCESS) {
- msg_info_re_cache ("cannot compile %s to hyperscan, try prefilter match",
+ msg_debug_re_cache ("cannot compile %s to hyperscan, try prefilter match",
rspamd_regexp_get_pattern (re));
hs_free_compile_error (hs_errors);
/* The approximation operation might take a significant
* amount of time, so we need to check if it's finite
*/
- if (rspamd_re_cache_is_finite (cache, re, hs_flags[i])) {
+ if (rspamd_re_cache_is_finite (cache, re, hs_flags[i], max_time)) {
hs_flags[i] |= HS_FLAG_PREFILTER;
hs_ids[i] = rspamd_regexp_get_cache_id (re);
hs_pats[i] = rspamd_regexp_get_pattern (re);