Skip to content

Use proxy for dns and ssl templates #6255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

ShubhamRasal
Copy link
Contributor

@ShubhamRasal ShubhamRasal commented Jun 10, 2025

Proposed changes

  • while using template execute level function we need to override custom dialer

Summary by CodeRabbit

  • New Features

    • Added the ability to override the network dialer in various protocols, allowing for custom dialer usage in network, SSL, HTTP, and WebSocket requests.
    • Introduced proxy support for DNS client connections based on executor options.
  • Refactor

    • Updated DNS and network client instantiation to support structured options and proxy configuration.
    • Localized dialer usage within request instances, replacing global dialer references.
    • Streamlined dialer configuration by removing direct dialer setters and integrating custom dialer fields.

- while using template execute level function we need to override custom dialer
@auto-assign auto-assign bot requested a review from dwisiswant0 June 10, 2025 15:21
@ShubhamRasal ShubhamRasal self-assigned this Jun 10, 2025
Copy link
Contributor

coderabbitai bot commented Jun 10, 2025

Walkthrough

The changes introduce support for overriding the default dialer in network-related protocol executors by propagating an OverrideFastdialer option through various layers. Structs and methods are updated to accept and pass this custom dialer. The DNS client instantiation now uses a new options-based constructor including proxy support. The SetDialer method was removed from the network request. Additionally, HTTP requests now initialize and use a dialer instance instead of a global dialer.

Changes

File(s) Change Summary
pkg/protocols/dns/dnsclientpool/clientpool.go Added Proxy field to Configuration; updated Hash to include Proxy; use retryabledns.NewWithOptions with proxy option.
pkg/protocols/dns/dns.go Set DNS client proxy from options.Options.AliveSocksProxy in getDnsClient.
pkg/protocols/network/network.go Compile passes OverrideFastdialer in config; removed SetDialer method.
pkg/protocols/network/networkclientpool/clientpool.go Added CustomDialer to Configuration; Get returns CustomDialer if set, else default client.
pkg/protocols/protocols.go Added OverrideFastdialer field to ExecutorOptions; imported fastdialer.
pkg/protocols/ssl/ssl.go Compile passes OverrideFastdialer in config to network client pool.
pkg/protocols/websocket/websocket.go Compile passes OverrideFastdialer from options to network client pool.
pkg/protocols/http/http.go Added dialer field to Request; initialized it via networkclientpool.Get with custom dialer config in Compile.
pkg/protocols/http/request.go Replaced global dialer usage with instance request.dialer in methods executeRequest and addCNameIfAvailable.
pkg/protocols/network/request.go Removed protocolstate import; replaced global dialer with request.dialer in getOpenPorts.

Sequence Diagram(s)

sequenceDiagram
    participant Executor as ExecutorOptions
    participant Protocol as Protocol Request
    participant Pool as NetworkClientPool

    Executor->>Protocol: Pass OverrideFastdialer in options
    Protocol->>Pool: Get(config{CustomDialer: options.OverrideFastdialer})
    alt CustomDialer is set
        Pool-->>Protocol: Return CustomDialer
    else
        Pool-->>Protocol: Return normalClient
    end
Loading

Possibly related PRs

Suggested reviewers

  • dogancanbakir
  • ehsandeep

Poem

In tunnels of code where the fast dialers run,
A rabbit hops in—now the override’s begun!
With options passed neatly, and proxies in tow,
The network connections are ready to go.
So here’s to new pathways, both nimble and spry—
The protocols leap, and the packets all fly!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7214fa1 and 40f3db5.

📒 Files selected for processing (2)
  • pkg/protocols/http/http.go (4 hunks)
  • pkg/protocols/network/request.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/protocols/network/request.go
  • pkg/protocols/http/http.go
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Tests (macOS-latest)
  • GitHub Check: Tests (windows-latest)
  • GitHub Check: Tests (ubuntu-latest)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4859df and 2469d46.

📒 Files selected for processing (6)
  • pkg/protocols/dns/dnsclientpool/clientpool.go (1 hunks)
  • pkg/protocols/network/network.go (1 hunks)
  • pkg/protocols/network/networkclientpool/clientpool.go (2 hunks)
  • pkg/protocols/protocols.go (2 hunks)
  • pkg/protocols/ssl/ssl.go (2 hunks)
  • pkg/protocols/websocket/websocket.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
pkg/protocols/websocket/websocket.go (2)
pkg/protocols/network/networkclientpool/clientpool.go (2)
  • Get (34-41)
  • Configuration (24-26)
pkg/types/types.go (1)
  • Options (30-452)
pkg/protocols/protocols.go (1)
pkg/protocols/common/protocolstate/state.go (1)
  • Dialer (24-24)
