Explorar el Código

Use keypairs cache.

tags/0.9.0
Vsevolod Stakhov hace 9 años
padre
commit
fec4b654db
Se han modificado 6 ficheros con 53 adiciones y 13 borrados
  1. 5
    1
      src/client/rspamdclient.c
  2. 30
    8
      src/libutil/http.c
  3. 5
    1
      src/libutil/http.h
  4. 1
    1
      src/libutil/map.c
  5. 2
    1
      src/lua/lua_http.c
  6. 10
    1
      src/worker.c

+ 5
- 1
src/client/rspamdclient.c Ver fichero

@@ -24,6 +24,7 @@
#include "rspamdclient.h"
#include "util.h"
#include "http.h"
#include "keypairs_cache.h"

#ifdef HAVE_FETCH_H
#include <fetch.h>
@@ -46,6 +47,7 @@ struct rspamd_client_connection {
struct rspamd_http_connection *http_conn;
gboolean req_sent;
struct rspamd_client_request *req;
struct rspamd_keypair_cache *keys_cache;
};

struct rspamd_client_request {
@@ -148,11 +150,13 @@ rspamd_client_init (struct event_base *ev_base, const gchar *name,
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,
rspamd_client_error_handler,
rspamd_client_finish_handler,
0,
RSPAMD_HTTP_CLIENT);
RSPAMD_HTTP_CLIENT,
conn->keys_cache);

conn->server_name = g_string_new (name);
if (port != 0) {

+ 30
- 8
src/libutil/http.c Ver fichero

@@ -397,7 +397,8 @@ rspamd_http_parse_date (const gchar *header, gsize len)
}

static void
rspamd_http_parse_key (GString *data, struct rspamd_http_connection_private *priv)
rspamd_http_parse_key (GString *data, struct rspamd_http_connection *conn,
struct rspamd_http_connection_private *priv)
{
guchar *decoded_id, *decoded_key;
const gchar *eq_pos;
@@ -422,6 +423,11 @@ rspamd_http_parse_key (GString *data, struct rspamd_http_connection_private *pri
RSPAMD_HTTP_KEY_ID_LEN) == 0) {
priv->msg->peer_key =
rspamd_http_connection_make_peer_key (eq_pos + 1);

if (conn->cache && priv->msg->peer_key) {
rspamd_keypair_cache_process (conn->cache,
priv->msg->peer_key, priv->local_key);
}
}
}
}
@@ -433,14 +439,15 @@ rspamd_http_parse_key (GString *data, struct rspamd_http_connection_private *pri
}

static inline void
rspamd_http_check_special_header (struct rspamd_http_connection_private *priv)
rspamd_http_check_special_header (struct rspamd_http_connection *conn,
struct rspamd_http_connection_private *priv)
{
if (g_ascii_strcasecmp (priv->header->name->str, date_header) == 0) {
priv->msg->date = rspamd_http_parse_date (priv->header->value->str,
priv->header->value->len);
}
else if (g_ascii_strcasecmp (priv->header->name->str, key_header) == 0) {
rspamd_http_parse_key (priv->header->value, priv);
rspamd_http_parse_key (priv->header->value, conn, priv);
}
}

