Skip to content

Add static resolver#37

Merged
lvkv merged 1 commit intomainfrom
lvkv/static-resolver
Apr 8, 2026
Merged

Add static resolver#37
lvkv merged 1 commit intomainfrom
lvkv/static-resolver

Conversation

@lvkv
Copy link
Copy Markdown
Member

@lvkv lvkv commented Apr 6, 2026

This adds a "static" resolver that bypasses DNS SRV resolution altogether and directly returns whatever you configure it with.

This is useful for, say, setting up a quick development instance of an SRV-based client-server system without needing to set up dummy SRV records first. Also nice to have when debugging (e.g., "is it DNS?").

The module for this is called manual to signal that you'll be "manually" supplying the targets. Unfortunately, static is a reserved keyword and I'd rather not put pub mod r#static in the public API.

I've also added some methods specific to this resolver to make working with it easier (e.g., get_static_srv_records, get_static_srv_records_unordered). The doc comments for both should (hopefully) explain why they're slightly nicer than their more generic, async counterparts meant for the resolvers that actually perform DNS resolution.

I'd like to sneak this in before the 1.0 release at #36.

@lvkv lvkv requested a review from Copilot April 6, 2026 19:19
@lvkv lvkv self-assigned this Apr 6, 2026
@lvkv lvkv changed the title feat(resolver): add static resolver Add static resolver Apr 6, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new “static/manual” SRV resolver implementation that returns pre-configured SRV records without performing DNS lookups, plus a small client convenience constructor and updated integration test coverage.

Changes:

  • Introduce resolver::manual::{StaticResolver, StaticSrvRecord} to bypass DNS SRV lookups.
  • Add SrvClient::new_with_static_resolver convenience constructor for StaticResolver.
  • Extend the single-record SRV lookup integration test to exercise the new resolver.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/resolver/mod.rs Exposes the new manual resolver module.
src/resolver/manual.rs Implements the static resolver + record type and unit tests.
src/client/mod.rs Adds new_with_static_resolver convenience constructor and imports StaticResolver.
tests/test_simple_lookup_srv_single.rs Adds coverage path using StaticResolver.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/resolver/manual.rs
Comment thread src/resolver/manual.rs
Comment on lines +76 to +81
async fn get_srv_records_unordered(
&self,
_srv: &str,
) -> Result<(Vec<Self::Record>, Instant), Self::Error> {
Ok((self.get_static_srv_records_unordered(), Instant::now()))
}
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

get_srv_records_unordered returns Instant::now() as valid_until. Because cache validity checks use Instant::now() <= valid_until (see src/client/cache.rs:22), this will almost always make caches immediately invalid and force a refresh on every operation. Consider returning a far-future valid_until (using a checked add with a large Duration) so static records can actually be cached.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This would be trivial to add if an Instant::MAX existed, or, perhaps saturating addition on Instant, but those don't exist (at least, not yet: rust-lang/rust#71224). In the meantime, I think the current behavior is somewhat suboptimal but still acceptable given the potential use cases.

@lvkv lvkv force-pushed the lvkv/static-resolver branch from 1975a5d to 9c8c60f Compare April 6, 2026 21:16
Copy link
Copy Markdown

@ping-deshaw2 ping-deshaw2 left a comment

Choose a reason for hiding this comment

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

LGTM, always a fan of more test coverage!

@lvkv lvkv merged commit 1d3fc3a into main Apr 8, 2026
5 checks passed
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