pkg/protocols/dns/dnsclientpool/clientpool.go (1)
pkg/types/types.go (1)
  • Options (30-452)
pkg/protocols/network/network.go (1)
pkg/protocols/network/networkclientpool/clientpool.go (2)
  • Get (34-41)
  • Configuration (24-26)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint
🔇 Additional comments (8)
pkg/protocols/protocols.go (2)

8-8: LGTM! Clean import addition.

The fastdialer import is appropriately added to support the new OverrideFastdialer field.


136-137: LGTM! Well-designed field addition.

The OverrideFastdialer field is well-named, properly typed, and includes clear documentation. This provides a clean way to override the default dialer across protocol implementations.

pkg/protocols/dns/dnsclientpool/clientpool.go (1)

86-90: LGTM! Improved constructor with proxy support.

The change from positional parameters to a structured Options approach is a good improvement. The addition of proxy support via options.AliveSocksProxy aligns with the PR objective to enable proxy functionality for DNS templates.

pkg/protocols/websocket/websocket.go (1)

103-105: LGTM! Consistent implementation of dialer override.

The change correctly passes the OverrideFastdialer through the networkclientpool.Configuration, maintaining consistency with other protocol implementations in this PR.

pkg/protocols/network/networkclientpool/clientpool.go (2)

24-26: LGTM! Clean configuration struct addition.

The OverrideDialer field is appropriately typed and provides a clean way to pass custom dialers through the configuration.


36-38: LGTM! Proper override pattern implementation.

The logic correctly returns the override dialer when provided, with appropriate null safety checks. The fallback to normalClient maintains backward compatibility.

pkg/protocols/network/network.go (1)

240-242: LGTM! Consistent dialer override implementation.

The change correctly integrates with the network client pool's new configuration-based approach, passing the OverrideFastdialer when available. This maintains consistency with the pattern established across other protocol implementations.

pkg/protocols/ssl/ssl.go (1)

118-120: LGTM: Proxy support correctly implemented.

The change properly passes the OverrideFastdialer from executor options to the network client pool, enabling proxy functionality for SSL templates. This aligns with the PR objective to support proxy usage in DNS and SSL templates.

- proxy client is shared between non proxy requests
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
pkg/protocols/dns/dns.go (1)

190-204: 🛠️ Refactor suggestion

Duplicate len(request.Resolvers) guard wipes the resolver list

The inner if len(request.Resolvers) > 0 { … } repeats the outer guard and appends any expression-evaluated resolvers to dnsClientOptions.Resolvers, but the assignment right after it

dnsClientOptions.Resolvers = request.Resolvers

overwrites the previously built slice, effectively discarding the evaluated items.

-    if len(request.Resolvers) > 0 {
-        for _, resolver := range request.Resolvers {
-
-            dnsClientOptions.Resolvers = append(dnsClientOptions.Resolvers, resolver)
-        }
-    }
-    dnsClientOptions.Resolvers = request.Resolvers
+    for _, resolver := range request.Resolvers {
+
+        dnsClientOptions.Resolvers = append(dnsClientOptions.Resolvers, resolver)
+    }

Removing the redundant outer check and not resetting dnsClientOptions.Resolvers preserves the resolved/templated entries.
This is pre-existing code but it lies in the modified hunk; fixing it now prevents subtle resolver-selection bugs.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8eccc46 and a7c54e8.

📒 Files selected for processing (2)
  • pkg/protocols/dns/dns.go (1 hunks)
  • pkg/protocols/dns/dnsclientpool/clientpool.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/protocols/dns/dnsclientpool/clientpool.go
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Tests (macOS-latest)
  • GitHub Check: Tests (ubuntu-latest)
  • GitHub Check: Tests (windows-latest)

Comment on lines 186 to 189
dnsClientOptions := &dnsclientpool.Configuration{
Retries: request.Retries,
Proxy: options.Options.AliveSocksProxy,
}
Copy link
Contributor

@coderabbitai coderabbitai bot Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Pass the override dialer alongside the proxy for full template-level control

Other protocol implementations in this PR (network, ssl, websocket) forward options.OverrideFastdialer so that a template can completely replace the default fast-dialer.
DNS now only forwards the SOCKS proxy string which leaves the dialer override path unused for DNS templates and breaks the symmetry promised in the PR description.

 dnsClientOptions := &dnsclientpool.Configuration{
     Retries: request.Retries,
     Proxy:   options.Options.AliveSocksProxy,
+    // Keep behaviour consistent with other protocol pools
+    CustomDialer: options.OverrideFastdialer,
 }

