|
1 | | -# Asynchronous Resolver |
| 1 | +# Swift Asynchronous DNS Resolver |
2 | 2 |
|
3 | 3 | A Swift library for asynchronous DNS requests, wrapping [c-ares](https://github.com/c-ares/c-ares) with Swift-friendly APIs and data structures. |
4 | 4 |
|
| 5 | +## Project status |
| 6 | + |
| 7 | +This is the beginning of a community-driven open-source project actively seeking contributions, be it code, documentation, or ideas. |
| 8 | + |
| 9 | +## Getting started |
| 10 | + |
| 11 | +If you have a server-side Swift application or a cross-platform (e.g. Linux, macOS) application that needs DNS resolution, Swift Asynchronous DNS Resolver is a great idea. Below you will find all you need to know to get started. |
| 12 | + |
| 13 | +### Adding the dependency |
| 14 | + |
| 15 | +To add a dependency on the package, declare it in your `Package.swift`: |
| 16 | + |
| 17 | +```swift |
| 18 | +.package(url: "https://github.com/apple/swift-async-dns-resolver.git", from: "0.1.0"), |
| 19 | +``` |
| 20 | + |
| 21 | +and to your application target, add `AsyncDNSResolver` to your dependencies: |
| 22 | + |
| 23 | +```swift |
| 24 | +.target(name: "MyApplication", dependencies: ["AsyncDNSResolver"]), |
| 25 | +``` |
| 26 | + |
| 27 | +### Using a DNS resolver |
| 28 | + |
| 29 | +```swift |
| 30 | +// import the package |
| 31 | +import AsyncDNSResolver |
| 32 | + |
| 33 | +// initialize the DNS resolver |
| 34 | +let resolver = AsyncDNSResolver() |
| 35 | + |
| 36 | +// run a query |
| 37 | +self.resolver.query(.A(name: "apple.com") { result in |
| 38 | + switch result { |
| 39 | + case .success(let aRecords): |
| 40 | + // process the ARecords |
| 41 | + case .failure(let error): |
| 42 | + // process the error |
| 43 | + } |
| 44 | +}) |
| 45 | +``` |
| 46 | + |
| 47 | +## Detailed design |
| 48 | + |
| 49 | +The main types in the library are `AsyncDNSResolver`, `AsyncDNSResolver.Query`, and `AsyncDNSResolver.Options`. |
| 50 | + |
| 51 | +`AsyncDNSResolver` uses the C-library [c-ares](https://github.com/c-ares/c-ares) underneath and delegates all queries to it. |
| 52 | + |
| 53 | +`AsyncDNSResolver.Query` defines the supported DNS query types, while `AsyncDNSResolver.Options` provides different options for configuring `AsyncDNSResolver`. |
| 54 | + |
| 55 | +The current implementation relies on a `DispatchQueue` to process queries asynchronously. An implementation that makes use of an event loop might be better. |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +Do not hesitate to get in touch, over on https://forums.swift.org/c/server. |
0 commit comments