From 233d053142d720a6e07602e7bd599ba36886457e Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Fri, 28 Aug 2020 15:59:22 -0700 Subject: [PATCH] Update README Add some contents to README and minor code cleanup --- README.md | 57 ++++++++++++++++++- .../AsyncDNSResolverTests.swift | 3 - 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2d34647..4a67127 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/Tests/AsyncDNSResolverTests/AsyncDNSResolverTests.swift b/Tests/AsyncDNSResolverTests/AsyncDNSResolverTests.swift index 14bb647..ef98080 100644 --- a/Tests/AsyncDNSResolverTests/AsyncDNSResolverTests.swift +++ b/Tests/AsyncDNSResolverTests/AsyncDNSResolverTests.swift @@ -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() }