Commit 26e551de authored by Jan Včelák's avatar Jan Včelák 🚀

server: replace overlay with a single layer

The processing context is now initialized once per handler
instead of once per query.
parent 045a4546
......@@ -37,7 +37,7 @@
#include "knot/common/fdset.h"
#include "knot/common/log.h"
#include "knot/nameserver/process_query.h"
#include "knot/query/overlay.h"
#include "knot/query/layer.h"
#include "contrib/macros.h"
#include "contrib/mempattern.h"
#include "contrib/net.h"
......@@ -47,7 +47,7 @@
/*! \brief TCP context data. */
typedef struct tcp_context {
struct knot_overlay overlay;/*!< Query processing overlay. */
knot_layer_t layer; /*!< Query processing layer. */
server_t *server; /*!< Name server structure. */
struct iovec iov[2]; /*!< TX/RX buffers. */
unsigned client_threshold; /*!< Index of first TCP client. */
......@@ -132,30 +132,22 @@ static int tcp_handle(tcp_context_t *tcp, int fd,
rx->iov_len = ret;
}
knot_mm_t *mm = tcp->overlay.mm;
/* Initialize processing layer. */
/* Initialize processing overlay. */
ret = knot_overlay_init(&tcp->overlay, mm);
if (ret != KNOT_EOK) {
return ret;
}
ret = knot_overlay_add(&tcp->overlay, NS_PROC_QUERY, &param);
if (ret != KNOT_EOK) {
return ret;
}
tcp->layer.state = knot_layer_begin(&tcp->layer, &param);
/* Create packets. */
knot_pkt_t *ans = knot_pkt_new(tx->iov_base, tx->iov_len, mm);
knot_pkt_t *query = knot_pkt_new(rx->iov_base, rx->iov_len, mm);
knot_pkt_t *ans = knot_pkt_new(tx->iov_base, tx->iov_len, tcp->layer.mm);
knot_pkt_t *query = knot_pkt_new(rx->iov_base, rx->iov_len, tcp->layer.mm);
/* Input packet. */
(void) knot_pkt_parse(query, 0);
int state = knot_overlay_consume(&tcp->overlay, query);
int state = knot_layer_consume(&tcp->layer, query);
/* Resolve until NOOP or finished. */
ret = KNOT_EOK;
while (state & (KNOT_STATE_PRODUCE|KNOT_STATE_FAIL)) {
state = knot_overlay_produce(&tcp->overlay, ans);
state = knot_layer_produce(&tcp->layer, ans);
/* Send, if response generation passed and wasn't ignored. */
if (ans->size > 0 && !(state & (KNOT_STATE_FAIL|KNOT_STATE_NOOP))) {
......@@ -167,8 +159,7 @@ static int tcp_handle(tcp_context_t *tcp, int fd,
}
/* Reset after processing. */
knot_overlay_finish(&tcp->overlay);
knot_overlay_deinit(&tcp->overlay);
knot_layer_finish(&tcp->layer);
/* Cleanup. */
knot_pkt_free(&query);
......@@ -232,7 +223,7 @@ static int tcp_event_serve(tcp_context_t *tcp, unsigned i)
int ret = tcp_handle(tcp, fd, &tcp->iov[0], &tcp->iov[1]);
/* Flush per-query memory. */
mp_flush(tcp->overlay.mm->ctx);
mp_flush(tcp->layer.mm->ctx);
if (ret == KNOT_EOK) {
/* Update socket activity timer. */
......@@ -315,13 +306,13 @@ int tcp_master(dthread_t *thread)
memset(&tcp, 0, sizeof(tcp_context_t));
/* Create big enough memory cushion. */
knot_mm_t mm;
knot_mm_t mm = { 0 };
mm_ctx_mempool(&mm, 16 * MM_DEFAULT_BLKSIZE);
/* Create TCP answering context. */
tcp.server = handler->server;
tcp.thread_id = handler->thread_id[dt_get_id(thread)];
tcp.overlay.mm = &mm;
knot_layer_init(&tcp.layer, &mm, NS_PROC_QUERY);
/* Prepare structures for bound sockets. */
conf_val_t val = conf_get(conf(), C_SRV, C_LISTEN);
......
......@@ -38,7 +38,7 @@
#include "contrib/sockaddr.h"
#include "contrib/ucw/mempool.h"
#include "knot/nameserver/process_query.h"
#include "knot/query/overlay.h"
#include "knot/query/layer.h"
#include "knot/server/server.h"
#include "knot/server/udp-handler.h"
......@@ -51,7 +51,7 @@ enum {
/*! \brief UDP context data. */
typedef struct udp_context {
struct knot_overlay overlay; /*!< Query processing overlay. */
struct knot_layer layer; /*!< Query processing layer. */
server_t *server; /*!< Name server structure. */
unsigned thread_id; /*!< Thread identifier. */
} udp_context_t;
......@@ -74,23 +74,20 @@ static void udp_handle(udp_context_t *udp, int fd, struct sockaddr_storage *ss,
param.proc_flags |= NS_QUERY_LIMIT_RATE;
}
knot_mm_t *mm = udp->overlay.mm;
/* Create query processing context. */
knot_overlay_init(&udp->overlay, mm);
knot_overlay_add(&udp->overlay, NS_PROC_QUERY, &param);
/* Start query processing. */
udp->layer.state = knot_layer_begin(&udp->layer, &param);
/* Create packets. */
knot_pkt_t *query = knot_pkt_new(rx->iov_base, rx->iov_len, mm);
knot_pkt_t *ans = knot_pkt_new(tx->iov_base, tx->iov_len, mm);
knot_pkt_t *query = knot_pkt_new(rx->iov_base, rx->iov_len, udp->layer.mm);
knot_pkt_t *ans = knot_pkt_new(tx->iov_base, tx->iov_len, udp->layer.mm);
/* Input packet. */
(void) knot_pkt_parse(query, 0);
int state = knot_overlay_consume(&udp->overlay, query);
int state = knot_layer_consume(&udp->layer, query);
/* Process answer. */
while (state & (KNOT_STATE_PRODUCE|KNOT_STATE_FAIL)) {
state = knot_overlay_produce(&udp->overlay, ans);
state = knot_layer_produce(&udp->layer, ans);
}
/* Send response only if finished successfully. */
......@@ -101,8 +98,7 @@ static void udp_handle(udp_context_t *udp, int fd, struct sockaddr_storage *ss,
}
/* Reset after processing. */
knot_overlay_finish(&udp->overlay);
knot_overlay_deinit(&udp->overlay);
knot_layer_finish(&udp->layer);
/* Cleanup. */
knot_pkt_free(&query);
......@@ -503,16 +499,16 @@ int udp_master(dthread_t *thread)
void *rq = _udp_init();
ifacelist_t *ref = NULL;
/* Create big enough memory cushion. */
knot_mm_t mm;
mm_ctx_mempool(&mm, 16 * MM_DEFAULT_BLKSIZE);
/* Create UDP answering context. */
udp_context_t udp;
memset(&udp, 0, sizeof(udp_context_t));
udp.server = handler->server;
udp.thread_id = handler->thread_id[thr_id];
/* Create big enough memory cushion. */
knot_mm_t mm;
mm_ctx_mempool(&mm, 16 * MM_DEFAULT_BLKSIZE);
udp.overlay.mm = &mm;
knot_layer_init(&udp.layer, &mm, NS_PROC_QUERY);
/* Event source. */
struct pollfd *fds = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment