From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server-vie001.gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_DBL_BLOCKED_OPENDNS, URIBL_ZEN_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=3.4.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=new2025; t=1753931351; bh=H7T6qs7wAJkxi0I/Ak5oEhGeE2WJKLQGwKSGTV29wEE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:Message-ID:Date:From:Reply-To:Subject:To: Cc:In-Reply-To:References:Resent-Date:Resent-From:Resent-To: Resent-Cc:User-Agent:Content-Type:Content-Transfer-Encoding; b=mvXMq4rF4YesLTj21qMP888XJWd2MFayRvb/TImnfotM6P59exKd3z1SF0nDON6ES EjdOPl7sZ/WobMy8SkIk3YgEbnVUeKSLvi0B03Q/d3NkF+/xNStio3G1fIZiGux58T Ch1l2/cUNvUwge8z0Wx09kiLxe/gvYquT6+NHYSavUV348oE9X/Q6mD6suAXK9oLT2 1OBAahsDFCE5IyICldU99N7ofvbCdiEQvnJLY+h0cQkDZ+BR+KNNiYNJru1szAZiMP +QNlAPpu7INqfGVuPKrgdvgaAEEGnhqgkKXsSOYVuFoKRvJX7aM9wwoDIypTa4JOjN Vk1DuoVJfTO2A== Received: from zero (unknown [182.253.228.104]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id 00DB73126F59; Thu, 31 Jul 2025 03:09:09 +0000 (UTC) From: Ahmad Gani To: Ammar Faizi Cc: Ahmad Gani , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH gwproxy v1 0/3] Initial work for DNS lookup implementation Date: Thu, 31 Jul 2025 10:07:43 +0700 Message-ID: <20250731030856.366368-1-reyuki@gnuweeb.org> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Hi Chief, This is initial work of dns lookup feature, The patches aren't final, but it's enough to get a grasp of what the interface looks like. I've provided a temporary entry point main function to test it. There are 3 patches in this series: - create net.h and net.c to store network related functionality. - allow only port string number in service parameter of gwp_dns_queue - initial work for implementation of C-ares-like getaddrinfo function I propose to move the utility or helper function (that is commonly used in multiple places) to net.h and net.c, e.g., struct gwp_sockaddr is useful, and it possibly will be used in multiple places as the project expands. I think it would be better to limit the service field to only contain the port number, as SOCKS5 always uses a string port number. in reply to Telegram chat [1]: > (( It's the only reason we need a dedicated thread for resolving DNS )) Is it preferred to use the current model (spawning dedicated DNS threads) and make the behavior of the resolver the same as getaddrinfo (blocking)? So far I've created the addrinfo interfaces with C-ares style and tested it; although, it's still blocking. I would like to know the numbers for comparison between the thread model vs. the asynchronous model. Which approach is best for this scenario/case (DNS resolution)? I feel like multi-threading is much faster than single-threading, as it's executed in true parallel (on a multi-core system) compared to concurrently doing things with an event notification mechanism. My general understanding of parallel and concurrent is derived from this definition on the Stack Overflow answer [2]: > Concurrency is when two or more tasks can start, run, and complete in > overlapping time periods. It doesn't necessarily mean they'll ever both > be running at the same instant. For example, multitasking on > a single-core machine. Parallelism is when tasks literally run at the > same time, e.g., on a multicore processor. I also noticed that in the C-ares example [3], they recommend using the event thread example, and it is similar to the io_uring model in my perspective, where the operation is executed internally instead of letting the caller poll for readiness with ares_process_fd. Maybe we can mimic this aspect? I will remove the callback and make it blocking to make it compatible with the current thread model, but let's hear your opinion first. I would like to request at least 40 revisions [4] to ensure I've learned something, so please treat me like I'm a dumb AI agent [5] (prompt me anything, I need more input!) and please review, thanks! [1]: - https://t.me/GNUWeeb/1192156 [2]: - https://stackoverflow.com/a/1050257/22382954 [3]: - https://c-ares.org/docs.html#examples [4]: - https://t.me/GNUWeeb/625966 - https://lore.kernel.org/lkml/20201104145430.300542-1-jarkko.sakkinen@linux.intel.com/T/ [5]: - https://www.youtube.com/watch?v=P_O0ynyLOtI Ahmad Gani (3): dnslookup: split common functionality and struct into net.c dnslookup: Allow only port string number dnslookup: Initial work for implementation of C-ares-like getaddrinfo function Makefile | 1 + man/gwp_dns_queue.3 | 2 +- src/gwproxy/dns.h | 12 +- src/gwproxy/dnslookup.c | 286 +++++++++++++++++++++++++++++++ src/gwproxy/dnslookup.h | 110 ++++++++++++ src/gwproxy/dnsparser.c | 362 ++++++++++++++++++++++++++++++++++++++++ src/gwproxy/dnsparser.h | 188 +++++++++++++++++++++ src/gwproxy/gwproxy.c | 29 ---- src/gwproxy/net.c | 108 ++++++++++++ src/gwproxy/net.h | 27 +++ 10 files changed, 1085 insertions(+), 40 deletions(-) create mode 100644 src/gwproxy/dnslookup.c create mode 100644 src/gwproxy/dnslookup.h create mode 100644 src/gwproxy/dnsparser.c create mode 100644 src/gwproxy/dnsparser.h create mode 100644 src/gwproxy/net.c create mode 100644 src/gwproxy/net.h base-commit: 0753f2d766e85fcbffc1f83dfd4e67d6206591cb -- Ahmad Gani