Skip to content

swift-libp2p/swift-libp2p-dnsaddr

Repository files navigation

LibP2PDNSAddr

Swift Package Manager compatible Build & Test (macos)

DNSAddr Protocol Address / Name Resolution

Table of Contents

Overview

dnsaddr is a protocol that instructs the resolver to lookup multiaddr(s) in DNS TXT records for the domain name in it's value section.

This package adds the ability to resolves multiaddr's of the form

// Given multiaddr that uses the DNSADDR protocol
let ma = Multiaddr("/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa")

// Resolving it by calling app.resolve
let resolvedAddresses = app.resolve(multiaddr: ma).wait()

// Yeilds a list of ip addresses that we can dial
// /ip4/139.178.91.71/tcp/4001/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN
// /ip6/2604:1380:45e3:6e00::1/tcp/4001/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN
// ...
// /ip4/139.178.91.71/udp/4001/quic-v1/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN

For more details see

Install

Include the following dependency in your Package.swift file

let package = Package(
    ...
    dependencies: [
        ...
        .package(url: "https://github.com/swift-libp2p/swift-libp2p-dnsaddr.git", .upToNextMajor(from: "0.0.1"))
    ],
    ...
        .target(
            ...
            dependencies: [
                ...
                .product(name: "LibP2PDNSAddr", package: "swift-libp2p-dnsaddr"),
            ]),
    ...
)

Usage

import LibP2PDNSAddr

/// Add the resolver to the applications resolver list. 
app.resolvers.use(.dnsaddr)

/// Or explicitly set your preferred dns resolver
let cloudflareDNS = try SocketAddress(ipAddress: "1.1.1.1", port: 53)
app.resolvers.use(.dnsaddr(host: cloudflareDNS))

/// From here on, when the application encounters a dnsaddr address it will use this package to attempt to resolve it.

Example

N/A

API

N/A

Contributing

Contributions are welcomed! This code is very much a proof of concept. I can guarantee you there's a better / safer way to accomplish the same results. Any suggestions, improvements, or even just critiques, are welcome!

Let's make this code better together! 🤝

Credits

License

MIT © 2022 Breth Inc.

About

DNSAddr Name Resolution

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages