Browse Source

[Minor] Avoid one copy when publishing fuzzy updates

tags/1.5.0
Vsevolod Stakhov 7 years ago
parent
commit
be8abd1825
2 changed files with 31 additions and 4 deletions
  1. 28
    3
      src/lua/lua_http.c
  2. 3
    1
      src/plugins/lua/fuzzy_collect.lua

+ 28
- 3
src/lua/lua_http.c View File

@@ -55,6 +55,8 @@ static const struct luaL_reg httplib_m[] = {
{NULL, NULL}
};

#define RSPAMD_LUA_HTTP_FLAG_TEXT (1 << 0)

struct lua_http_cbdata {
lua_State *L;
struct rspamd_http_connection *conn;
@@ -69,6 +71,7 @@ struct lua_http_cbdata {
rspamd_inet_addr_t *addr;
gchar *mime_type;
gchar *host;
gint flags;
gint fd;
gint cbref;
};
@@ -179,11 +182,22 @@ lua_http_finish_handler (struct rspamd_http_connection *conn,
/* Body */
body = rspamd_http_message_get_body (msg, &body_len);

if (body_len > 0) {
lua_pushlstring (cbd->L, body, body_len);
if (cbd->flags & RSPAMD_LUA_HTTP_FLAG_TEXT) {
struct rspamd_lua_text *t;

t = lua_newuserdata (cbd->L, sizeof (*t));
rspamd_lua_setclass (cbd->L, "rspamd{text}", -1);
t->start = body;
t->len = body_len;
t->flags = 0;
}
else {
lua_pushnil (cbd->L);
if (body_len > 0) {
lua_pushlstring (cbd->L, body, body_len);
}
else {
lua_pushnil (cbd->L);
}
}
/* Headers */
lua_newtable (cbd->L);
@@ -338,6 +352,7 @@ lua_http_request (lua_State *L)
struct rspamd_cryptobox_pubkey *peer_key = NULL;
struct rspamd_cryptobox_keypair *local_kp = NULL;
gdouble timeout = default_http_timeout;
gint flags = 0;
gchar *mime_type = NULL;

if (lua_gettop (L) >= 2) {
@@ -524,6 +539,15 @@ lua_http_request (lua_State *L)
}

lua_pop (L, 1);

lua_pushstring (L, "opaque_body");
lua_gettable (L, 1);

if (!!lua_toboolean (L, -1)) {
flags |= RSPAMD_LUA_HTTP_FLAG_TEXT;
}

lua_pop (L, 1);
}
else {
msg_err ("http request has bad params");
@@ -543,6 +567,7 @@ lua_http_request (lua_State *L)
cbd->cfg = cfg;
cbd->peer_pk = peer_key;
cbd->local_kp = local_kp;
cbd->flags = flags;

if (msg->host) {
cbd->host = rspamd_fstring_cstr (msg->host);

+ 3
- 1
src/plugins/lua/fuzzy_collect.lua View File

@@ -53,6 +53,7 @@ local function collect_fuzzy_hashes(cfg, ev_base)
if not body or err then
rspamd_logger.errx(cfg, 'cannot load data: %s', err)
else
-- Here, we actually copy body once for each mirror
fun.each(function(_, v) send_data_mirror(v, cfg, ev_base, body) end,
settings.mirrors)
end
@@ -81,7 +82,8 @@ local function collect_fuzzy_hashes(cfg, ev_base)
peer_key = settings.collect_pubkey,
headers = {
Signature = sig:hex()
}
},
opaque_body = true,
}
end
else

Loading…
Cancel
Save