Skip to content

Conversation

@dontcrash
Copy link

Implements the option for a random resolver to go alongside this PR AdguardTeam/AdGuardHome#7950

Hopefully resolves AdguardTeam/AdGuardHome#4756

Copy link

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

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

Other comments (1)
  • proxy/upstreammode.go (27-27) The comment for `UpstreamModeRandom` is missing a verb. Consider changing to "makes server to use a random upstream" or "makes server to select a random upstream".

💡 To request another review, post a new comment with "/windsurf-review".

proxy/config.go Outdated
UpstreamModeLoadBalance,
UpstreamModeParallel:
UpstreamModeParallel,
UpstreamModeRandom:
Copy link

Choose a reason for hiding this comment

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

The PR adds UpstreamModeRandom to the switch statement, but this constant isn't defined anywhere in the visible code. You need to define this constant alongside the other UpstreamMode constants (like UpstreamModeFastestAddr, UpstreamModeLoadBalance, etc.).

Copy link
Author

@dontcrash dontcrash Jul 25, 2025

Choose a reason for hiding this comment

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

This one I believe is fine as it is inherited from AdGuardHome?
Although I realised the switch case is wrong, fixed it up

UpstreamModeFastestAddr,
UpstreamModeLoadBalance,
UpstreamModeRandom,
UpstreamModeParallel:
// Go on.

case
UpstreamModeLoadBalance,
UpstreamModeParallel,
UpstreamModeRandomm,
Copy link

Choose a reason for hiding this comment

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

There's a typo in the variable name: UpstreamModeRandomm should be UpstreamModeRandom.

Copy link
Author

Choose a reason for hiding this comment

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

Facepalm.

dontcrash and others added 3 commits July 25, 2025 20:39
Co-authored-by: windsurf-bot[bot] <189301087+windsurf-bot[bot]@users.noreply.github.com>
@ainar-g ainar-g self-requested a review July 29, 2025 15:35
@ainar-g ainar-g self-assigned this Jul 29, 2025
@ainar-g
Copy link
Contributor

ainar-g commented Jul 29, 2025

Thanks for the contribution! We'll review it shortly.

},
upstreamModeIdx: {
description: "Defines the upstreams logic mode, possible values: load_balance, parallel, " +
description: "Defines the upstreams logic mode, possible values: load_balance, parallel, random, " +
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update README.md as well.

// Simply set ups to a random entry in ups
// Falls back to default behaviour as if ups <= 1 it will run UpstreamModeLoadBalance as intended
if len(ups) > 1 {
ups = []upstream.Upstream{ups[p.randSrc.Intn(len(ups))]}
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't build:

proxy/exchange.go:28:44: p.randSrc.Intn undefined (type "math/rand/v2".Source has no field or method Intn)

See go doc math/rand/v2.

// response time or TCP connection time.
UpstreamModeFastestAddr UpstreamMode = "fastest_addr"

// UpstreamModeRandom makes server to a random upstream
Copy link
Member

Choose a reason for hiding this comment

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

Please, consider using gofumpt to format the code in this repository:

  1. make go-tools
  2. ./bin/gofumpt --extra -w .

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.

Add a "Random" option to the DNS settings

3 participants