@@ -495,7 +502,7 @@ rspamd_http_on_header_field (http_parser * parser,
}
else if (priv->new_header) {
DL_APPEND (priv->msg->headers, priv->header);
rspamd_http_check_special_header (priv);
rspamd_http_check_special_header (conn, priv);
priv->header = g_slice_alloc (sizeof (struct rspamd_http_header));
priv->header->name = g_string_sized_new (32);
priv->header->value = g_string_sized_new (32);
@@ -540,7 +547,7 @@ rspamd_http_on_headers_complete (http_parser * parser)

if (priv->header != NULL) {
DL_APPEND (priv->msg->headers, priv->header);
rspamd_http_check_special_header (priv);
rspamd_http_check_special_header (conn, priv);
priv->header = NULL;
}

@@ -856,7 +863,8 @@ rspamd_http_connection_new (rspamd_http_body_handler_t body_handler,
rspamd_http_error_handler_t error_handler,
rspamd_http_finish_handler_t finish_handler,
unsigned opts,
enum rspamd_http_connection_type type)
enum rspamd_http_connection_type type,
struct rspamd_keypair_cache *cache)
{
struct rspamd_http_connection *new;
struct rspamd_http_connection_private *priv;
@@ -874,6 +882,7 @@ rspamd_http_connection_new (rspamd_http_body_handler_t body_handler,
new->fd = -1;
new->ref = 1;
new->finished = FALSE;
new->cache = cache;

/* Init priv */
priv = g_slice_alloc0 (sizeof (struct rspamd_http_connection_private));
@@ -1012,10 +1021,15 @@ rspamd_http_connection_write_message (struct rspamd_http_connection *conn,
priv->buf->data = g_string_sized_new (128);
buf = priv->buf->data;

if (priv->peer_key) {
if (priv->peer_key && priv->local_key) {
priv->msg->peer_key = priv->peer_key;
priv->peer_key = NULL;
priv->encrypted = TRUE;

if (conn->cache && priv->msg->peer_key) {
rspamd_keypair_cache_process (conn->cache,
priv->msg->peer_key, priv->local_key);
}
}

if (msg->method < HTTP_SYMBOLS) {
@@ -1575,6 +1589,7 @@ rspamd_http_router_new (rspamd_http_router_error_handler_t eh,
}

new->default_fs_path = NULL;

if (default_fs_path != NULL) {
if (stat (default_fs_path, &st) == -1) {
msg_err ("cannot stat %s", default_fs_path);
@@ -1589,6 +1604,9 @@ rspamd_http_router_new (rspamd_http_router_error_handler_t eh,
}
}

/* XXX: stupid default value, should be configurable */
new->cache = rspamd_keypair_cache_new (256);

return new;
}

@@ -1633,7 +1651,7 @@ rspamd_http_router_handle_socket (struct rspamd_http_connection_router *router,
rspamd_http_router_error_handler,
rspamd_http_router_finish_handler,
0,
RSPAMD_HTTP_SERVER);
RSPAMD_HTTP_SERVER, router->cache);

if (router->key) {
rspamd_http_connection_set_key (conn->conn, router->key);
@@ -1661,6 +1679,10 @@ rspamd_http_router_free (struct rspamd_http_connection_router *router)
REF_RELEASE (kp);
}

if (router->cache) {
rspamd_keypair_cache_destroy (router->cache);
}

if (router->default_fs_path != NULL) {
g_free (router->default_fs_path);
}

+ 5
- 1
src/libutil/http.h Ver fichero

@@ -33,6 +33,7 @@

#include "config.h"
#include "http_parser.h"
#include "keypairs_cache.h"

enum rspamd_http_connection_type {
RSPAMD_HTTP_SERVER,
@@ -109,6 +110,7 @@ struct rspamd_http_connection {
rspamd_http_body_handler_t body_handler;
rspamd_http_error_handler_t error_handler;
rspamd_http_finish_handler_t finish_handler;
struct rspamd_keypair_cache *cache;
gpointer ud;
unsigned opts;
enum rspamd_http_connection_type type;
@@ -131,6 +133,7 @@ struct rspamd_http_connection_router {
struct timeval tv;
struct timeval *ptv;
struct event_base *ev_base;
struct rspamd_keypair_cache *cache;
gchar *default_fs_path;
gpointer key;
rspamd_http_router_error_handler_t error_handler;
@@ -148,7 +151,8 @@ struct rspamd_http_connection * rspamd_http_connection_new (
rspamd_http_error_handler_t error_handler,
rspamd_http_finish_handler_t finish_handler,
unsigned opts,
enum rspamd_http_connection_type type);
enum rspamd_http_connection_type type,
struct rspamd_keypair_cache *cache);

/**
* Load the encryption keypair

+ 1
- 1
src/libutil/map.c Ver fichero

@@ -588,7 +588,7 @@ rspamd_map_add (struct rspamd_config *cfg,
hdata->conn = rspamd_http_connection_new (http_map_read, http_map_error,
http_map_finish,
RSPAMD_HTTP_BODY_PARTIAL | RSPAMD_HTTP_CLIENT_SIMPLE,
RSPAMD_HTTP_CLIENT);
RSPAMD_HTTP_CLIENT, NULL);
new_map->map_data = hdata;
}
/* Temp pool */

+ 2
- 1
src/lua/lua_http.c Ver fichero

@@ -158,7 +158,8 @@ lua_http_make_connection (struct lua_http_cbdata *cbd)
}
cbd->fd = fd;
cbd->conn = rspamd_http_connection_new (NULL, lua_http_error_handler,
lua_http_finish_handler, RSPAMD_HTTP_CLIENT_SIMPLE, RSPAMD_HTTP_CLIENT);
lua_http_finish_handler, RSPAMD_HTTP_CLIENT_SIMPLE,
RSPAMD_HTTP_CLIENT, NULL);

rspamd_http_connection_write_message (cbd->conn, cbd->msg,
NULL, NULL, cbd, fd, &cbd->tv, cbd->ev_base);

+ 10
- 1
src/worker.c Ver fichero

@@ -36,6 +36,7 @@
#include "libserver/dns.h"
#include "libmime/message.h"
#include "main.h"
#include "keypairs_cache.h"

#include "lua/lua_common.h"

@@ -88,6 +89,8 @@ struct rspamd_worker_ctx {
struct event_base *ev_base;
/* Encryption key */
gpointer key;
/* Keys cache */
struct rspamd_keypair_cache *keys_cache;
};

/*
@@ -237,7 +240,8 @@ accept_socket (gint fd, short what, void *arg)
rspamd_worker_error_handler,
rspamd_worker_finish_handler,
0,
RSPAMD_HTTP_SERVER);
RSPAMD_HTTP_SERVER,
ctx->keys_cache);
new_task->ev_base = ctx->ev_base;
ctx->tasks++;
rspamd_mempool_add_destructor (new_task->task_pool,
@@ -352,6 +356,9 @@ start_worker (struct rspamd_worker *worker)
}
}

/* XXX: stupid default */
ctx->keys_cache = rspamd_keypair_cache_new (256);

event_base_loop (ctx->ev_base, 0);

g_mime_shutdown ();
@@ -361,6 +368,8 @@ start_worker (struct rspamd_worker *worker)
rspamd_http_connection_key_unref (ctx->key);
}

rspamd_keypair_cache_destroy (ctx->keys_cache);

exit (EXIT_SUCCESS);
}


Cargando…
Cancelar
Guardar