static gchar *user_agent = "rspamc";
static GList *children;
static GPatternSpec **exclude_compiled = NULL;
+static struct rspamd_http_context *http_ctx;
static gint retcode = EXIT_SUCCESS;
}
- conn = rspamd_client_init (ev_base, hostbuf, port, timeout, key);
+ conn = rspamd_client_init (http_ctx, ev_base, hostbuf, port, timeout, key);
if (conn != NULL) {
cbdata = g_malloc0 (sizeof (struct rspamc_callback_data));
rspamd_init_libs ();
ev_base = event_base_new ();
+ struct rspamd_http_context_cfg http_config;
+
+ memset (&http_config, 0, sizeof (http_config));
+ http_config.kp_cache_size_client = 32;
+ http_config.kp_cache_size_server = 0;
+ http_config.user_agent = user_agent;
+ http_ctx = rspamd_http_context_create_config (&http_config,
+ ev_base);
+
/* Ignore sigpipe */
sigemptyset (&sigpipe_act.sa_mask);
sigaddset (&sigpipe_act.sa_mask, SIGPIPE);
}
struct rspamd_client_connection *
-rspamd_client_init (struct event_base *ev_base, const gchar *name,
- guint16 port, gdouble timeout, const gchar *key)
+rspamd_client_init (struct rspamd_http_context *http_ctx,
+ struct event_base *ev_base, const gchar *name,
+ guint16 port, gdouble timeout, const gchar *key)
{
struct rspamd_client_connection *conn;
gint fd;
conn->ev_base = ev_base;
conn->fd = fd;
conn->req_sent = FALSE;
- conn->keys_cache = rspamd_keypair_cache_new (32);
- conn->http_conn = rspamd_http_connection_new (rspamd_client_body_handler,
+ conn->http_conn = rspamd_http_connection_new (http_ctx,
+ rspamd_client_body_handler,
rspamd_client_error_handler,
rspamd_client_finish_handler,
0,
- RSPAMD_HTTP_CLIENT,
- conn->keys_cache,
- NULL);
+ RSPAMD_HTTP_CLIENT);
conn->server_name = g_string_new (name);
if (port != 0) {
gdouble send_time,
GError *err);
+struct rspamd_http_context;
/**
* Start rspamd worker or controller command
* @param ev_base event base
* @return
*/
struct rspamd_client_connection * rspamd_client_init (
- struct event_base *ev_base,
- const gchar *name,
- guint16 port,
- gdouble timeout,
- const gchar *key);
+ struct rspamd_http_context *http_ctx,
+ struct event_base *ev_base,
+ const gchar *name,
+ guint16 port,
+ gdouble timeout,
+ const gchar *key);
/**
*
rspamd_ftok_t cached_password;
rspamd_ftok_t cached_enable_password;
/* HTTP server */
+ struct rspamd_http_context *http_ctx;
struct rspamd_http_connection_router *http;
/* Server's start time */
time_t start_time;
GHashTableIter iter;
gpointer key, value;
guint i;
- struct rspamd_keypair_cache *cache;
struct timeval stv;
const guint save_stats_interval = 60 * 1000; /* 1 minute */
gpointer m;
"password");
/* Accept event */
- cache = rspamd_keypair_cache_new (256);
+ ctx->http_ctx = rspamd_http_context_create (ctx->cfg, ctx->ev_base);
ctx->http = rspamd_http_router_new (rspamd_controller_error_handler,
- rspamd_controller_finish_handler, &ctx->io_tv, ctx->ev_base,
- ctx->static_files_dir, cache);
+ rspamd_controller_finish_handler, &ctx->io_tv,
+ ctx->static_files_dir, ctx->http_ctx);
/* Add callbacks for different methods */
rspamd_http_router_add_path (ctx->http,
g_hash_table_unref (ctx->plugins);
g_hash_table_unref (ctx->custom_commands);
+ rspamd_http_context_free (ctx->http_ctx);
REF_RELEASE (ctx->cfg);
rspamd_log_close (worker->srv->logger, TRUE);
struct rspamd_cryptobox_keypair *collection_keypair;
struct rspamd_cryptobox_pubkey *collection_sign_key;
gchar *collection_id_file;
+ struct rspamd_http_context *http_ctx;
struct rspamd_keypair_cache *keypair_cache;
rspamd_lru_hash_t *errors_ips;
rspamd_lru_hash_t *ratelimit_buckets;
msg = rspamd_http_new_message (HTTP_REQUEST);
rspamd_printf_fstring (&msg->url, "/update_v1/%s", m->name);
- conn->http_conn = rspamd_http_connection_new (NULL,
+ conn->http_conn = rspamd_http_connection_new (
+ ctx->http_ctx,
+ NULL,
fuzzy_mirror_error_handler,
fuzzy_mirror_finish_handler,
RSPAMD_HTTP_CLIENT_SIMPLE,
- RSPAMD_HTTP_CLIENT,
- ctx->keypair_cache,
- NULL);
+ RSPAMD_HTTP_CLIENT);
rspamd_http_connection_set_key (conn->http_conn,
ctx->sync_keypair);
session->name = rspamd_inet_address_to_string (addr);
rspamd_random_hex (session->uid, sizeof (session->uid) - 1);
session->uid[sizeof (session->uid) - 1] = '\0';
- http_conn = rspamd_http_connection_new (NULL,
+ http_conn = rspamd_http_connection_new (
+ ctx->http_ctx,
+ NULL,
rspamd_fuzzy_mirror_error_handler,
rspamd_fuzzy_mirror_finish_handler,
0,
- RSPAMD_HTTP_SERVER,
- ctx->keypair_cache,
- NULL);
+ RSPAMD_HTTP_SERVER);
rspamd_http_connection_set_key (http_conn, ctx->sync_keypair);
session->ctx = ctx;
ctx->keypair_cache = rspamd_keypair_cache_new (ctx->keypair_cache_size);
}
+ ctx->http_ctx = rspamd_http_context_create (cfg, ctx->ev_base);
+
if (!ctx->collection_mode) {
/*
* Open DB and perform VACUUM
rspamd_fuzzy_collection_error_handler,
rspamd_fuzzy_collection_finish_handler,
&ctx->stat_tv,
- ctx->ev_base,
- NULL, ctx->keypair_cache);
+ NULL,
+ ctx->http_ctx);
if (ctx->collection_keypair) {
rspamd_http_router_set_key (ctx->collection_rt,
else if (worker->index == 0) {
gint fd;
- /* Steal keypairs cache... */
- ctx->collection_rt->cache = NULL;
rspamd_http_router_free (ctx->collection_rt);
/* Try to save collection id */
rspamd_keypair_cache_destroy (ctx->keypair_cache);
}
+ rspamd_http_context_free (ctx->http_ctx);
REF_RELEASE (ctx->cfg);
-
rspamd_log_close (worker->srv->logger, TRUE);
exit (EXIT_SUCCESS);
param->url = url;
param->task = task;
param->conn = rspamd_http_connection_new (NULL,
+ NULL,
surbl_redirector_error,
surbl_redirector_finish,
RSPAMD_HTTP_CLIENT_SIMPLE,
- RSPAMD_HTTP_CLIENT,
- NULL,
- NULL);
+ RSPAMD_HTTP_CLIENT);
param->ctx = surbl_module_ctx;
msg = rspamd_http_new_message (HTTP_REQUEST);
msg->url = rspamd_fstring_assign (msg->url, url->string, url->urllen);
exit (1);
}
- conn = rspamd_http_connection_new (NULL,
+ conn = rspamd_http_connection_new (
+ NULL, /* Default context */
+ NULL,
rspamd_control_error_handler,
rspamd_control_finish_handler,
RSPAMD_HTTP_CLIENT_SIMPLE,
- RSPAMD_HTTP_CLIENT,
- NULL,
- NULL);
+ RSPAMD_HTTP_CLIENT);
msg = rspamd_http_new_message (HTTP_REQUEST);
msg->url = rspamd_fstring_new_init (path, strlen (path));
double_to_tv (timeout, &tv);
ctx = g_malloc0 (sizeof (*ctx));
http = rspamd_http_router_new (rspamadm_lua_error_handler,
rspamadm_lua_finish_handler,
- NULL, ev_base,
- NULL, NULL);
+ NULL,
+ NULL,
+ rspamd_main->http_ctx);
ctx->L = L;
ctx->rt = http;
rspamd_http_router_add_path (http,
(void) dns_resolver_init (rspamd_main->logger,
rspamd_main->ev_base,
cfg);
+ rspamd_main->http_ctx = rspamd_http_context_create (cfg, rspamd_main->ev_base);
g_log_set_default_handler (rspamd_glib_log_function, rspamd_main->logger);
g_set_printerr_handler (rspamd_glib_printerr_function);
gboolean cores_throttling; /**< turn off cores when limits are exceeded */
struct roll_history *history; /**< rolling history */
struct event_base *ev_base;
+ struct rspamd_http_context *http_ctx;
};
enum rspamd_exception_type {
struct timeval io_tv;
/* Encryption key for clients */
struct rspamd_cryptobox_keypair *key;
- /* Keys cache */
- struct rspamd_keypair_cache *keys_cache;
+ /* HTTP context */
+ struct rspamd_http_context *http_ctx;
/* Upstreams to use */
GHashTable *upstreams;
/* Mirrors to send traffic to */
GPtrArray *mirrors;
/* Default upstream */
struct rspamd_http_upstream *default_upstream;
- /* Local rotating keypair for upstreams */
- struct rspamd_cryptobox_keypair *local_key;
- struct event rotate_ev;
- gdouble rotate_tm;
lua_State *lua_state;
/* Array of callback functions called on end of scan to compare results */
GArray *cmp_refs;
ctx->mirrors = g_ptr_array_new ();
rspamd_mempool_add_destructor (cfg->cfg_pool,
(rspamd_mempool_destruct_t)rspamd_ptr_array_free_hard, ctx->mirrors);
- ctx->rotate_tm = DEFAULT_ROTATION_TIME;
ctx->cfg = cfg;
ctx->lua_state = cfg->lua_state;
ctx->cmp_refs = g_array_new (FALSE, FALSE, sizeof (gint));
G_STRUCT_OFFSET (struct rspamd_proxy_ctx, timeout),
RSPAMD_CL_FLAG_TIME_FLOAT,
"IO timeout");
- rspamd_rcl_register_worker_option (cfg,
- type,
- "rotate",
- rspamd_rcl_parse_struct_time,
- ctx,
- G_STRUCT_OFFSET (struct rspamd_proxy_ctx, rotate_tm),
- RSPAMD_CL_FLAG_TIME_FLOAT,
- "Rotation keys time, default: "
- G_STRINGIFY (DEFAULT_ROTATION_TIME) " seconds");
rspamd_rcl_register_worker_option (cfg,
type,
"keypair",
rspamd_http_message_add_header (msg, "Settings-ID", m->settings_id);
}
- bk_conn->backend_conn = rspamd_http_connection_new (NULL,
+ bk_conn->backend_conn = rspamd_http_connection_new (
+ session->ctx->http_ctx,
+ NULL,
proxy_backend_mirror_error_handler,
proxy_backend_mirror_finish_handler,
RSPAMD_HTTP_CLIENT_SIMPLE,
- RSPAMD_HTTP_CLIENT,
- session->ctx->keys_cache,
- NULL);
+ RSPAMD_HTTP_CLIENT);
if (m->key) {
- rspamd_http_connection_set_key (bk_conn->backend_conn,
- session->ctx->local_key);
msg->peer_key = rspamd_pubkey_ref (m->key);
}
}
session->master_conn->backend_conn = rspamd_http_connection_new (
+ session->ctx->http_ctx,
NULL,
proxy_backend_master_error_handler,
proxy_backend_master_finish_handler,
RSPAMD_HTTP_CLIENT_SIMPLE,
- RSPAMD_HTTP_CLIENT,
- session->ctx->keys_cache,
- NULL);
+ RSPAMD_HTTP_CLIENT);
session->master_conn->flags &= ~RSPAMD_BACKEND_CLOSED;
session->master_conn->parser_from_ref = backend->parser_from_ref;
session->master_conn->parser_to_ref = backend->parser_to_ref;
if (backend->key) {
msg->peer_key = rspamd_pubkey_ref (backend->key);
- rspamd_http_connection_set_key (session->master_conn->backend_conn,
- session->ctx->local_key);
}
if (backend->settings_id != NULL) {
}
if (!ctx->milter) {
- session->client_conn = rspamd_http_connection_new (NULL,
+ session->client_conn = rspamd_http_connection_new (
+ ctx->http_ctx,
+ NULL,
proxy_client_error_handler,
proxy_client_finish_handler,
0,
- RSPAMD_HTTP_SERVER,
- ctx->keys_cache,
- NULL);
+ RSPAMD_HTTP_SERVER);
if (ctx->key) {
rspamd_http_connection_set_key (session->client_conn, ctx->key);
}
}
-static void
-proxy_rotate_key (gint fd, short what, void *arg)
-{
- struct timeval rot_tv;
- struct rspamd_proxy_ctx *ctx = arg;
- gpointer kp;
-
- double_to_tv (ctx->rotate_tm, &rot_tv);
- rot_tv.tv_sec += ottery_rand_range (rot_tv.tv_sec);
- event_del (&ctx->rotate_ev);
- event_add (&ctx->rotate_ev, &rot_tv);
-
- kp = ctx->local_key;
- ctx->local_key = rspamd_keypair_new (RSPAMD_KEYPAIR_KEX,
- RSPAMD_CRYPTOBOX_MODE_25519);
- rspamd_keypair_unref (kp);
-}
-
static void
adjust_upstreams_limits (struct rspamd_proxy_ctx *ctx)
{
}
void
-start_rspamd_proxy (struct rspamd_worker *worker) {
+start_rspamd_proxy (struct rspamd_worker *worker)
+{
struct rspamd_proxy_ctx *ctx = worker->ctx;
- struct timeval rot_tv;
ctx->cfg = worker->srv->cfg;
ctx->ev_base = rspamd_prepare_worker (worker, "rspamd_proxy",
rspamd_upstreams_library_config (worker->srv->cfg, ctx->cfg->ups_ctx,
ctx->ev_base, ctx->resolver->r);
- /* XXX: stupid default */
- ctx->keys_cache = rspamd_keypair_cache_new (256);
- ctx->local_key = rspamd_keypair_new (RSPAMD_KEYPAIR_KEX,
- RSPAMD_CRYPTOBOX_MODE_25519);
-
- double_to_tv (ctx->rotate_tm, &rot_tv);
- rot_tv.tv_sec += ottery_rand_range (rot_tv.tv_sec);
- event_set (&ctx->rotate_ev, -1, EV_TIMEOUT, proxy_rotate_key, ctx);
- event_base_set (ctx->ev_base, &ctx->rotate_ev);
- event_add (&ctx->rotate_ev, &rot_tv);
+ ctx->http_ctx = rspamd_http_context_create (ctx->cfg, ctx->ev_base);
if (ctx->has_self_scan) {
/* Additional initialisation needed */
rspamd_stat_close ();
}
- rspamd_keypair_cache_destroy (ctx->keys_cache);
+ rspamd_http_context_free (ctx->http_ctx);
REF_RELEASE (ctx->cfg);
rspamd_log_close (worker->srv->logger, TRUE);
http_opts = RSPAMD_HTTP_REQUIRE_ENCRYPTION;
}
- task->http_conn = rspamd_http_connection_new (rspamd_worker_body_handler,
+ task->http_conn = rspamd_http_connection_new (
+ ctx->http_ctx,
+ rspamd_worker_body_handler,
rspamd_worker_error_handler,
rspamd_worker_finish_handler,
http_opts,
- RSPAMD_HTTP_SERVER,
- ctx->keys_cache,
- NULL);
+ RSPAMD_HTTP_SERVER);
rspamd_http_connection_set_max_size (task->http_conn, task->cfg->max_message);
worker->nconns++;
rspamd_mempool_add_destructor (task->task_pool,
rspamd_upstreams_library_config (worker->srv->cfg, ctx->cfg->ups_ctx,
ctx->ev_base, ctx->resolver->r);
- /* XXX: stupid default */
- ctx->keys_cache = rspamd_keypair_cache_new (256);
+ ctx->http_ctx = rspamd_http_context_create (ctx->cfg, ctx->ev_base);
rspamd_worker_init_scanner (worker, ctx->ev_base, ctx->resolver,
&ctx->lang_det);
rspamd_lua_run_postloads (ctx->cfg->lua_state, ctx->cfg, ctx->ev_base,
rspamd_worker_block_signals ();
rspamd_stat_close ();
- rspamd_keypair_cache_destroy (ctx->keys_cache);
+ rspamd_http_context_free (ctx->http_ctx);
REF_RELEASE (ctx->cfg);
rspamd_log_close (worker->srv->logger, TRUE);
/* Encryption key */
struct rspamd_cryptobox_keypair *key;
/* Keys cache */
- struct rspamd_keypair_cache *keys_cache;
+ struct rspamd_http_context *http_ctx;
/* Language detector */
struct rspamd_lang_detector *lang_det;
};