From b68ce10b47c69aafeffacd8f8b23a720de93b77a Mon Sep 17 00:00:00 2001 From: Envyw6567 Date: Wed, 20 Nov 2024 13:18:59 +0900 Subject: [PATCH 1/9] setting: proxy-server npm install --- backend/proxy-server/package-lock.json | 396 +------------------------ 1 file changed, 5 insertions(+), 391 deletions(-) diff --git a/backend/proxy-server/package-lock.json b/backend/proxy-server/package-lock.json index d5bb2521..2553cc81 100644 --- a/backend/proxy-server/package-lock.json +++ b/backend/proxy-server/package-lock.json @@ -1917,74 +1917,6 @@ "integrity": "sha512-aQgH0UODGuFHfL8rgeLSrGCoh3NCoNUs0tFGl0o79iyfASfvWtT/K/X3RM0QJpXXOgXpB//T2nD5XvCFtdk32w==", "license": "Apache-2.0" }, - "node_modules/@esbuild/aix-ppc64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.23.1.tgz", - "integrity": "sha512-6VhYk1diRqrhBAqpJEdjASR/+WVRtfjpqKuNw11cLiaWpAT/Uu+nokB+UJnevzy/P9C/ty6AOe0dwueMrGh/iQ==", - "cpu": [ - "ppc64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "aix" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/android-arm": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.23.1.tgz", - "integrity": "sha512-uz6/tEy2IFm9RYOyvKl88zdzZfwEfKZmnX9Cj1BHjeSGNuGLuMD1kR8y5bteYmwqKm1tj8m4cb/aKEorr6fHWQ==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/android-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.23.1.tgz", - "integrity": "sha512-xw50ipykXcLstLeWH7WRdQuysJqejuAGPd30vd1i5zSyKK3WE+ijzHmLKxdiCMtH1pHz78rOg0BKSYOSB/2Khw==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/android-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.23.1.tgz", - "integrity": "sha512-nlN9B69St9BwUoB+jkyU090bru8L0NA3yFvAd7k8dNsVH8bi9a8cUAUSEcEEgTp2z3dbEDGJGfP6VUnkQnlReg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=18" - } - }, "node_modules/@esbuild/darwin-arm64": { "version": "0.23.1", "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.23.1.tgz", @@ -2002,329 +1934,6 @@ "node": ">=18" } }, - "node_modules/@esbuild/darwin-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.23.1.tgz", - "integrity": "sha512-aClqdgTDVPSEGgoCS8QDG37Gu8yc9lTHNAQlsztQ6ENetKEO//b8y31MMu2ZaPbn4kVsIABzVLXYLhCGekGDqw==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/freebsd-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.23.1.tgz", - "integrity": "sha512-h1k6yS8/pN/NHlMl5+v4XPfikhJulk4G+tKGFIOwURBSFzE8bixw1ebjluLOjfwtLqY0kewfjLSrO6tN2MgIhA==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/freebsd-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.23.1.tgz", - "integrity": "sha512-lK1eJeyk1ZX8UklqFd/3A60UuZ/6UVfGT2LuGo3Wp4/z7eRTRYY+0xOu2kpClP+vMTi9wKOfXi2vjUpO1Ro76g==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-arm": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.23.1.tgz", - "integrity": "sha512-CXXkzgn+dXAPs3WBwE+Kvnrf4WECwBdfjfeYHpMeVxWE0EceB6vhWGShs6wi0IYEqMSIzdOF1XjQ/Mkm5d7ZdQ==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.23.1.tgz", - "integrity": "sha512-/93bf2yxencYDnItMYV/v116zff6UyTjo4EtEQjUBeGiVpMmffDNUyD9UN2zV+V3LRV3/on4xdZ26NKzn6754g==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-ia32": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.23.1.tgz", - "integrity": "sha512-VTN4EuOHwXEkXzX5nTvVY4s7E/Krz7COC8xkftbbKRYAl96vPiUssGkeMELQMOnLOJ8k3BY1+ZY52tttZnHcXQ==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-loong64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.23.1.tgz", - "integrity": "sha512-Vx09LzEoBa5zDnieH8LSMRToj7ir/Jeq0Gu6qJ/1GcBq9GkfoEAoXvLiW1U9J1qE/Y/Oyaq33w5p2ZWrNNHNEw==", - "cpu": [ - "loong64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-mips64el": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.23.1.tgz", - "integrity": "sha512-nrFzzMQ7W4WRLNUOU5dlWAqa6yVeI0P78WKGUo7lg2HShq/yx+UYkeNSE0SSfSure0SqgnsxPvmAUu/vu0E+3Q==", - "cpu": [ - "mips64el" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-ppc64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.23.1.tgz", - "integrity": "sha512-dKN8fgVqd0vUIjxuJI6P/9SSSe/mB9rvA98CSH2sJnlZ/OCZWO1DJvxj8jvKTfYUdGfcq2dDxoKaC6bHuTlgcw==", - "cpu": [ - "ppc64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-riscv64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.23.1.tgz", - "integrity": "sha512-5AV4Pzp80fhHL83JM6LoA6pTQVWgB1HovMBsLQ9OZWLDqVY8MVobBXNSmAJi//Csh6tcY7e7Lny2Hg1tElMjIA==", - "cpu": [ - "riscv64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-s390x": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.23.1.tgz", - "integrity": "sha512-9ygs73tuFCe6f6m/Tb+9LtYxWR4c9yg7zjt2cYkjDbDpV/xVn+68cQxMXCjUpYwEkze2RcU/rMnfIXNRFmSoDw==", - "cpu": [ - "s390x" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.23.1.tgz", - "integrity": "sha512-EV6+ovTsEXCPAp58g2dD68LxoP/wK5pRvgy0J/HxPGB009omFPv3Yet0HiaqvrIrgPTBuC6wCH1LTOY91EO5hQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/netbsd-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.23.1.tgz", - "integrity": "sha512-aevEkCNu7KlPRpYLjwmdcuNz6bDFiE7Z8XC4CPqExjTvrHugh28QzUXVOZtiYghciKUacNktqxdpymplil1beA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "netbsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/openbsd-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.23.1.tgz", - "integrity": "sha512-3x37szhLexNA4bXhLrCC/LImN/YtWis6WXr1VESlfVtVeoFJBRINPJ3f0a/6LV8zpikqoUg4hyXw0sFBt5Cr+Q==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "openbsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/openbsd-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.23.1.tgz", - "integrity": "sha512-aY2gMmKmPhxfU+0EdnN+XNtGbjfQgwZj43k8G3fyrDM/UdZww6xrWxmDkuz2eCZchqVeABjV5BpildOrUbBTqA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "openbsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/sunos-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.23.1.tgz", - "integrity": "sha512-RBRT2gqEl0IKQABT4XTj78tpk9v7ehp+mazn2HbUeZl1YMdaGAQqhapjGTCe7uw7y0frDi4gS0uHzhvpFuI1sA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "sunos" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/win32-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.23.1.tgz", - "integrity": "sha512-4O+gPR5rEBe2FpKOVyiJ7wNDPA8nGzDuJ6gN4okSA1gEOYZ67N8JPk58tkWtdtPeLz7lBnY6I5L3jdsr3S+A6A==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/win32-ia32": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.23.1.tgz", - "integrity": "sha512-BcaL0Vn6QwCwre3Y717nVHZbAa4UBEigzFm6VdsVdT/MbZ38xoj1X9HPkZhbmaBGUD1W8vxAfffbDe8bA6AKnQ==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/win32-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.23.1.tgz", - "integrity": "sha512-BHpFFeslkWrXWyUPnbKm+xYYVYruCinGcftSBaa8zoF9hZO4BcSCFUvHVTtzpIY6YzUnYtuEhZ+C9iEXjxnasg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=18" - } - }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.1.tgz", @@ -3624,6 +3233,7 @@ "engines": { "node": ">=8" } + }, "node_modules/asap": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", @@ -4214,6 +3824,8 @@ "license": "MIT", "engines": { "node": "^12.20.0 || >=14" + } + }, "node_modules/component-emitter": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.1.tgz", @@ -5512,6 +5124,8 @@ }, "funding": { "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/gopd": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", From 152e297ae024902249bdde5db96c6efc9f72518e Mon Sep 17 00:00:00 2001 From: Envyw6567 Date: Wed, 20 Nov 2024 14:05:36 +0900 Subject: [PATCH 2/9] =?UTF-8?q?fix:=20=EC=9A=94=EA=B5=AC=EC=82=AC=ED=95=AD?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/name-server/test/server.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/name-server/test/server.test.ts b/backend/name-server/test/server.test.ts index 56ad71cb..b9bf7273 100644 --- a/backend/name-server/test/server.test.ts +++ b/backend/name-server/test/server.test.ts @@ -1,9 +1,10 @@ -import dgram from 'dgram'; +import * as dgram from 'dgram'; import { encode, decode, Packet } from 'dns-packet'; import { Server } from '../src/server/server'; import { ServerConfig } from '../src/common/utils/validator/configuration.validator'; import { NORMAL_PACKET, NOT_EXIST_DOMAIN_PACKET } from './constant/packet'; import { TestProjectQuery } from './database/test-project.query'; +import { ProjectQuery } from '../src/database/query/project.query'; describe('DNS 서버는 ', () => { let server: Server; @@ -21,7 +22,7 @@ describe('DNS 서버는 ', () => { beforeAll(async () => { client = dgram.createSocket('udp4'); - server = new Server(config, new TestProjectQuery()); + server = new Server(config, new TestProjectQuery(), new ProjectQuery()); server.start(); await new Promise((resolve) => setTimeout(resolve, 100)); From 2fb1c609563d110b34a95aefaf633cc78429c851 Mon Sep 17 00:00:00 2001 From: Envyw6567 Date: Wed, 20 Nov 2024 14:05:48 +0900 Subject: [PATCH 3/9] =?UTF-8?q?fix:=20=EC=9A=94=EA=B5=AC=EC=82=AC=ED=95=AD?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/name-server/test/dns-response-builder.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/name-server/test/dns-response-builder.test.ts b/backend/name-server/test/dns-response-builder.test.ts index 10997c1e..57ac43b9 100644 --- a/backend/name-server/test/dns-response-builder.test.ts +++ b/backend/name-server/test/dns-response-builder.test.ts @@ -44,7 +44,7 @@ describe('DNSResponseBuilder의', () => { name: 'example.com', type: 'A', class: 'IN', - ttl: 300, + ttl: 86400, data: '127.0.0.1', }); }); From c1bcdd9699ab89b88f52f3ae06e2f6b98e8d3c89 Mon Sep 17 00:00:00 2001 From: Envyw6567 Date: Wed, 20 Nov 2024 14:06:50 +0900 Subject: [PATCH 4/9] =?UTF-8?q?debug:=20=EB=94=94=EB=B2=84=EA=B9=85?= =?UTF-8?q?=EC=9A=A9=20=EC=BD=98=EC=86=94=EB=A1=9C=EA=B7=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Nginx에서 UDP 데이터를 넘겨주는 과정에서 패킷 로그 확인용 --- backend/name-server/src/server/server.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/name-server/src/server/server.ts b/backend/name-server/src/server/server.ts index d2d0806f..14d5e5ec 100644 --- a/backend/name-server/src/server/server.ts +++ b/backend/name-server/src/server/server.ts @@ -2,13 +2,13 @@ import type { Socket } from 'dgram'; import { createSocket, type RemoteInfo } from 'dgram'; import { decode, encode } from 'dns-packet'; import type { DecodedPacket, Question } from 'dns-packet'; -import type { ServerConfig } from '../common/utils/validator/configuration.validator'; +import type { ServerConfig } from 'common/utils/validator/configuration.validator'; import { PacketValidator } from './utils/packet.validator'; import { DNSResponseBuilder } from './utils/dns-response-builder'; import { ResponseCode } from './constant/dns-packet.constant'; -import { logger } from '../common/utils/logger/console.logger'; +import { logger } from 'common/utils/logger/console.logger'; import { ServerError } from './error/server.error'; -import type { ProjectQueryInterface } from '../database/query/project.query.interface'; +import type { ProjectQueryInterface } from 'database/query/project.query.interface'; import type { DAURecorderInterface } from 'database/query/dau-recorder'; export class Server { @@ -33,7 +33,11 @@ export class Server { try { const query = decode(msg); const question = this.parseQuery(query); + + console.log(query); // TODO: 삭제 + logger.logQuery(question.name, remoteInfo); + await this.validateRequest(question.name); this.dauRecorder.recordAccess(question.name).catch((err) => { logger.error(`DAU recording failed for ${question.name}: ${err.message}`); From 45fdd74626a777d5d55d68ab51c33544696b6521 Mon Sep 17 00:00:00 2001 From: Envyw6567 Date: Wed, 20 Nov 2024 14:07:45 +0900 Subject: [PATCH 5/9] =?UTF-8?q?refactor:=20dev=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 로컬 mysql 접속 환경변수 추가 - start:dev 스크립트에 NODE_ENV 환경변수 추가 --- backend/name-server/package.json | 2 +- backend/name-server/src/app.ts | 12 +++++----- .../name-server/src/database/mysql/config.ts | 23 +++++++++++++------ backend/name-server/src/index.ts | 4 ++-- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/backend/name-server/package.json b/backend/name-server/package.json index 952986d0..32bd79fc 100644 --- a/backend/name-server/package.json +++ b/backend/name-server/package.json @@ -4,7 +4,7 @@ "description": "", "main": "src/index.ts", "scripts": { - "dev": "tsx watch src/index.ts", + "start:dev": "NODE_ENV=development tsx watch src/index.ts", "start": "tsx src/index.ts", "build": "tsc -p tsconfig.json && tsc-alias -p tsconfig.json", "tmp": "tsx src/index.ts", diff --git a/backend/name-server/src/app.ts b/backend/name-server/src/app.ts index 12e95354..d346b5bc 100644 --- a/backend/name-server/src/app.ts +++ b/backend/name-server/src/app.ts @@ -1,10 +1,10 @@ import { config } from 'dotenv'; -import type { ServerConfig } from './common/utils/validator/configuration.validator'; -import { ConfigurationValidator } from './common/utils/validator/configuration.validator'; -import { Server } from './server/server'; -import { db } from './database/mysql/mysql-database'; -import { logger } from './common/utils/logger/console.logger'; -import { ProjectQuery } from './database/query/project.query'; +import type { ServerConfig } from 'common/utils/validator/configuration.validator'; +import { ConfigurationValidator } from 'common/utils/validator/configuration.validator'; +import { Server } from 'server/server'; +import { db } from 'database/mysql/mysql-database'; +import { logger } from 'common/utils/logger/console.logger'; +import { ProjectQuery } from 'database/query/project.query'; import { DAURecorder } from 'database/query/dau-recorder'; config(); diff --git a/backend/name-server/src/database/mysql/config.ts b/backend/name-server/src/database/mysql/config.ts index e7c455bf..56816b2d 100644 --- a/backend/name-server/src/database/mysql/config.ts +++ b/backend/name-server/src/database/mysql/config.ts @@ -3,10 +3,19 @@ import type { PoolOptions } from 'mysql2/promise'; dotenv.config(); -export const poolConfig: PoolOptions = { - host: process.env.DB_HOST, - port: Number(process.env.DB_PORT), - user: process.env.DB_USERNAME, - password: process.env.DB_PASSWORD, - database: process.env.DB_NAME, -}; +export const poolConfig: PoolOptions = + process.env.NODE_ENV === 'development' + ? { + host: process.env.DEV_DB_HOST, + port: Number(process.env.DEV_DB_PORT), + user: process.env.DEV_DB_USERNAME, + password: process.env.DEV_DB_PASSWORD, + database: process.env.DEV_DB_NAME, + } + : { + host: process.env.DB_HOST, + port: Number(process.env.DB_PORT), + user: process.env.DB_USERNAME, + password: process.env.DB_PASSWORD, + database: process.env.DB_NAME, + }; diff --git a/backend/name-server/src/index.ts b/backend/name-server/src/index.ts index 79eaca25..26ff9b91 100644 --- a/backend/name-server/src/index.ts +++ b/backend/name-server/src/index.ts @@ -1,5 +1,5 @@ -import { Application } from './app'; -import { logger } from './common/utils/logger/console.logger'; +import { Application } from 'app'; +import { logger } from 'common/utils/logger/console.logger'; async function main(): Promise { const initializer = new Application(); From dd7e3427c55cb42b5b3074fac7800643d809c433 Mon Sep 17 00:00:00 2001 From: Envyw6567 Date: Wed, 20 Nov 2024 15:19:05 +0900 Subject: [PATCH 6/9] =?UTF-8?q?fix:=20health-check=20=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/constant/dns-packet.constant.ts | 6 ++--- .../server/constant/message-type.constants.ts | 8 ++++++ backend/name-server/src/server/server.ts | 26 +++++++++++++++---- .../src/server/utils/dns-response-builder.ts | 14 +++++----- .../src/server/utils/packet.validator.ts | 21 +++++++++++++++ .../test/dns-response-builder.test.ts | 8 +++--- 6 files changed, 64 insertions(+), 19 deletions(-) create mode 100644 backend/name-server/src/server/constant/message-type.constants.ts diff --git a/backend/name-server/src/server/constant/dns-packet.constant.ts b/backend/name-server/src/server/constant/dns-packet.constant.ts index b971a053..70c4561c 100644 --- a/backend/name-server/src/server/constant/dns-packet.constant.ts +++ b/backend/name-server/src/server/constant/dns-packet.constant.ts @@ -1,4 +1,4 @@ -export const DNSFlags = { +export const DNS_FLAGS = { AUTHORITATIVE_ANSWER: 0x0400, // 권한 있는 응답 (네임서버가 해당 도메인의 공식 서버일 때) TRUNCATED_RESPONSE: 0x0200, // 응답이 잘린 경우 (UDP 크기 제한 초과) RECURSION_DESIRED: 0x0100, // 재귀적 쿼리 요청 (클라이언트가 설정) @@ -7,10 +7,10 @@ export const DNSFlags = { CHECKING_DISABLED: 0x0010, // DNSSEC 검증 비활성화 } as const; -export const ResponseCode = { +export const RESPONSE_CODE = { NOERROR: 0, // 정상 응답 NXDOMAIN: 3, // 도메인이 존재하지 않음 SERVFAIL: 2, // 서버 에러 } as const; -export type ResponseCodeType = (typeof ResponseCode)[keyof typeof ResponseCode]; +export type ResponseCodeType = (typeof RESPONSE_CODE)[keyof typeof RESPONSE_CODE]; diff --git a/backend/name-server/src/server/constant/message-type.constants.ts b/backend/name-server/src/server/constant/message-type.constants.ts new file mode 100644 index 00000000..94d2ac47 --- /dev/null +++ b/backend/name-server/src/server/constant/message-type.constants.ts @@ -0,0 +1,8 @@ +export const MESSAGE_TYPE = { + DNS: 'DNS', + HEALTH_CHECK: 'HEALTH_CHECK', +} as const; + +export const MIN_DNS_MESSAGE_LENGTH = 12; + +export type MessageType = (typeof MESSAGE_TYPE)[keyof typeof MESSAGE_TYPE]; diff --git a/backend/name-server/src/server/server.ts b/backend/name-server/src/server/server.ts index 14d5e5ec..4f5e00ac 100644 --- a/backend/name-server/src/server/server.ts +++ b/backend/name-server/src/server/server.ts @@ -5,11 +5,12 @@ import type { DecodedPacket, Question } from 'dns-packet'; import type { ServerConfig } from 'common/utils/validator/configuration.validator'; import { PacketValidator } from './utils/packet.validator'; import { DNSResponseBuilder } from './utils/dns-response-builder'; -import { ResponseCode } from './constant/dns-packet.constant'; +import { RESPONSE_CODE } from './constant/dns-packet.constant'; import { logger } from 'common/utils/logger/console.logger'; import { ServerError } from './error/server.error'; import type { ProjectQueryInterface } from 'database/query/project.query.interface'; import type { DAURecorderInterface } from 'database/query/dau-recorder'; +import { MESSAGE_TYPE } from 'server/constant/message-type.constants'; export class Server { private server: Socket; @@ -31,11 +32,16 @@ export class Server { private async handleMessage(msg: Buffer, remoteInfo: RemoteInfo): Promise { try { + const messageType = PacketValidator.validateMessageType(msg); + + if (messageType === MESSAGE_TYPE.HEALTH_CHECK) { + await this.handleHealthCheck(remoteInfo); + return; + } + const query = decode(msg); const question = this.parseQuery(query); - console.log(query); // TODO: 삭제 - logger.logQuery(question.name, remoteInfo); await this.validateRequest(question.name); @@ -44,7 +50,7 @@ export class Server { }); const response = new DNSResponseBuilder(this.config, query) - .addAnswer(ResponseCode.NOERROR, question) + .addAnswer(RESPONSE_CODE.NOERROR, question) .build(); const responseMsg = encode(response); @@ -54,6 +60,16 @@ export class Server { } } + private async handleHealthCheck(remoteInfo: RemoteInfo): Promise { + try { + const healthCheckResponse = Buffer.from([]); + + await this.sendResponse(healthCheckResponse, remoteInfo); + } catch (error) { + logger.error(`Health check response failed: ${(error as Error).message}`); + } + } + private async validateRequest(name: string): Promise { if (await this.projectQuery.existsByDomain(name)) { return; @@ -93,7 +109,7 @@ export class Server { const errorMessage = `Failed to process DNS query from ${remoteInfo.address}:${remoteInfo.port}`; const response = new DNSResponseBuilder(this.config, query) - .addAnswer(ResponseCode.NXDOMAIN) + .addAnswer(RESPONSE_CODE.NXDOMAIN) .build(); const responseMsg = encode(response); diff --git a/backend/name-server/src/server/utils/dns-response-builder.ts b/backend/name-server/src/server/utils/dns-response-builder.ts index 42e4a945..e444a585 100644 --- a/backend/name-server/src/server/utils/dns-response-builder.ts +++ b/backend/name-server/src/server/utils/dns-response-builder.ts @@ -2,7 +2,7 @@ import type { Packet, Question, RecordClass } from 'dns-packet'; import type { ServerConfig } from '../../common/utils/validator/configuration.validator'; import { PacketValidator } from './packet.validator'; import type { ResponseCodeType } from '../constant/dns-packet.constant'; -import { DNSFlags, ResponseCode } from '../constant/dns-packet.constant'; +import { DNS_FLAGS, RESPONSE_CODE } from '../constant/dns-packet.constant'; interface DNSResponse extends Packet { answers: Array<{ @@ -30,10 +30,10 @@ export class DNSResponseBuilder { } private createFlags(query: Packet): number { - const flags = DNSFlags.AUTHORITATIVE_ANSWER; + const flags = DNS_FLAGS.AUTHORITATIVE_ANSWER; - if (PacketValidator.hasFlags(query) && query.flags & DNSFlags.RECURSION_DESIRED) { - return flags | DNSFlags.RECURSION_DESIRED; + if (PacketValidator.hasFlags(query) && query.flags & DNS_FLAGS.RECURSION_DESIRED) { + return flags | DNS_FLAGS.RECURSION_DESIRED; } return flags; @@ -42,11 +42,11 @@ export class DNSResponseBuilder { addAnswer(rcode: ResponseCodeType, question?: Question): this { this.response.flags = 0x8000; - if (this.response.flags && rcode === ResponseCode.NXDOMAIN) { - this.response.flags |= ResponseCode.NXDOMAIN; + if (this.response.flags && rcode === RESPONSE_CODE.NXDOMAIN) { + this.response.flags |= RESPONSE_CODE.NXDOMAIN; } - if (rcode === ResponseCode.NOERROR && question) { + if (rcode === RESPONSE_CODE.NOERROR && question) { this.response.answers = [ { name: question.name, diff --git a/backend/name-server/src/server/utils/packet.validator.ts b/backend/name-server/src/server/utils/packet.validator.ts index 7642daed..268cd507 100644 --- a/backend/name-server/src/server/utils/packet.validator.ts +++ b/backend/name-server/src/server/utils/packet.validator.ts @@ -1,4 +1,9 @@ import type { Packet, Question } from 'dns-packet'; +import { + MESSAGE_TYPE, + MessageType, + MIN_DNS_MESSAGE_LENGTH, +} from 'server/constant/message-type.constants'; type TypeGuardResult = T extends Packet ? T & { questions: Question[] } : never; @@ -14,4 +19,20 @@ export class PacketValidator { static validatePacket(packet: Packet): boolean { return this.hasQuestions(packet) && this.hasFlags(packet); } + + static validateMessageType(msg: Buffer): MessageType { + if (msg.length >= MIN_DNS_MESSAGE_LENGTH) { + const flags = msg.readUInt16BE(2); + const isQuery = (flags & 0x8000) === 0; + + if (isQuery) { + const questionCount = msg.readUInt16BE(4); + if (questionCount > 0) { + return MESSAGE_TYPE.DNS; + } + } + } + + return MESSAGE_TYPE.HEALTH_CHECK; + } } diff --git a/backend/name-server/test/dns-response-builder.test.ts b/backend/name-server/test/dns-response-builder.test.ts index 57ac43b9..afab81b3 100644 --- a/backend/name-server/test/dns-response-builder.test.ts +++ b/backend/name-server/test/dns-response-builder.test.ts @@ -1,7 +1,7 @@ import { DNSResponseBuilder } from '../src/server/utils/dns-response-builder'; import type { Packet } from 'dns-packet'; import { PacketValidator } from '../src/server/utils/packet.validator'; -import { DNSFlags, ResponseCode } from '../src/server/constant/dns-packet.constant'; +import { DNS_FLAGS, RESPONSE_CODE } from '../src/server/constant/dns-packet.constant'; describe('DNSResponseBuilder의', () => { const mockConfig = { @@ -12,7 +12,7 @@ describe('DNSResponseBuilder의', () => { const mockQuery: Packet = { type: 'query', id: 1234, - flags: DNSFlags.RECURSION_DESIRED, + flags: DNS_FLAGS.RECURSION_DESIRED, questions: [ { name: 'example.com', @@ -29,14 +29,14 @@ describe('DNSResponseBuilder의', () => { expect(response.id).toBe(mockQuery.id); expect(response.type).toBe('response'); - expect(response.flags).toBe(DNSFlags.AUTHORITATIVE_ANSWER | DNSFlags.RECURSION_DESIRED); + expect(response.flags).toBe(DNS_FLAGS.AUTHORITATIVE_ANSWER | DNS_FLAGS.RECURSION_DESIRED); }); test('addAnswer()는 올바른 정보를 담은 answer를 추가해야 합니다.', () => { const builder = new DNSResponseBuilder(mockConfig, mockQuery); if (!PacketValidator.hasQuestions(mockQuery)) return; - builder.addAnswer(ResponseCode.NOERROR, mockQuery.questions[0]); + builder.addAnswer(RESPONSE_CODE.NOERROR, mockQuery.questions[0]); const response = builder.build(); expect(response.answers).toHaveLength(1); From 4559b4323d7b172224c3d7de4b4d45795f51ffbb Mon Sep 17 00:00:00 2001 From: Envyw6567 Date: Wed, 20 Nov 2024 16:31:07 +0900 Subject: [PATCH 7/9] =?UTF-8?q?fix:=20server=20=ED=86=B5=ED=95=A9=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9D=98=20server=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20=EC=9D=B8=EC=9E=90=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - dev 환경에서 clickhouse 데이터베이스 연결이 dev 환경변수를 사용하도록 변경 --- .../clickhouse/config/clickhouse.config.ts | 20 +++++++++++++------ .../src/database/query/dau-recorder.ts | 1 + backend/name-server/test/server.test.ts | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/backend/name-server/src/database/clickhouse/config/clickhouse.config.ts b/backend/name-server/src/database/clickhouse/config/clickhouse.config.ts index 4406760a..26022575 100644 --- a/backend/name-server/src/database/clickhouse/config/clickhouse.config.ts +++ b/backend/name-server/src/database/clickhouse/config/clickhouse.config.ts @@ -1,8 +1,16 @@ import { ClickHouseClientConfigOptions } from '@clickhouse/client'; -export const clickhouseConfig: ClickHouseClientConfigOptions = { - url: process.env.CLICKHOUSE_URL || 'http://localhost:8123', - username: process.env.CLICKHOUSE_USERNAME || 'default', - password: process.env.CLICKHOUSE_PASSWORD || '', - database: process.env.CLICKHOUSE_DATABASE, -}; +export const clickhouseConfig: ClickHouseClientConfigOptions = + process.env.NODE_ENV === 'development' + ? { + url: process.env.DEV_CLICKHOUSE_URL, + username: process.env.DEV_CLICKHOUSE_USERNAME, + password: process.env.DEV_CLICKHOUSE_PASSWORD, + database: process.env.DEV_CLICKHOUSE_DATABASE, + } + : { + url: process.env.CLICKHOUSE_URL || 'http://localhost:8123', + username: process.env.CLICKHOUSE_USERNAME || 'default', + password: process.env.CLICKHOUSE_PASSWORD || '', + database: process.env.CLICKHOUSE_DATABASE, + }; diff --git a/backend/name-server/src/database/query/dau-recorder.ts b/backend/name-server/src/database/query/dau-recorder.ts index e5f1c27e..036bf9bf 100644 --- a/backend/name-server/src/database/query/dau-recorder.ts +++ b/backend/name-server/src/database/query/dau-recorder.ts @@ -6,6 +6,7 @@ export interface DAURecorderInterface { export class DAURecorder implements DAURecorderInterface { private clickhouseClient = ClickhouseDatabase.getInstance(); + public async recordAccess(domain: string): Promise { const date = new Date().toISOString().slice(0, 10); const values = [{ domain, date, access: 1 }]; diff --git a/backend/name-server/test/server.test.ts b/backend/name-server/test/server.test.ts index b9bf7273..f8e25e67 100644 --- a/backend/name-server/test/server.test.ts +++ b/backend/name-server/test/server.test.ts @@ -3,8 +3,8 @@ import { encode, decode, Packet } from 'dns-packet'; import { Server } from '../src/server/server'; import { ServerConfig } from '../src/common/utils/validator/configuration.validator'; import { NORMAL_PACKET, NOT_EXIST_DOMAIN_PACKET } from './constant/packet'; -import { TestProjectQuery } from './database/test-project.query'; import { ProjectQuery } from '../src/database/query/project.query'; +import { DAURecorder } from '../src/database/query/dau-recorder'; describe('DNS 서버는 ', () => { let server: Server; @@ -22,7 +22,7 @@ describe('DNS 서버는 ', () => { beforeAll(async () => { client = dgram.createSocket('udp4'); - server = new Server(config, new TestProjectQuery(), new ProjectQuery()); + server = new Server(config, new DAURecorder(), new ProjectQuery()); server.start(); await new Promise((resolve) => setTimeout(resolve, 100)); From c1d1e089d7797715fa2ffd2ddd9aead32bf460eb Mon Sep 17 00:00:00 2001 From: Envyw6567 Date: Wed, 20 Nov 2024 16:32:41 +0900 Subject: [PATCH 8/9] =?UTF-8?q?fix:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9?= =?UTF-8?q?=20server=20=EA=B0=9D=EC=B2=B4=EC=9D=98=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=EB=B2=A0=EC=9D=B4=EC=8A=A4=EB=A1=9C=20sqlite=EB=A5=BC?= =?UTF-8?q?=20=EC=93=B0=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/name-server/test/server.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/name-server/test/server.test.ts b/backend/name-server/test/server.test.ts index f8e25e67..3dc1c58d 100644 --- a/backend/name-server/test/server.test.ts +++ b/backend/name-server/test/server.test.ts @@ -3,8 +3,8 @@ import { encode, decode, Packet } from 'dns-packet'; import { Server } from '../src/server/server'; import { ServerConfig } from '../src/common/utils/validator/configuration.validator'; import { NORMAL_PACKET, NOT_EXIST_DOMAIN_PACKET } from './constant/packet'; -import { ProjectQuery } from '../src/database/query/project.query'; import { DAURecorder } from '../src/database/query/dau-recorder'; +import { TestProjectQuery } from './database/test-project.query'; describe('DNS 서버는 ', () => { let server: Server; @@ -22,7 +22,7 @@ describe('DNS 서버는 ', () => { beforeAll(async () => { client = dgram.createSocket('udp4'); - server = new Server(config, new DAURecorder(), new ProjectQuery()); + server = new Server(config, new DAURecorder(), new TestProjectQuery()); server.start(); await new Promise((resolve) => setTimeout(resolve, 100)); From cfaaa09592871f6535e7e4ee51d88cc171367d21 Mon Sep 17 00:00:00 2001 From: Envyw6567 Date: Wed, 20 Nov 2024 16:36:02 +0900 Subject: [PATCH 9/9] =?UTF-8?q?fix:=20=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=B2=A0?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=20=EC=82=BD=EC=9E=85=20=EC=8B=9C=20lowercase?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/name-server/src/database/query/dau-recorder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/name-server/src/database/query/dau-recorder.ts b/backend/name-server/src/database/query/dau-recorder.ts index 036bf9bf..a5616c5f 100644 --- a/backend/name-server/src/database/query/dau-recorder.ts +++ b/backend/name-server/src/database/query/dau-recorder.ts @@ -9,7 +9,7 @@ export class DAURecorder implements DAURecorderInterface { public async recordAccess(domain: string): Promise { const date = new Date().toISOString().slice(0, 10); - const values = [{ domain, date, access: 1 }]; + const values = [{ domain: domain.toLowerCase(), date, access: 1 }]; try { await this.clickhouseClient.insert({ table: 'dau',