public inbox for gwml@vger.gnuweeb.org
 help / color / mirror / Atom feed
From: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
To: Ahmad Gani <reyuki@gnuweeb.org>
Cc: Ammar Faizi <ammarfaizi2@gnuweeb.org>,
	"GNU/Weeb Mailing List" <gwml@vger.gnuweeb.org>
Subject: Re: [PATCH gwproxy v8 2/2] gwproxy: refactor code base to add experimental raw DNS backend
Date: Sat, 6 Sep 2025 20:30:54 +0700	[thread overview]
Message-ID: <CAOG64qOL4Wi_Nbq-gMYFKDSUdiqVyb2ZxN3tuiYQpt=JtmtpgQ@mail.gmail.com> (raw)
In-Reply-To: <CAADvAgpdFCbmFUu+jJSb1jzaw2tM4r76vEUtvhwo9nadk2RH8A@mail.gmail.com>

On Sat, Sep 6, 2025 at 7:59 PM Ahmad Gani wrote:
> So, what are our options in this case?

Ok, good question. That's probably the most challenging part of this
implementation. It will require careful planning to ensure that all
edge cases are handled properly.

        My initial thought is, the most efficient data structure for
this task would be an array of "struct gwp_conn_pair". Let's drop the
atomic counter proposal. I suggest having thread-local incrementing
counters.

        So the plan is, each thread has its own DNS resolver. That
will simplify things a lot, because we don't need to worry about
synchronization across threads. Each thread will have its own "struct
gwp_conn_pair" array that maps the txid to your session.

        That also means, each thread can only have a max of 65536
concurrent connections. We can expand it by having more than one
array. But I think that can be done later. Here's the initial plan
(may still change as we go and discover more requirements):
        1) Each thread has its own DNS resolver.
        2) Each DNS resolver has:
            struct gwp_conn_pair *pairs[65536];
            On a 64-bit machine, that's around 0.5MB per thread.
            On a 32-bit machine, that's around 0.25MB per thread.
            You may as well allocate it lazily by calling realloc()
starting from a small number and keep reallocating as the number grows
to keep the memory footprint low.
        3) The array index will be the txid.
        4) Each entry in the array will be a pointer to a struct
gwp_conn_pair that contains the session information.

        But note that, since the lifetime of the "struct
gwp_conn_pair" is now tied to both:
        1) The SOCKS5 session, and
        2) The DNS resolution query.
You will need to make "struct gwp_conn_pair" refcounted to avoid
use-after-free in case the DNS resolution query completes after the
SOCKS5 session has been killed.

        I will think more about this and post something about it later
when I have something better in my mind. Let me know your design if
you have one too.

  reply	other threads:[~2025-09-06 13:31 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-29  7:55 [PATCH gwproxy v8 0/2] Initial work on integration of DNS parser lib in gwproxy Ahmad Gani
2025-08-29  7:55 ` [PATCH gwproxy v8 1/2] dnsparser: Add dns parser code Ahmad Gani
2025-08-29  7:55 ` [PATCH gwproxy v8 2/2] gwproxy: refactor code base to add experimental raw DNS backend Ahmad Gani
2025-09-05 16:26   ` Alviro Iskandar Setiawan
2025-09-06  4:32     ` Ahmad Gani
2025-09-06  5:16       ` Ahmad Gani
2025-09-06  6:17       ` Ahmad Gani
2025-09-06  6:48         ` Ahmad Gani
2025-09-06  7:02           ` Alviro Iskandar Setiawan
2025-09-06  6:47       ` Alviro Iskandar Setiawan
2025-09-09  2:38         ` reyuki
2025-09-06 11:27       ` Ahmad Gani
2025-09-06 12:01         ` Alviro Iskandar Setiawan
2025-09-06 12:58         ` Ahmad Gani
2025-09-06 13:30           ` Alviro Iskandar Setiawan [this message]
2025-09-06 13:44             ` Alviro Iskandar Setiawan
2025-09-06 14:26             ` Ahmad Gani
2025-09-06 14:30               ` Alviro Iskandar Setiawan
2025-09-07  4:22             ` Ammar Faizi
2025-09-07  5:57               ` Ammar Faizi
2025-09-07  6:39               ` Ahmad Gani
2025-09-07  6:40                 ` Ahmad Gani
2025-09-07  6:43                   ` Ammar Faizi
2025-09-07  7:06                 ` Ammar Faizi
2025-09-07  7:17                   ` Ahmad Gani
2025-09-07  9:52               ` Ahmad Gani
2025-09-07 10:19                 ` Ammar Faizi
2025-09-07 10:36                   ` Ahmad Gani
2025-09-06  7:14     ` Alviro Iskandar Setiawan
2025-09-06  7:21       ` Ahmad Gani
2025-09-06  7:47   ` Alviro Iskandar Setiawan
2025-09-06 11:01     ` Ahmad Gani
2025-09-05  9:18 ` [PATCH gwproxy v8 0/2] Initial work on integration of DNS parser lib in gwproxy Ammar Faizi
2025-09-05  9:34   ` Alviro Iskandar Setiawan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOG64qOL4Wi_Nbq-gMYFKDSUdiqVyb2ZxN3tuiYQpt=JtmtpgQ@mail.gmail.com' \
    --to=alviro.iskandar@gnuweeb.org \
    --cc=ammarfaizi2@gnuweeb.org \
    --cc=gwml@vger.gnuweeb.org \
    --cc=reyuki@gnuweeb.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox