Skip to content

Commit

Permalink
Update README (#2)
Browse files Browse the repository at this point in the history
Add some contents to README and minor code cleanup
  • Loading branch information
yim-lee authored Aug 31, 2020
1 parent ccbedad commit 48bb739
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
57 changes: 56 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,59 @@
# Asynchronous Resolver
# Swift Asynchronous DNS Resolver

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

## Project status

This is the beginning of a community-driven open-source project actively seeking contributions, be it code, documentation, or ideas.

## Getting started

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.

### Adding the dependency

To add a dependency on the package, declare it in your `Package.swift`:

```swift
.package(url: "https://github.com/apple/swift-async-dns-resolver.git", from: "0.1.0"),
```

and to your application target, add `AsyncDNSResolver` to your dependencies:

```swift
.target(name: "MyApplication", dependencies: ["AsyncDNSResolver"]),
```

### Using a DNS resolver

```swift
// import the package
import AsyncDNSResolver

// initialize the DNS resolver
let resolver = AsyncDNSResolver()

// run a query
self.resolver.query(.A(name: "apple.com") { result in
switch result {
case .success(let aRecords):
// process the ARecords
case .failure(let error):
// process the error
}
})
```

## Detailed design

The main types in the library are `AsyncDNSResolver`, `AsyncDNSResolver.Query`, and `AsyncDNSResolver.Options`.

`AsyncDNSResolver` uses the C-library [c-ares](https://github.com/c-ares/c-ares) underneath and delegates all queries to it.

`AsyncDNSResolver.Query` defines the supported DNS query types, while `AsyncDNSResolver.Options` provides different options for configuring `AsyncDNSResolver`.

The current implementation relies on a `DispatchQueue` to process queries asynchronously. An implementation that makes use of an event loop might be better.

---

Do not hesitate to get in touch, over on https://forums.swift.org/c/server.
3 changes: 0 additions & 3 deletions Tests/AsyncDNSResolverTests/AsyncDNSResolverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ final class AsyncDNSResolverTests: XCTestCase {
override func setUp() {
super.setUp()

// var options = AsyncDNSResolver.Options()
// options.servers = ["8.8.8.8"]
// self.resolver = try! AsyncDNSResolver(options: options)
self.resolver = try! AsyncDNSResolver()
}

Expand Down

0 comments on commit 48bb739

Please sign in to comment.