From a69999aba394ba40dcfd677f155eaee364ae28e0 Mon Sep 17 00:00:00 2001 From: Xie Han <63350856@qq.com> Date: Sun, 1 Jan 2023 01:12:25 +0800 Subject: [PATCH 1/3] Change a internal function name. --- src/protocol/MySQLMessage.cc | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/protocol/MySQLMessage.cc b/src/protocol/MySQLMessage.cc index dd30c677..591f7237 100644 --- a/src/protocol/MySQLMessage.cc +++ b/src/protocol/MySQLMessage.cc @@ -248,20 +248,14 @@ int MySQLHandshakeResponse::decode_packet(const unsigned char *buf, size_t bufle return 1; } -static inline void __sha1(const std::string& str, unsigned char *md) +static inline std::string __sha1_str(const std::string& str) { + unsigned char sha1[20]; SHA_CTX ctx; SHA1_Init(&ctx); SHA1_Update(&ctx, str.c_str(), str.size()); - SHA1_Final(md, &ctx); -} - -static inline std::string __sha1_bin(const std::string& str) -{ - unsigned char md[20]; - - __sha1(str, md); - return std::string((const char *)md, 20); + SHA1_Final(sha1, &ctx); + return std::string((const char *)sha1, 20); } #define MYSQL_CAPFLAG_CLIENT_SSL 0x00000800 @@ -334,8 +328,8 @@ int MySQLAuthRequest::encode(struct iovec vectors[], int max) else { native.push_back((char)20); - std::string first = __sha1_bin(password_); - std::string second = __sha1_bin(challenge_ + __sha1_bin(first)); + std::string first = __sha1_str(password_); + std::string second = __sha1_str(challenge_ + __sha1_str(first)); for (int i = 0; i < 20; i++) native.push_back(first[i] ^ second[i]); From b1c8d5181765bfc9f53c56c975e95569e7bc73d8 Mon Sep 17 00:00:00 2001 From: Xie Han <63350856@qq.com> Date: Sun, 1 Jan 2023 03:22:59 +0800 Subject: [PATCH 2/3] Optimize the method for generating DNS request ID. --- src/factory/DnsTaskImpl.cc | 12 +++++++++++- src/protocol/DnsMessage.cc | 2 -- src/protocol/DnsMessage.h | 14 +------------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/factory/DnsTaskImpl.cc b/src/factory/DnsTaskImpl.cc index 313c2667..c5964319 100644 --- a/src/factory/DnsTaskImpl.cc +++ b/src/factory/DnsTaskImpl.cc @@ -45,6 +45,7 @@ public: protected: virtual CommMessageOut *message_out(); + virtual int keep_alive_timeout(); virtual bool init_success(); virtual bool finish_once(); @@ -70,7 +71,8 @@ CommMessageOut *ComplexDnsTask::message_out() DnsResponse *resp = this->get_resp(); TransportType type = this->get_transport_type(); - /* Set these field every time, in case of reconstruct on redirect */ + if (req->get_id() == 0) + req->set_id(this->get_task_seq() + 1); resp->set_request_id(req->get_id()); resp->set_request_name(req->get_question_name()); req->set_single_packet(type == TT_UDP); @@ -79,6 +81,14 @@ CommMessageOut *ComplexDnsTask::message_out() return this->WFClientTask::message_out(); } +int ComplexDnsTask::keep_alive_timeout() +{ + if (this->get_task_seq() == (2 << 16) - 2) + return 0; + + return this->WFClientTask::keep_alive_timeout(); +} + bool ComplexDnsTask::init_success() { if (uri_.scheme && strcasecmp(uri_.scheme, "dnss") == 0) diff --git a/src/protocol/DnsMessage.cc b/src/protocol/DnsMessage.cc index f52f3166..f4b90f52 100644 --- a/src/protocol/DnsMessage.cc +++ b/src/protocol/DnsMessage.cc @@ -184,8 +184,6 @@ void DnsMessage::set_question_name(const std::string& name) parser->question.qname = strdup(name.c_str()); } -std::atomic DnsRequest::req_id_(1); - int DnsResponse::append(const void *buf, size_t *size) { int ret = this->DnsMessage::append(buf, size); diff --git a/src/protocol/DnsMessage.h b/src/protocol/DnsMessage.h index a8c87b18..43078ef2 100644 --- a/src/protocol/DnsMessage.h +++ b/src/protocol/DnsMessage.h @@ -26,7 +26,6 @@ #include #include -#include #include "ProtocolMessage.h" #include "dns_parser.h" @@ -193,15 +192,7 @@ private: class DnsRequest : public DnsMessage { public: - DnsRequest() - { - uint64_t req_id; - do - req_id = DnsRequest::req_id_++; - while (req_id == 0); - dns_parser_set_id(req_id, this->parser); - } - + DnsRequest() = default; DnsRequest(DnsRequest&& req) = default; DnsRequest& operator = (DnsRequest&& req) = default; @@ -209,9 +200,6 @@ public: { dns_parser_set_question(host, qtype, qclass, this->parser); } - -private: - static std::atomic req_id_; }; class DnsResponse : public DnsMessage From 79c0eb564e819bfd2919bc0d5a0f4d7797bf89ea Mon Sep 17 00:00:00 2001 From: Xie Han <63350856@qq.com> Date: Sun, 1 Jan 2023 14:02:00 +0800 Subject: [PATCH 3/3] Fix DNS client connection max keepalive times. --- src/factory/DnsTaskImpl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/factory/DnsTaskImpl.cc b/src/factory/DnsTaskImpl.cc index c5964319..64aeee57 100644 --- a/src/factory/DnsTaskImpl.cc +++ b/src/factory/DnsTaskImpl.cc @@ -83,7 +83,7 @@ CommMessageOut *ComplexDnsTask::message_out() int ComplexDnsTask::keep_alive_timeout() { - if (this->get_task_seq() == (2 << 16) - 2) + if (this->get_task_seq() == (1 << 16) - 2) return 0; return this->WFClientTask::keep_alive_timeout();