From d496c39ecdd3413c9b5c0d5f03a634f347727f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Thu, 6 Mar 2025 01:42:08 +0800 Subject: [PATCH] =?UTF-8?q?optimize:=20TCP=20=E5=92=8C=20UDP=20=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84DNS=EF=BC=8C=E5=8F=AA=E6=8E=A5=E6=94=B6?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E4=B8=80=E6=AC=A1=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mitmproxy/src/lib/dns/tcp.js | 4 ++-- packages/mitmproxy/src/lib/dns/udp.js | 2 +- packages/mitmproxy/test/dnsTest.mjs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/mitmproxy/src/lib/dns/tcp.js b/packages/mitmproxy/src/lib/dns/tcp.js index 779e75e..9861eef 100644 --- a/packages/mitmproxy/src/lib/dns/tcp.js +++ b/packages/mitmproxy/src/lib/dns/tcp.js @@ -37,13 +37,13 @@ module.exports = class DNSOverTCP extends BaseDNS { tcpClient.write(Buffer.concat([lengthBuffer, packet])) }) - tcpClient.on('data', (data) => { + tcpClient.once('data', (data) => { const length = data.readUInt16BE(0) const response = dnsPacket.decode(data.subarray(2, 2 + length)) resolve(response) }) - tcpClient.on('error', (err) => { + tcpClient.once('error', (err) => { reject(err) }) }) diff --git a/packages/mitmproxy/src/lib/dns/udp.js b/packages/mitmproxy/src/lib/dns/udp.js index 10464c3..cb0fb8b 100644 --- a/packages/mitmproxy/src/lib/dns/udp.js +++ b/packages/mitmproxy/src/lib/dns/udp.js @@ -35,7 +35,7 @@ module.exports = class DNSOverUDP extends BaseDNS { }) // 接收 UDP 响应 - udpClient.on('message', (msg) => { + udpClient.once('message', (msg) => { const response = dnsPacket.decode(msg) resolve(response) }) diff --git a/packages/mitmproxy/test/dnsTest.mjs b/packages/mitmproxy/test/dnsTest.mjs index cb50beb..540adc4 100644 --- a/packages/mitmproxy/test/dnsTest.mjs +++ b/packages/mitmproxy/test/dnsTest.mjs @@ -106,9 +106,9 @@ let ip console.log('\n--------------- test PreSet ---------------\n') ip = await dnsProviders.PreSet.lookup(presetHostname) -assert.strictEqual(ip, presetIp) // test preset console.log('===> test PreSet:', ip, '\n\n') console.log('\n\n') +assert.strictEqual(ip, presetIp) // test preset console.log('\n--------------- test https ---------------\n')