8000 GitHub - TaduCloud/dns4s: Scala DNS implementation with Akka and Netty extension
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

TaduCloud/dns4s

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dns4s

Build Status Coverage Status

dns4s is an implementation of the DNS protocol in Scala. It consists of the following parts:

  • Core
  • Akka IO Extension
  • Netty Codec

Core

The core part contains the functionality used for en-/decoding of DNS messages as well as an inner-DSL to con-/destruct DNS messages.

For a detailed explanation of the DSL have a look at its documentation.

Akka IO Extension

The akka part contains an akka-io extension.

Usage

If you're using sbt just add the following to your build definition:

resolvers += "bintray" at "http://jcenter.bintray.com"

libraryDependencies ++= Seq(
  "com.typesafe.akka" %% "akka-actor" % "2.4.1",
  "com.github.mkroli" %% "dns4s-akka" % "0.9")

Imports

Use the following imports to get started:

import akka.actor._
import akka.io.IO
import com.github.mkroli.dns4s.dsl._
import com.github.mkroli.dns4s.akka._
import scala.concurrent.duration._

Server

The following is an excerpt from examples/simple/../DnsServer.scala:

class DnsHandlerActor extends Actor {
  override def receive = {
    case Query(q) ~ Questions(QName(host) ~ TypeA() :: Nil) =>
      sender ! Response(q) ~ Answers(RRName(host) ~ ARecord("1.2.3.4"))
  }
}

object DnsServer extends App {
  implicit val system = ActorSystem("DnsServer")
  implicit val timeout = Timeout(5 seconds)
  IO(Dns) ? Dns.Bind(system.actorOf(Props[DnsHandlerActor]), 5354)
}

Client

The following is an excerpt from examples/simple-client/../DnsClient.scala:

implicit val system = ActorSystem("DnsServer")
implicit val timeout = Timeout(5 seconds)
import system.dispatcher

IO(Dns) ? Dns.DnsPacket(Query ~ Questions(QName("google.de")), new InetSocketAddress("8.8.8.8", 53)) onSuccess {
  case Response(Answers(answers)) =>
    answers.collect {
      case ARecord(arecord) => println(arecord.address.getHostAddress)
    }
}

Nett 599F y Codec

The netty part contains the MessageToMessageCodec DnsCodec. See the examples simple-netty and simple-netty-client for more information.

About

Scala DNS implementation with Akka and Netty extension

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 100.0%
0