mirror of
https://github.com/sogou/workflow.git
synced 2026-02-08 01:33:17 +08:00
Simplify DNS server implementation. (#1693)
This commit is contained in:
@@ -212,10 +212,31 @@ protected:
|
||||
return this->WFServerTask::message_out();
|
||||
}
|
||||
|
||||
virtual void handle(int state, int error);
|
||||
|
||||
protected:
|
||||
enum TransportType type;
|
||||
};
|
||||
|
||||
void WFDnsServerTask::handle(int state, int error)
|
||||
{
|
||||
if (state == WFT_STATE_TOREPLY)
|
||||
{
|
||||
DnsRequest *req = this->get_req();
|
||||
DnsResponse *resp = this->get_resp();
|
||||
|
||||
resp->set_question_name(req->get_question_name());
|
||||
resp->set_question_type(req->get_question_type());
|
||||
resp->set_question_class(req->get_question_class());
|
||||
resp->set_opcode(req->get_opcode());
|
||||
resp->set_id(req->get_id());
|
||||
resp->set_rd(req->get_rd());
|
||||
resp->set_qr(1);
|
||||
}
|
||||
|
||||
return WFServerTask::handle(state, error);
|
||||
}
|
||||
|
||||
/**********Server Factory**********/
|
||||
|
||||
WFDnsTask *WFServerTaskFactory::create_dns_task(CommService *service,
|
||||
|
||||
@@ -19,16 +19,6 @@ void process(WFDnsTask *task)
|
||||
printf("name:%s type:%s class:%s\n",
|
||||
name.c_str(), dns_type2str(qtype), dns_class2str(qclass));
|
||||
|
||||
resp->set_question_name(name);
|
||||
resp->set_question_type(qtype);
|
||||
resp->set_question_class(qclass);
|
||||
|
||||
resp->set_opcode(opcode);
|
||||
resp->set_id(req->get_id()); // resp should set same id
|
||||
resp->set_qr(1); // this is a response
|
||||
resp->set_aa(1); // this is an authoritative answer
|
||||
resp->set_rd(req->get_rd());
|
||||
|
||||
if (opcode != 0)
|
||||
{
|
||||
resp->set_rcode(DNS_RCODE_NOT_IMPLEMENTED);
|
||||
@@ -36,6 +26,7 @@ void process(WFDnsTask *task)
|
||||
}
|
||||
|
||||
resp->set_rcode(DNS_RCODE_NO_ERROR);
|
||||
resp->set_aa(1);
|
||||
|
||||
if (qtype == DNS_TYPE_A)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user