Skip to content
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

Export DNS resolver for library usage #754

Closed
crisidev opened this issue Nov 2, 2023 · 6 comments · Fixed by #756
Closed

Export DNS resolver for library usage #754

crisidev opened this issue Nov 2, 2023 · 6 comments · Fixed by #756
Labels
dns enhancement New feature or request
Milestone

Comments

@crisidev
Copy link

crisidev commented Nov 2, 2023

Hello,
I am wondering if you would be open to exporting the DNS resolver to be used as a library and not only by the main TUI / Stream / etc.

I would be already pretty happy to just have a pub mod dns inside lib.rs. What do you think?

@fujiapple852 fujiapple852 self-assigned this Nov 3, 2023
@fujiapple852
Copy link
Owner

fujiapple852 commented Nov 3, 2023

@crisidev I think we should be able to do this, i'm just not sure what the right approach is.

Trippy is intended primarily as a tool but is structured as a tool built on top of a library, such that other tools could be build using the Trippy library.

In fact there is an (out of date) pr (#640) to split Trippy into different crates which may or may not happen, i'm still unsure if it is a good idea or not. See this comment for my thoughts on the topic.

So right now the library portion of Trippy does not deal with DNS at all and so the dns module is not part of the library, but is part of the tool. Therefore it doesn't make sense to re-export it in lib.rs, even though it would be trivial to do so.

I should point out that the DNS resolver in Trippy is simply a wrapper on top of the dns-lookup and trust-dns-resolver (recently rebranded as hickory-resolver) crates which do all the heavy lifting. The only things that Trippy adds is lazy background lookups and ASN lookups, which I guess maybe useful to other projects? If not then I'd recommend using those crates directly.

Aside: I would actually like to divest hickory-resolver as it is an async only library which forces Trippy to pull in the whole tokio eco-system which bloats the final executable size by a large multiple. However I am yet to find a suitable replacement library that is cross platform, non-async and of high quality so for now we stick with what we have.

@fujiapple852
Copy link
Owner

fujiapple852 commented Nov 3, 2023

I think that given:

  • Trippy is pre-1.0 and perma-unstable at this point
  • No decision has been made about how to structure it going forward (tool vs tool + library)
  • This is a trivial change

Then I'm ok with it for now.

PR up: #756 and this will go into 0.9.0.

@c-git
Copy link
Collaborator

c-git commented Nov 3, 2023

You said trivial and I just looked at the PR and I'm like that was a lot. It's easy for you, but it's actually not easy. Required a good understanding of what needed to move where.

@fujiapple852
Copy link
Owner

fujiapple852 commented Nov 3, 2023

Fair point @c-git !

There was one complication that makes this look more complex than it is which may be worth explaining as it crops up from time to time.

The DnsResolveMethod enum was shared between the config and dns modules. By moving the dns module into the library (and out of the tool) I had to move the DnsResolveMethod enum into the dns module as well.

However in the dns module we do not want to have to specify attributes such as ValueEnum, Deserialize and #[serde(rename_all = "kebab-case")] which are needed in the config module to support it being read from a config file.

The solution is to duplicate the type into DnsResolveMethodConfig and DnsResolveMethod and provide a conversion from the former to the latter.

This pattern is repeated for types in the tracing/config.rs module which have the same issue.

I also improved the rustdoc comments for the dns module given it's now part of the public interface.

@c-git
Copy link
Collaborator

c-git commented Nov 3, 2023

Thanks for explaining that I wasn't quite following what was happening. Thought I'd have to play with it a bit to understand. Thanks for saving me the time.

@fujiapple852
Copy link
Owner

@crisidev I did some further refactoring of the dns module to make it more suitable to be part of the public interface. I'll merge it now as it is, please me know if it works for you.

@fujiapple852 fujiapple852 removed their assignment Nov 5, 2023
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Dec 1, 2023
[0.9.0] - 2023-11-30

Added

- Added support for tracing flows
  ([#776](fujiapple852/trippy#776))
- Added support for `icmp` extensions
  ([#33](fujiapple852/trippy#33))
- Added support for `MPLS` label stack class `icmp` extension
  objects ([#753](fujiapple852/trippy#753))
- Added support for [paris]
  (https://github.com/libparistraceroute/libparistraceroute) ECMP routing
  for `IPv6/udp` ([#749](fujiapple852/trippy#749))
- Added `--unprivileged` (`-u`) flag to allow tracing without elevated
  privileges (macOS
  only) ([#101](fujiapple852/trippy#101))
- Added `--tui-privacy-max-ttl` flag to hide host and IP details for low ttl
  hops ([#766](fujiapple852/trippy#766))
- Added `toggle-privacy` (default: `p`) key binding to show or hide private
  hops ([#823](fujiapple852/trippy#823))
- Added `toggle-flows` (default: `f`) key binding to show or hide tracing
  flows ([#777](fujiapple852/trippy#777))
- Added `--dns-resolve-all` (`-y`) flag to allow tracing to all IPs resolved
  from DNS lookup
  entry ([#743](fujiapple852/trippy#743))
- Added `dot` report mode (`-m dot`) to output hop graph in Graphviz `DOT`
  format ([#582](fujiapple852/trippy#582))
- Added `flows` report mode (`-m flows`) to output a list of all unique tracing
  flows ([#770](fujiapple852/trippy#770))
- Added `--icmp-extensions` (`-e`) flag for parsing `IPv4`/`IPv6` `icmp`
  extensions ([#751](fujiapple852/trippy#751))
- Added `--tui-icmp-extension-mode` flag to control how `icmp` extensions are
  rendered ([#752](fujiapple852/trippy#752))
- Added `--print-config-template` flag to output a template config
  file ([#792](fujiapple852/trippy#792))
- Added `--icmp` flag as a shortcut for `--protocol icmp`
  ([#649](fujiapple852/trippy#649))
- Added `toggle-help-alt` (default: `?`) key binding to show or hide
  help ([#694](fujiapple852/trippy#694))
- Added panic handing to Tui
  ([#784](fujiapple852/trippy#784))
- Added official Windows `scoop` package
  ([#462](fujiapple852/trippy#462))
- Added official Windows `winget` package
  ([#460](fujiapple852/trippy#460))
- Release `musl` Debian `deb` binary asset
  ([#568](fujiapple852/trippy#568))
- Release `armv7` Linux binary assets
  ([#712](fujiapple852/trippy#712))
- Release `aarch64-apple-darwin` (aka macOS Apple Silicon) binary
  assets ([#801](fujiapple852/trippy#801))
- Added additional Rust Tier 1 and Tier 2 binary assets
  ([#811](fujiapple852/trippy#811))

Changed

- [BREAKING CHANGE] `icmp` extension object data added to `json` and `stream`
  reports ([#806](fujiapple852/trippy#806))
- [BREAKING CHANGE] IPs field added to `csv` and all tabular
  reports ([#597](fujiapple852/trippy#597))
- [BREAKING CHANGE] Command line flags `--dns-lookup-as-info` and
  `--tui-preserve-screen` no longer require a boolean
  argument ([#708](fujiapple852/trippy#708))
- [BREAKING CHANGE] Default key binding for `ToggleFreeze` changed from `f`
  to `ctrl+f` ([#785](fujiapple852/trippy#785))
- Always render AS lines in hop details mode
  ([#825](fujiapple852/trippy#825))
- Expose DNS resolver module as part of `trippy` library
  ([#754](fujiapple852/trippy#754))
- Replaced unmaintained `tui-rs` crate with `ratatui` crate
  ([#569](fujiapple852/trippy#569))

Fixed

- Reverse DNS lookup not working in reports
  ([#509](fujiapple852/trippy#509))
- Crash on NetBSD during window resizing
  ([#276](fujiapple852/trippy#276))
- Protocol mismatch causes tracer panic
  ([#745](fujiapple852/trippy#745))
- Incorrect row height in Tui hop detail navigation view for hops with no
  responses ([#765](fujiapple852/trippy#765))
- Unnecessary socket creation in certain tracing modes
  ([#647](fujiapple852/trippy#647))
- Incorrect byte order in `IPv4` packet length calculation
  ([#686](fujiapple852/trippy#686))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dns enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants