You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

http_context.c 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /*
  2. * Copyright 2024 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "http_context.h"
  17. #include "http_private.h"
  18. #include "keypair.h"
  19. #include "keypairs_cache.h"
  20. #include "cfg_file.h"
  21. #include "contrib/libottery/ottery.h"
  22. #include "contrib/http-parser/http_parser.h"
  23. #include "ssl_util.h"
  24. #include "rspamd.h"
  25. #include "libev_helper.h"
  26. INIT_LOG_MODULE(http_context)
  27. #define msg_debug_http_context(...) rspamd_conditional_debug_fast(NULL, NULL, \
  28. rspamd_http_context_log_id, "http_context", NULL, \
  29. G_STRFUNC, \
  30. __VA_ARGS__)
  31. static struct rspamd_http_context *default_ctx = NULL;
  32. struct rspamd_http_keepalive_cbdata {
  33. struct rspamd_http_connection *conn;
  34. struct rspamd_http_context *ctx;
  35. GQueue *queue;
  36. GList *link;
  37. struct rspamd_io_ev ev;
  38. };
  39. static void
  40. rspamd_http_keepalive_queue_cleanup(GQueue *conns)
  41. {
  42. GList *cur;
  43. cur = conns->head;
  44. while (cur) {
  45. struct rspamd_http_keepalive_cbdata *cbd;
  46. cbd = (struct rspamd_http_keepalive_cbdata *) cur->data;
  47. /* unref call closes fd, so we need to remove ev watcher first! */
  48. rspamd_ev_watcher_stop(cbd->ctx->event_loop, &cbd->ev);
  49. rspamd_http_connection_unref(cbd->conn);
  50. g_free(cbd);
  51. cur = cur->next;
  52. }
  53. g_queue_clear(conns);
  54. }
  55. static void
  56. rspamd_http_context_client_rotate_ev(struct ev_loop *loop, ev_timer *w, int revents)
  57. {
  58. struct rspamd_http_context *ctx = (struct rspamd_http_context *) w->data;
  59. gpointer kp;
  60. w->repeat = rspamd_time_jitter(ctx->config.client_key_rotate_time, 0);
  61. msg_debug_http_context("rotate local keypair, next rotate in %.0f seconds",
  62. w->repeat);
  63. ev_timer_again(loop, w);
  64. kp = ctx->client_kp;
  65. ctx->client_kp = rspamd_keypair_new(RSPAMD_KEYPAIR_KEX,
  66. RSPAMD_CRYPTOBOX_MODE_25519);
  67. rspamd_keypair_unref(kp);
  68. }
  69. static struct rspamd_http_context *
  70. rspamd_http_context_new_default(struct rspamd_config *cfg,
  71. struct ev_loop *ev_base,
  72. struct upstream_ctx *ups_ctx)
  73. {
  74. struct rspamd_http_context *ctx;
  75. static const int default_kp_size = 1024;
  76. static const gdouble default_rotate_time = 120;
  77. static const gdouble default_keepalive_interval = 65;
  78. static const gchar *default_user_agent = "rspamd-" RSPAMD_VERSION_FULL;
  79. static const gchar *default_server_hdr = "rspamd/" RSPAMD_VERSION_FULL;
  80. ctx = g_malloc0(sizeof(*ctx));
  81. ctx->config.kp_cache_size_client = default_kp_size;
  82. ctx->config.kp_cache_size_server = default_kp_size;
  83. ctx->config.client_key_rotate_time = default_rotate_time;
  84. ctx->config.user_agent = default_user_agent;
  85. ctx->config.keepalive_interval = default_keepalive_interval;
  86. ctx->config.server_hdr = default_server_hdr;
  87. ctx->ups_ctx = ups_ctx;
  88. if (cfg) {
  89. ctx->ssl_ctx = cfg->libs_ctx->ssl_ctx;
  90. ctx->ssl_ctx_noverify = cfg->libs_ctx->ssl_ctx_noverify;
  91. }
  92. else {
  93. ctx->ssl_ctx = rspamd_init_ssl_ctx();
  94. ctx->ssl_ctx_noverify = rspamd_init_ssl_ctx_noverify();
  95. }
  96. ctx->event_loop = ev_base;
  97. ctx->keep_alive_hash = kh_init(rspamd_keep_alive_hash);
  98. return ctx;
  99. }
  100. static void
  101. rspamd_http_context_parse_proxy(struct rspamd_http_context *ctx,
  102. const gchar *name,
  103. struct upstream_list **pls)
  104. {
  105. struct http_parser_url u;
  106. struct upstream_list *uls;
  107. if (!ctx->ups_ctx) {
  108. msg_err("cannot parse http_proxy %s - upstreams context is undefined", name);
  109. return;
  110. }
  111. memset(&u, 0, sizeof(u));
  112. if (http_parser_parse_url(name, strlen(name), 1, &u) == 0) {
  113. if (!(u.field_set & (1u << UF_HOST)) || u.port == 0) {
  114. msg_err("cannot parse http(s) proxy %s - invalid host or port", name);
  115. return;
  116. }
  117. uls = rspamd_upstreams_create(ctx->ups_ctx);
  118. if (!rspamd_upstreams_parse_line_len(uls,
  119. name + u.field_data[UF_HOST].off,
  120. u.field_data[UF_HOST].len, u.port, NULL)) {
  121. msg_err("cannot parse http(s) proxy %s - invalid data", name);
  122. rspamd_upstreams_destroy(uls);
  123. }
  124. else {
  125. *pls = uls;
  126. msg_info("set http(s) proxy to %s", name);
  127. }
  128. }
  129. else {
  130. uls = rspamd_upstreams_create(ctx->ups_ctx);
  131. if (!rspamd_upstreams_parse_line(uls,
  132. name, 3128, NULL)) {
  133. msg_err("cannot parse http(s) proxy %s - invalid data", name);
  134. rspamd_upstreams_destroy(uls);
  135. }
  136. else {
  137. *pls = uls;
  138. msg_info("set http(s) proxy to %s", name);
  139. }
  140. }
  141. }
  142. static void
  143. rspamd_http_context_init(struct rspamd_http_context *ctx)
  144. {
  145. if (ctx->config.kp_cache_size_client > 0) {
  146. ctx->client_kp_cache = rspamd_keypair_cache_new(ctx->config.kp_cache_size_client);
  147. }
  148. if (ctx->config.kp_cache_size_server > 0) {
  149. ctx->server_kp_cache = rspamd_keypair_cache_new(ctx->config.kp_cache_size_server);
  150. }
  151. if (ctx->config.client_key_rotate_time > 0 && ctx->event_loop) {
  152. double jittered = rspamd_time_jitter(ctx->config.client_key_rotate_time,
  153. 0);
  154. ev_timer_init(&ctx->client_rotate_ev,
  155. rspamd_http_context_client_rotate_ev, jittered, 0);
  156. ev_timer_start(ctx->event_loop, &ctx->client_rotate_ev);
  157. ctx->client_rotate_ev.data = ctx;
  158. }
  159. if (ctx->config.http_proxy) {
  160. rspamd_http_context_parse_proxy(ctx, ctx->config.http_proxy,
  161. &ctx->http_proxies);
  162. }
  163. default_ctx = ctx;
  164. }
  165. struct rspamd_http_context *
  166. rspamd_http_context_create(struct rspamd_config *cfg,
  167. struct ev_loop *ev_base,
  168. struct upstream_ctx *ups_ctx)
  169. {
  170. struct rspamd_http_context *ctx;
  171. const ucl_object_t *http_obj;
  172. ctx = rspamd_http_context_new_default(cfg, ev_base, ups_ctx);
  173. http_obj = ucl_object_lookup(cfg->cfg_ucl_obj, "http");
  174. if (http_obj) {
  175. const ucl_object_t *server_obj, *client_obj;
  176. client_obj = ucl_object_lookup(http_obj, "client");
  177. if (client_obj) {
  178. const ucl_object_t *kp_size;
  179. kp_size = ucl_object_lookup(client_obj, "cache_size");
  180. if (kp_size) {
  181. ctx->config.kp_cache_size_client = ucl_object_toint(kp_size);
  182. }
  183. const ucl_object_t *rotate_time;
  184. rotate_time = ucl_object_lookup(client_obj, "rotate_time");
  185. if (rotate_time) {
  186. ctx->config.client_key_rotate_time = ucl_object_todouble(rotate_time);
  187. }
  188. const ucl_object_t *user_agent;
  189. user_agent = ucl_object_lookup(client_obj, "user_agent");
  190. if (user_agent) {
  191. ctx->config.user_agent = ucl_object_tostring(user_agent);
  192. if (ctx->config.user_agent && strlen(ctx->config.user_agent) == 0) {
  193. ctx->config.user_agent = NULL;
  194. }
  195. }
  196. const ucl_object_t *server_hdr;
  197. server_hdr = ucl_object_lookup(client_obj, "server_hdr");
  198. if (server_hdr) {
  199. ctx->config.server_hdr = ucl_object_tostring(server_hdr);
  200. if (ctx->config.server_hdr && strlen(ctx->config.server_hdr) == 0) {
  201. ctx->config.server_hdr = "";
  202. }
  203. }
  204. const ucl_object_t *keepalive_interval;
  205. keepalive_interval = ucl_object_lookup(client_obj, "keepalive_interval");
  206. if (keepalive_interval) {
  207. ctx->config.keepalive_interval = ucl_object_todouble(keepalive_interval);
  208. }
  209. const ucl_object_t *http_proxy;
  210. http_proxy = ucl_object_lookup(client_obj, "http_proxy");
  211. if (http_proxy) {
  212. ctx->config.http_proxy = ucl_object_tostring(http_proxy);
  213. }
  214. }
  215. server_obj = ucl_object_lookup(http_obj, "server");
  216. if (server_obj) {
  217. const ucl_object_t *kp_size;
  218. kp_size = ucl_object_lookup(server_obj, "cache_size");
  219. if (kp_size) {
  220. ctx->config.kp_cache_size_server = ucl_object_toint(kp_size);
  221. }
  222. }
  223. }
  224. rspamd_http_context_init(ctx);
  225. return ctx;
  226. }
  227. void rspamd_http_context_free(struct rspamd_http_context *ctx)
  228. {
  229. if (ctx == default_ctx) {
  230. default_ctx = NULL;
  231. }
  232. if (ctx->client_kp_cache) {
  233. rspamd_keypair_cache_destroy(ctx->client_kp_cache);
  234. }
  235. if (ctx->server_kp_cache) {
  236. rspamd_keypair_cache_destroy(ctx->server_kp_cache);
  237. }
  238. if (ctx->config.client_key_rotate_time > 0) {
  239. ev_timer_stop(ctx->event_loop, &ctx->client_rotate_ev);
  240. if (ctx->client_kp) {
  241. rspamd_keypair_unref(ctx->client_kp);
  242. }
  243. }
  244. struct rspamd_keepalive_hash_key *hk;
  245. kh_foreach_key(ctx->keep_alive_hash, hk, {
  246. msg_debug_http_context("cleanup keepalive elt %s (%s)",
  247. rspamd_inet_address_to_string_pretty(hk->addr),
  248. hk->host);
  249. if (hk->host) {
  250. g_free(hk->host);
  251. }
  252. rspamd_inet_address_free(hk->addr);
  253. rspamd_http_keepalive_queue_cleanup(&hk->conns);
  254. g_free(hk);
  255. });
  256. kh_destroy(rspamd_keep_alive_hash, ctx->keep_alive_hash);
  257. if (ctx->http_proxies) {
  258. rspamd_upstreams_destroy(ctx->http_proxies);
  259. }
  260. g_free(ctx);
  261. }
  262. struct rspamd_http_context *
  263. rspamd_http_context_create_config(struct rspamd_http_context_cfg *cfg,
  264. struct ev_loop *ev_base,
  265. struct upstream_ctx *ups_ctx)
  266. {
  267. struct rspamd_http_context *ctx;
  268. ctx = rspamd_http_context_new_default(NULL, ev_base, ups_ctx);
  269. memcpy(&ctx->config, cfg, sizeof(*cfg));
  270. rspamd_http_context_init(ctx);
  271. return ctx;
  272. }
  273. struct rspamd_http_context *
  274. rspamd_http_context_default(void)
  275. {
  276. g_assert(default_ctx != NULL);
  277. return default_ctx;
  278. }
  279. int32_t
  280. rspamd_keep_alive_key_hash(struct rspamd_keepalive_hash_key *k)
  281. {
  282. rspamd_cryptobox_fast_hash_state_t hst;
  283. rspamd_cryptobox_fast_hash_init(&hst, 0);
  284. if (k->host) {
  285. rspamd_cryptobox_fast_hash_update(&hst, k->host, strlen(k->host));
  286. }
  287. rspamd_cryptobox_fast_hash_update(&hst, &k->port, sizeof(k->port));
  288. rspamd_cryptobox_fast_hash_update(&hst, &k->is_ssl, sizeof(k->is_ssl));
  289. return rspamd_cryptobox_fast_hash_final(&hst);
  290. }
  291. bool rspamd_keep_alive_key_equal(struct rspamd_keepalive_hash_key *k1,
  292. struct rspamd_keepalive_hash_key *k2)
  293. {
  294. if (k1->is_ssl != k2->is_ssl) {
  295. return false;
  296. }
  297. if (k1->host && k2->host) {
  298. if (k1->port == k2->port) {
  299. return strcmp(k1->host, k2->host) == 0;
  300. }
  301. }
  302. else if (!k1->host && !k2->host) {
  303. return (k1->port == k2->port);
  304. }
  305. /* One has host and another has no host */
  306. return false;
  307. }
  308. struct rspamd_http_connection *
  309. rspamd_http_context_check_keepalive(struct rspamd_http_context *ctx,
  310. const rspamd_inet_addr_t *addr,
  311. const gchar *host,
  312. bool is_ssl)
  313. {
  314. struct rspamd_keepalive_hash_key hk, *phk;
  315. khiter_t k;
  316. if (ctx == NULL) {
  317. ctx = rspamd_http_context_default();
  318. }
  319. hk.addr = (rspamd_inet_addr_t *) addr;
  320. hk.host = (gchar *) host;
  321. hk.port = rspamd_inet_address_get_port(addr);
  322. hk.is_ssl = is_ssl;
  323. k = kh_get(rspamd_keep_alive_hash, ctx->keep_alive_hash, &hk);
  324. if (k != kh_end(ctx->keep_alive_hash)) {
  325. phk = kh_key(ctx->keep_alive_hash, k);
  326. GQueue *conns = &phk->conns;
  327. /* Use stack based approach */
  328. if (g_queue_get_length(conns) > 0) {
  329. struct rspamd_http_keepalive_cbdata *cbd;
  330. struct rspamd_http_connection *conn;
  331. gint err;
  332. socklen_t len = sizeof(gint);
  333. cbd = g_queue_pop_head(conns);
  334. rspamd_ev_watcher_stop(ctx->event_loop, &cbd->ev);
  335. conn = cbd->conn;
  336. g_free(cbd);
  337. if (getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len) == -1) {
  338. err = errno;
  339. }
  340. if (err != 0) {
  341. rspamd_http_connection_unref(conn);
  342. msg_debug_http_context("invalid reused keepalive element %s (%s, ssl=%d); "
  343. "%s error; "
  344. "%d connections queued",
  345. rspamd_inet_address_to_string_pretty(phk->addr),
  346. phk->host,
  347. (int) phk->is_ssl,
  348. g_strerror(err),
  349. conns->length);
  350. return NULL;
  351. }
  352. msg_debug_http_context("reused keepalive element %s (%s, ssl=%d), %d connections queued",
  353. rspamd_inet_address_to_string_pretty(phk->addr),
  354. phk->host,
  355. (int) phk->is_ssl,
  356. conns->length);
  357. /* We transfer refcount here! */
  358. return conn;
  359. }
  360. else {
  361. msg_debug_http_context("found empty keepalive element %s (%s), cannot reuse",
  362. rspamd_inet_address_to_string_pretty(phk->addr),
  363. phk->host);
  364. }
  365. }
  366. return NULL;
  367. }
  368. const rspamd_inet_addr_t *
  369. rspamd_http_context_has_keepalive(struct rspamd_http_context *ctx,
  370. const gchar *host,
  371. unsigned port,
  372. bool is_ssl)
  373. {
  374. struct rspamd_keepalive_hash_key hk, *phk;
  375. khiter_t k;
  376. if (ctx == NULL) {
  377. ctx = rspamd_http_context_default();
  378. }
  379. hk.host = (gchar *) host;
  380. hk.port = port;
  381. hk.is_ssl = is_ssl;
  382. k = kh_get(rspamd_keep_alive_hash, ctx->keep_alive_hash, &hk);
  383. if (k != kh_end(ctx->keep_alive_hash)) {
  384. phk = kh_key(ctx->keep_alive_hash, k);
  385. GQueue *conns = &phk->conns;
  386. if (g_queue_get_length(conns) > 0) {
  387. return phk->addr;
  388. }
  389. }
  390. return NULL;
  391. }
  392. void rspamd_http_context_prepare_keepalive(struct rspamd_http_context *ctx,
  393. struct rspamd_http_connection *conn,
  394. const rspamd_inet_addr_t *addr,
  395. const gchar *host,
  396. bool is_ssl)
  397. {
  398. struct rspamd_keepalive_hash_key hk, *phk;
  399. khiter_t k;
  400. hk.addr = (rspamd_inet_addr_t *) addr;
  401. hk.host = (gchar *) host;
  402. hk.is_ssl = is_ssl;
  403. hk.port = rspamd_inet_address_get_port(addr);
  404. k = kh_get(rspamd_keep_alive_hash, ctx->keep_alive_hash, &hk);
  405. if (k != kh_end(ctx->keep_alive_hash)) {
  406. /* Reuse existing */
  407. conn->keepalive_hash_key = kh_key(ctx->keep_alive_hash, k);
  408. msg_debug_http_context("use existing keepalive element %s (%s)",
  409. rspamd_inet_address_to_string_pretty(conn->keepalive_hash_key->addr),
  410. conn->keepalive_hash_key->host);
  411. }
  412. else {
  413. /* Create new one */
  414. GQueue empty_init = G_QUEUE_INIT;
  415. gint r;
  416. phk = g_malloc(sizeof(*phk));
  417. phk->conns = empty_init;
  418. phk->host = g_strdup(host);
  419. phk->is_ssl = is_ssl;
  420. phk->addr = rspamd_inet_address_copy(addr, NULL);
  421. phk->port = hk.port;
  422. kh_put(rspamd_keep_alive_hash, ctx->keep_alive_hash, phk, &r);
  423. conn->keepalive_hash_key = phk;
  424. msg_debug_http_context("create new keepalive element %s (%s)",
  425. rspamd_inet_address_to_string_pretty(conn->keepalive_hash_key->addr),
  426. conn->keepalive_hash_key->host);
  427. }
  428. }
  429. static void
  430. rspamd_http_keepalive_handler(gint fd, short what, gpointer ud)
  431. {
  432. struct rspamd_http_keepalive_cbdata *cbdata =
  433. (struct rspamd_http_keepalive_cbdata *) ud; /*
  434. * We can get here if a remote side reported something or it has
  435. * timed out. In both cases we just terminate keepalive connection.
  436. */
  437. g_queue_delete_link(cbdata->queue, cbdata->link);
  438. msg_debug_http_context("remove keepalive element %s (%s), %d connections left",
  439. rspamd_inet_address_to_string_pretty(cbdata->conn->keepalive_hash_key->addr),
  440. cbdata->conn->keepalive_hash_key->host,
  441. cbdata->queue->length);
  442. /* unref call closes fd, so we need to remove ev watcher first! */
  443. rspamd_ev_watcher_stop(cbdata->ctx->event_loop, &cbdata->ev);
  444. rspamd_http_connection_unref(cbdata->conn);
  445. g_free(cbdata);
  446. }
  447. /* Non-static for unit testing */
  448. long rspamd_http_parse_keepalive_timeout(const rspamd_ftok_t *tok)
  449. {
  450. long timeout = -1;
  451. goffset pos = rspamd_substring_search(tok->begin,
  452. tok->len, "timeout", sizeof("timeout") - 1);
  453. if (pos != -1) {
  454. pos += sizeof("timeout") - 1;
  455. /* Skip spaces and equal sign */
  456. while (pos < tok->len) {
  457. if (tok->begin[pos] != '=' && !g_ascii_isspace(tok->begin[pos])) {
  458. break;
  459. }
  460. pos++;
  461. }
  462. gsize ndigits = rspamd_memspn(tok->begin + pos, "0123456789", tok->len - pos);
  463. glong real_timeout;
  464. if (ndigits > 0) {
  465. if (rspamd_strtoul(tok->begin + pos, ndigits, &real_timeout)) {
  466. timeout = real_timeout;
  467. msg_debug_http_context("got timeout attr %l", timeout);
  468. }
  469. }
  470. }
  471. return timeout;
  472. }
  473. void rspamd_http_context_push_keepalive(struct rspamd_http_context *ctx,
  474. struct rspamd_http_connection *conn,
  475. struct rspamd_http_message *msg,
  476. struct ev_loop *event_loop)
  477. {
  478. struct rspamd_http_keepalive_cbdata *cbdata;
  479. gdouble timeout = ctx->config.keepalive_interval;
  480. g_assert(conn->keepalive_hash_key != NULL);
  481. if (msg) {
  482. const rspamd_ftok_t *tok;
  483. rspamd_ftok_t cmp;
  484. tok = rspamd_http_message_find_header(msg, "Connection");
  485. if (!tok) {
  486. /* Server has not stated that it can do keep alive */
  487. conn->finished = TRUE;
  488. msg_debug_http_context("no Connection header");
  489. return;
  490. }
  491. RSPAMD_FTOK_ASSIGN(&cmp, "keep-alive");
  492. if (rspamd_ftok_casecmp(&cmp, tok) != 0) {
  493. conn->finished = TRUE;
  494. msg_debug_http_context("connection header is not `keep-alive`");
  495. return;
  496. }
  497. /* We can proceed, check timeout */
  498. tok = rspamd_http_message_find_header(msg, "Keep-Alive");
  499. if (tok) {
  500. long maybe_timeout = rspamd_http_parse_keepalive_timeout(tok);
  501. if (maybe_timeout > 0) {
  502. timeout = maybe_timeout;
  503. }
  504. }
  505. }
  506. /* Move connection to the keepalive pool */
  507. cbdata = g_malloc0(sizeof(*cbdata));
  508. cbdata->conn = rspamd_http_connection_ref(conn);
  509. /* Use stack like approach to that would easy reading */
  510. g_queue_push_head(&conn->keepalive_hash_key->conns, cbdata);
  511. cbdata->link = conn->keepalive_hash_key->conns.head;
  512. cbdata->queue = &conn->keepalive_hash_key->conns;
  513. cbdata->ctx = ctx;
  514. conn->finished = FALSE;
  515. rspamd_ev_watcher_init(&cbdata->ev, conn->fd, EV_READ,
  516. rspamd_http_keepalive_handler,
  517. cbdata);
  518. rspamd_ev_watcher_start(event_loop, &cbdata->ev, timeout);
  519. msg_debug_http_context("push keepalive element %s (%s), %d connections queued, %.1f timeout",
  520. rspamd_inet_address_to_string_pretty(cbdata->conn->keepalive_hash_key->addr),
  521. cbdata->conn->keepalive_hash_key->host,
  522. cbdata->queue->length,
  523. timeout);
  524. }