taxonomy
Strongly typed DNS for scala based on the cats ecosystem with scodec and fs2
Versions
Version | Release date | cats version | Scala versions |
---|---|---|---|
1.0.0 |
2021-05-09 | 3.1.0 |
2.13.5 , 2.12.13 |
0.3.0 |
2021-01-09 | 2.2.0 |
2.13.4 , 2.12.12 |
0.2.0 |
2020-12-20 | 2.2.0 |
2.13.4 , 2.12.12 |
0.1.0 |
2020-12-17 | 2.2.0 |
2.13.4 , 2.12.12 |
Getting taxonomy
// DNS with fs2
libraryDependencies += "fr.davit" %% "taxonomy-fs2" % "<version>"
If you want to only part of the project with another IO implementation for instance, you can import the following sub modules
// for the scala model only
libraryDependencies += "fr.davit" %% "taxonomy-model" % "<version>"
// for the binary protocol with scodec
libraryDependencies += "fr.davit" %% "taxonomy-scodec" % "<version>"
Dns
Here is a quick example of a DNS lookup to the 9.9.9.9
DNS server for the davit.fr
domain name
import java.net.{Inet4Address, InetAddress, InetSocketAddress}
import cats.effect._
import cats.effect.unsafe.implicits._
import fr.davit.taxonomy.model.record._
import fr.davit.taxonomy.model._
import fr.davit.taxonomy.scodec.DnsCodec
import fs2.io.net.Network
import munit.CatsEffectSuite
import scodec.Codec
import scala.concurrent.duration._
implicit val codec: Codec[DnsMessage] = DnsCodec.dnsMessage
val quad9DnsServer = new InetSocketAddress("9.9.9.9", 53)
val question = DnsQuestion("davit.fr", DnsRecordType.A, unicastResponse = false, DnsRecordClass.Internet)
val query = DnsMessage.query(id = 1, questions = Seq(question))
val socketResource = Network[IO].openDatagramSocket()
val response = socketResource.use(s => Dns.resolve(s, DnsPacket(quad9DnsServer, query))).unsafeRunSync()