Skip to content

Commit 48bb739

Browse files
authored
Update README (#2)
Add some contents to README and minor code cleanup
1 parent ccbedad commit 48bb739

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,59 @@
1-
# Asynchronous Resolver
1+
# Swift Asynchronous DNS Resolver
22

33
A Swift library for asynchronous DNS requests, wrapping [c-ares](https://github.com/c-ares/c-ares) with Swift-friendly APIs and data structures.
44

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.

Tests/AsyncDNSResolverTests/AsyncDNSResolverTests.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ final class AsyncDNSResolverTests: XCTestCase {
2323
override func setUp() {
2424
super.setUp()
2525

26-
// var options = AsyncDNSResolver.Options()
27-
// options.servers = ["8.8.8.8"]
28-
// self.resolver = try! AsyncDNSResolver(options: options)
2926
self.resolver = try! AsyncDNSResolver()
3027
}
3128

0 commit comments

Comments
 (0)