Skip to content

Commit

Permalink
Add WFDnsServerTask and specify WFDnsServer::new_session().
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim committed Mar 5, 2024
1 parent bc55129 commit 6ded661
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
42 changes: 41 additions & 1 deletion src/factory/DnsTaskImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

#include <string>
#include <atomic>
#include "DnsMessage.h"
#include "WFTaskError.h"
#include "WFTaskFactory.h"
#include "DnsMessage.h"
#include "WFServer.h"

using namespace protocol;

Expand Down Expand Up @@ -184,3 +185,42 @@ WFDnsTask *WFTaskFactory::create_dns_task(const ParsedURI& uri,
return task;
}


/**********Server**********/

class WFDnsServerTask : public WFServerTask<DnsRequest, DnsResponse>
{
public:
WFDnsServerTask(CommService *service,
std::function<void (WFDnsTask *)>& proc) :
WFServerTask(service, WFGlobal::get_scheduler(), proc)
{
auto *server = (WFServer<DnsRequest, DnsResponse> *)service;
this->type = server->get_params()->transport_type;
}

protected:
virtual CommMessageIn *message_in()
{
this->get_req()->set_single_packet(this->type == TT_UDP);
return this->WFServerTask::message_in();
}

virtual CommMessageOut *message_out()
{
this->get_resp()->set_single_packet(this->type == TT_UDP);
return this->WFServerTask::message_out();
}

protected:
enum TransportType type;
};

/**********Server Factory**********/

WFDnsTask *WFServerTaskFactory::create_dns_task(CommService *service,
std::function<void (WFDnsTask *)>& proc)
{
return new WFDnsServerTask(service, proc);
}

3 changes: 3 additions & 0 deletions src/factory/WFTaskFactory.inl
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ WFNetworkTaskFactory<REQ, RESP>::create_server_task(CommService *service,
class WFServerTaskFactory
{
public:
static WFDnsTask *create_dns_task(CommService *service,
std::function<void (WFDnsTask *)>& proc);

static WFHttpTask *create_http_task(CommService *service,
std::function<void (WFHttpTask *)>& proc)
{
Expand Down
13 changes: 13 additions & 0 deletions src/server/WFDnsServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,18 @@ WFDnsServer::WFServer(dns_process_t proc) :
{
}

template<> inline
CommSession *WFDnsServer::new_session(long long seq, CommConnection *conn)
{
WFDnsTask *task;

task = WFServerTaskFactory::create_dns_task(this, this->process);
task->set_keep_alive(this->params.keep_alive_timeout);
task->set_receive_timeout(this->params.receive_timeout);
task->get_req()->set_size_limit(this->params.request_size_limit);

return task;
}

#endif

2 changes: 2 additions & 0 deletions src/server/WFServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class WFServerBase : protected CommService
return -1;
}

const struct WFServerParams *get_params() const { return &this->params; }

protected:
/* Override this function to create the initial SSL CTX of the server */
virtual SSL_CTX *new_ssl_ctx(const char *cert_file, const char *key_file);
Expand Down

0 comments on commit 6ded661

Please sign in to comment.