Please verify that dnsclientpool.Configuration already exposes a CustomDialer (or similar) field; if not, extend it as was done for networkclientpool.
Failing to forward the dialer means DNS templates still funnel through the global fast-dialer even when the user explicitly asked for an override.


🏁 Script executed:

#!/bin/bash
# Inspect dnsclientpool package for Configuration and CustomDialer
grep -R "package dnsclientpool" -n pkg/protocols/dns
grep -R "type Configuration" -n pkg/protocols/dns
grep -R "CustomDialer" -n pkg/protocols/dns

# Compare with networkclientpool implementation
grep -R "package networkclientpool" -n pkg/protocols/network
grep -R "type Configuration" -n pkg/protocols/network
grep -R "CustomDialer" -n pkg/protocols/network

Length of output: 1021


Extend DNS client configuration to support dialer overrides

To restore symmetry with other protocol pools, add a CustomDialer field to the DNS client configuration and forward the override in dns.go:

• In pkg/protocols/dns/dnsclientpool/clientpool.go, modify the Configuration struct:

 type Configuration struct {
     Retries    int
     Proxy      string
+    CustomDialer *fastdialer.Dialer
 }

(Remember to import the fastdialer package.)

• In pkg/protocols/dns/dns.go, update the options passed into the pool:

 dnsClientOptions := &dnsclientpool.Configuration{
     Retries: request.Retries,
     Proxy:   options.Options.AliveSocksProxy,
+    CustomDialer: options.OverrideFastdialer,
 }

This ensures DNS templates can fully override the default fast-dialer just like network, SSL, and WebSocket.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dnsClientOptions := &dnsclientpool.Configuration{
Retries: request.Retries,
Proxy: options.Options.AliveSocksProxy,
}
dnsClientOptions := &dnsclientpool.Configuration{
Retries: request.Retries,
Proxy: options.Options.AliveSocksProxy,
// Keep behaviour consistent with other protocol pools
CustomDialer: options.OverrideFastdialer,
}
🤖 Prompt for AI Agents
In pkg/protocols/dns/dns.go around lines 186 to 189, the
dnsclientpool.Configuration is only set with Retries and Proxy, but it does not
forward the OverrideFastdialer option. To fix this, first verify and if missing,
add a CustomDialer field to the Configuration struct in
pkg/protocols/dns/dnsclientpool/clientpool.go, importing the fastdialer package
as needed. Then, update the dnsClientOptions initialization in dns.go to include
options.OverrideFastdialer assigned to the new CustomDialer field, ensuring DNS
templates can override the default fast-dialer consistently with other
protocols.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dogancanbakir Teşekkürler, onayınızı aldım. DNS için de CustomDialer’ı iletip diğer protokollerle tutarlılık sağlayacak değişiklikleri planlıyorum. Bir sonraki adımda dnsclientpool.Configuration yapısına alan eklenecek ve dns.go içinde options.OverrideFastdialer aktarılacak. Bunu planlayarak ilerleyeceğim.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, are you recommending that I include it even though it isn’t required?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Comment on lines 186 to 189
dnsClientOptions := &dnsclientpool.Configuration{
Retries: request.Retries,
Proxy: options.Options.AliveSocksProxy,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

@@ -132,6 +133,8 @@ type ExecutorOptions struct {
ExportReqURLPattern bool
// GlobalMatchers is the storage for global matchers with http passive templates
GlobalMatchers *globalmatchers.Storage
// OverrideFastdialer is a fastdialer dialer instance
OverrideFastdialer *fastdialer.Dialer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this for lib usage only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

- use request.dialer instead of global variable
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a7c54e8 and 7214fa1.

📒 Files selected for processing (3)
  • pkg/protocols/http/http.go (4 hunks)
  • pkg/protocols/http/request.go (2 hunks)
  • pkg/protocols/network/request.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • pkg/protocols/http/request.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
pkg/protocols/http/http.go (3)
pkg/protocols/common/protocolstate/state.go (1)
  • Dialer (24-24)
pkg/protocols/http/httpclientpool/clientpool.go (2)
  • Get (177-182)
  • Configuration (94-109)
pkg/types/types.go (1)
  • Options (30-452)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Tests (windows-latest)
  • GitHub Check: Tests (macOS-latest)
  • GitHub Check: Tests (ubuntu-latest)

@@ -132,6 +133,8 @@ type ExecutorOptions struct {
ExportReqURLPattern bool
// GlobalMatchers is the storage for global matchers with http passive templates
GlobalMatchers *globalmatchers.Storage
// OverrideFastdialer is a fastdialer dialer instance
OverrideFastdialer *fastdialer.Dialer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think CustomFastdialer would be a better naming choice/convention in this context. the OverrideXXX naming pattern tends to sound like expecting a boolean value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants