⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@sgerbino
Copy link
Collaborator

@sgerbino sgerbino commented Jan 26, 2026

Implement reverse DNS lookup capability for the resolver class, enabling hostname lookups from IP addresses using getnameinfo() on POSIX and GetNameInfoW() on Windows.

New API:

  • resolve(endpoint) - reverse resolve with default flags
  • resolve(endpoint, reverse_flags) - reverse resolve with custom flags
  • reverse_flags enum (numeric_host, numeric_service, name_required, datagram_service)
  • reverse_resolver_result class with endpoint(), host_name(), service_name()

Implementation uses worker threads on both platforms since the underlying APIs (getnameinfo/GetNameInfoW) are synchronous. Thread lifetime is managed via shared_ptr to prevent use-after-free during shutdown.

Resolves #64.

Summary by CodeRabbit

  • New Features

    • Reverse DNS resolution: resolve endpoints to host and service names.
    • Configurable reverse-resolution flags for fine-grained lookup behavior.
    • Async/await-compatible reverse lookups on Windows and POSIX platforms.
  • Chores

    • Improved resolver lifetime, thread tracking, and graceful shutdown so in-flight lookups complete or cancel cleanly.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 26, 2026

📝 Walkthrough

Walkthrough

Adds endpoint-based reverse DNS resolution: new public reverse_flags, reverse_resolver_result, resolver overloads resolve(endpoint[, reverse_flags]), a reverse_resolve_awaitable, and a resolver_impl::reverse_resolve API; POSIX and IOCP services implement worker-thread getnameinfo/GetNameInfoW paths and thread/shutdown tracking.

Changes

Cohort / File(s) Summary
Public API
include/boost/corosio/resolver.hpp, include/boost/corosio/resolver_results.hpp
Adds reverse_flags enum + bitwise operators, reverse_resolver_result type (endpoint, host, service), reverse_resolve_awaitable, and resolver::resolve(endpoint[, reverse_flags]) overloads.
POSIX resolver implementation
src/corosio/src/detail/posix/resolver_service.cpp
Adds reverse_resolve_op, reverse_op_ member, posix_resolver_impl::reverse_resolve(...) using getnameinfo, flags_to_ni_flags() helper, worker-thread execution, and shutdown/wait-for-threads integration.
IOCP (Windows) resolver implementation
src/corosio/src/detail/iocp/resolver_service.cpp, src/corosio/src/detail/iocp/resolver_service.hpp
Adds reverse_resolve_op, win_resolver_impl::reverse_resolve(...) using GetNameInfoW on worker thread, wide→UTF‑8 conversion, thread lifecycle tracking (thread_started/thread_finished/is_shutting_down), and changes to resolver ownership tracking (shared_ptr / resolver_ptrs_).
Service lifecycle / shutdown
src/corosio/src/detail/*/resolver_service.{cpp,hpp}
Service now tracks active worker threads, always posts completion ops for draining, waits for worker threads during shutdown, and updates cancel/destroy flows to cover reverse operations.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Resolver as Resolver
    participant Impl as ResolverImpl
    participant Worker as WorkerThread
    participant Scheduler as Scheduler

    Client->>Resolver: co_await resolve(endpoint, flags)
    Resolver->>Impl: reverse_resolve(coro, executor, endpoint, flags, stop_token, ec*, result*)
    Impl->>Worker: spawn worker thread (getnameinfo / GetNameInfoW)
    Worker->>Worker: perform lookup, convert strings
    Worker->>Impl: populate op (host/service, error)
    Worker->>Scheduler: post completion op
    Scheduler->>Impl: invoke op() -> resume coroutine
    Impl->>Client: coroutine resumes with reverse_resolver_result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

🐰 I nibble PTRs in moonlit code,
Hopping threads down network road,
From IP back to name I peep,
Worker hums while coroutines sleep,
A carrot-host returned to keep.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the changeset: adding reverse DNS resolution support to the resolver class.
Linked Issues check ✅ Passed The pull request implements all primary coding objectives from issue #64: reverse DNS API, flags support, platform-specific implementations, worker threads, endpoint conversion, and new result types.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #64 objectives: resolver headers/implementation updates, platform-specific resolver services, new result types, and reverse resolution infrastructure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@cppalliance-bot
Copy link

cppalliance-bot commented Jan 26, 2026

An automated preview of the documentation is available at https://85.corosio.prtest3.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-01-26 22:33:15 UTC

Copy link

@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: 3

🤖 Fix all issues with AI agents
In `@src/corosio/src/detail/iocp/resolver_service.cpp`:
- Around line 19-23: The file using std::memcpy (resolver_service.cpp) is
missing the <cstring> include; add `#include` <cstring> near the other includes
(alongside <thread> and boost headers) so std::memcpy is provided directly
rather than relying on transitive includes used by functions like memcpy in the
reverse path.

In `@src/corosio/src/detail/iocp/resolver_service.hpp`:
- Around line 269-286: Update the file-level overview comment to reflect that
reverse DNS resolution now spawns worker threads and that shutdown is tracked;
explicitly mention the presence of thread bookkeeping methods (thread_started,
thread_finished, is_shutting_down) and state members (shutting_down_,
active_threads_) as part of the shutdown protocol, and note that resolver
instances are tracked via resolver_list_ and resolver_ptrs_. Keep the summary
concise, remove the outdated claim that this path avoids worker threads, and add
a short sentence describing the purpose of the condition variable cv_ and
win_mutex mutex_ in coordinating thread shutdown.

In `@src/corosio/src/detail/posix/resolver_service.cpp`:
- Around line 703-794: The file uses std::memcpy inside
posix_resolver_impl::reverse_resolve (in resolver_service.cpp) but does not
include <cstring>; add an explicit `#include` <cstring> at the top of the file so
std::memcpy is available without relying on transitive includes (this touches
resolver_service.cpp where reverse_resolve and std::memcpy are used).

@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.58%. Comparing base (a700836) to head (332b97d).
⚠️ Report is 6 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #85      +/-   ##
===========================================
+ Coverage    84.19%   84.58%   +0.38%     
===========================================
  Files           43       43              
  Lines         2822     2951     +129     
===========================================
+ Hits          2376     2496     +120     
- Misses         446      455       +9     

see 5 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a700836...332b97d. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sgerbino sgerbino force-pushed the feature/reverse-lookup branch from 1daa1c4 to 2d43af0 Compare January 26, 2026 21:31
Copy link

@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

🤖 Fix all issues with AI agents
In `@src/corosio/src/detail/iocp/resolver_service.cpp`:
- Around line 435-452: GetNameInfoW's return value should be stored directly
into reverse_op_.gai_error instead of calling ::WSAGetLastError(); in the block
after calling GetNameInfoW (use the GetNameInfoW call and reverse_op_ locals to
find the spot), set reverse_op_.gai_error = result when result != 0 and set
reverse_op_.gai_error = 0 when result == 0 (while still populating
reverse_op_.stored_host and reverse_op_.stored_service via from_wide as
currently done).

Implement reverse DNS lookup capability for the resolver class, enabling
hostname lookups from IP addresses using getnameinfo() on POSIX and
GetNameInfoW() on Windows.

New API:
- resolve(endpoint) - reverse resolve with default flags
- resolve(endpoint, reverse_flags) - reverse resolve with custom flags
- reverse_flags enum (numeric_host, numeric_service, name_required, datagram_service)
- reverse_resolver_result class with endpoint(), host_name(), service_name()

Implementation uses worker threads on both platforms since the underlying
APIs (getnameinfo/GetNameInfoW) are synchronous. Thread lifetime is managed
via shared_ptr to prevent use-after-free during shutdown.
@sgerbino sgerbino force-pushed the feature/reverse-lookup branch from 2d43af0 to 332b97d Compare January 26, 2026 22:29
@sgerbino sgerbino merged commit a6390ea into cppalliance:develop Jan 27, 2026
28 of 29 checks passed
@sgerbino sgerbino deleted the feature/reverse-lookup branch January 27, 2026 00:08
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.

Implement reverse DNS lookup

2 participants