Permalink
Browse files

Create minidns-client, make minidns-core a pure functional core

Fixes #48.
  • Loading branch information...
Flowdalic committed Mar 26, 2018
1 parent badfdbe commit 6b665a11ae7994a6b217aeae9a77b4ea2b88a727
Showing with 87 additions and 26 deletions.
  1. +1 −1 .gitignore
  2. +3 −21 minidns-client/build.gradle
  3. +23 −0 minidns-core/build.gradle
  4. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/DNSMessage.java
  5. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/DNSName.java
  6. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/DNSSECConstants.java
  7. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/EDNS.java
  8. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/InvalidDNSNameException.java
  9. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/Question.java
  10. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/RRSet.java
  11. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/Record.java
  12. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/dnslabel/ALabel.java
  13. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/dnslabel/DNSLabel.java
  14. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/dnslabel/FakeALabel.java
  15. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/dnslabel/LdhLabel.java
  16. 0 ...lient → minidns-core}/src/main/java/de/measite/minidns/dnslabel/LeadingOrTrailingHyphenLabel.java
  17. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/dnslabel/NonLdhLabel.java
  18. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/dnslabel/NonReservedLdhLabel.java
  19. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/dnslabel/OtherNonLdhLabel.java
  20. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/dnslabel/ReservedLdhLabel.java
  21. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/dnslabel/UnderscoreLabel.java
  22. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/dnslabel/XnLabel.java
  23. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/edns/EDNSOption.java
  24. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/edns/NSID.java
  25. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/edns/UnknownEDNSOption.java
  26. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/idna/DefaultIdnaTransformator.java
  27. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/idna/IdnaTransformator.java
  28. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/idna/MiniDnsIdna.java
  29. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/A.java
  30. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/AAAA.java
  31. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/CNAME.java
  32. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/DLV.java
  33. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/DNAME.java
  34. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/DNSKEY.java
  35. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/DS.java
  36. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/Data.java
  37. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/DelegatingDnssecRR.java
  38. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/InternetAddressRR.java
  39. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/MX.java
  40. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/NS.java
  41. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/NSEC.java
  42. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/NSEC3.java
  43. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/NSEC3PARAM.java
  44. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/OPENPGPKEY.java
  45. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/OPT.java
  46. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/PTR.java
  47. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/RRSIG.java
  48. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/RRWithTarget.java
  49. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/SOA.java
  50. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/SRV.java
  51. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/TLSA.java
  52. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/TXT.java
  53. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/record/UNKNOWN.java
  54. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/util/Base32.java
  55. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/util/Base64.java
  56. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/util/CallbackRecipient.java
  57. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/util/CollectionsUtil.java
  58. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/util/ExceptionCallback.java
  59. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/util/Hex.java
  60. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/util/InetAddressUtil.java
  61. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/util/MultipleIoException.java
  62. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/util/NameUtil.java
  63. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/util/PlatformDetection.java
  64. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/util/SrvUtil.java
  65. 0 {minidns-client → minidns-core}/src/main/java/de/measite/minidns/util/SuccessCallback.java
  66. 0 {minidns-client → minidns-core}/src/test/java/de/measite/minidns/Assert.java
  67. +59 −4 {minidns-client → minidns-core}/src/test/java/de/measite/minidns/DNSMessageTest.java
  68. 0 {minidns-client → minidns-core}/src/test/java/de/measite/minidns/DNSNameTest.java
  69. 0 {minidns-client → minidns-core}/src/test/java/de/measite/minidns/dnslabel/DNSLabelTest.java
  70. 0 {minidns-client → minidns-core}/src/test/java/de/measite/minidns/record/RecordsTest.java
  71. 0 {minidns-client → minidns-core}/src/test/java/de/measite/minidns/util/Base32Test.java
  72. 0 {minidns-client → minidns-core}/src/test/java/de/measite/minidns/util/Base64Test.java
  73. 0 {minidns-client → minidns-core}/src/test/java/de/measite/minidns/util/InetAddressUtilTest.java
  74. 0 {minidns-client → minidns-core}/src/test/java/de/measite/minidns/util/NameUtilTest.java
  75. 0 {minidns-client → minidns-core}/src/test/java/de/measite/minidns/util/SrvUtilTest.java
  76. BIN {minidns-client → minidns-core}/src/test/resources/de/measite/minidns/codinghorror-txt
  77. BIN {minidns-client → minidns-core}/src/test/resources/de/measite/minidns/com-ds-rrsig
  78. BIN {minidns-client → minidns-core}/src/test/resources/de/measite/minidns/com-ns
  79. BIN {minidns-client → minidns-core}/src/test/resources/de/measite/minidns/com-nsec3
  80. BIN {minidns-client → minidns-core}/src/test/resources/de/measite/minidns/example-nsec
  81. BIN {minidns-client → minidns-core}/src/test/resources/de/measite/minidns/gmail-mx
  82. BIN {minidns-client → minidns-core}/src/test/resources/de/measite/minidns/google-aaaa
  83. BIN {minidns-client → minidns-core}/src/test/resources/de/measite/minidns/gpn-srv
  84. BIN {minidns-client → minidns-core}/src/test/resources/de/measite/minidns/oracle-soa
  85. BIN {minidns-client → minidns-core}/src/test/resources/de/measite/minidns/root-dnskey
  86. BIN {minidns-client → minidns-core}/src/test/resources/de/measite/minidns/sun-a
  87. +1 −0 settings.gradle
@@ -112,4 +112,4 @@ Temporary Items
.apdisk

# Auto generated version file
/minidns-client/src/main/resources/de.measite.minidns/version
/minidns-core/src/main/resources/de.measite.minidns/version
@@ -1,23 +1,5 @@
dependencies {
testCompile "junit:junit:$junitVersion"
compile project(':minidns-core')
testCompile project(path: ":minidns-core", configuration: "testRuntime")
testCompile project(path: ":minidns-core", configuration: "archives")
}

class CreateFileTask extends DefaultTask {
@Input
String fileContent

@OutputFile
File outputFile

@TaskAction
def createFile() {
outputFile.text = fileContent
}
}

task createVersionResource(type: CreateFileTask) {
fileContent = version + ' (' + gitCommit + ' ' + builtDate + ')'
outputFile = new File(projectDir, 'src/main/resources/de.measite.minidns/version')
}

compileJava.dependsOn(createVersionResource)
@@ -0,0 +1,23 @@
dependencies {
testCompile "junit:junit:$junitVersion"
}

class CreateFileTask extends DefaultTask {
@Input
String fileContent

@OutputFile
File outputFile

@TaskAction
def createFile() {
outputFile.text = fileContent
}
}

task createVersionResource(type: CreateFileTask) {
fileContent = version + ' (' + gitCommit + ' ' + builtDate + ')'
outputFile = new File(projectDir, 'src/main/resources/de.measite.minidns/version')
}

compileJava.dependsOn(createVersionResource)
@@ -12,6 +12,7 @@

import de.measite.minidns.DNSSECConstants.DigestAlgorithm;
import de.measite.minidns.DNSSECConstants.SignatureAlgorithm;
import de.measite.minidns.Record.CLASS;
import de.measite.minidns.Record.TYPE;
import de.measite.minidns.record.A;
import de.measite.minidns.record.AAAA;
@@ -35,6 +36,8 @@

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -45,10 +48,6 @@
import java.util.TreeMap;

import static de.measite.minidns.Assert.assertCsEquals;
import static de.measite.minidns.DNSWorld.a;
import static de.measite.minidns.DNSWorld.aaaa;
import static de.measite.minidns.DNSWorld.ns;
import static de.measite.minidns.DNSWorld.record;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -536,4 +535,60 @@ public void testFilledMessageTerminalOutput() throws Exception {
message.getEdnsBuilder().setUdpPayloadSize(512);
assertNotNull(message.build().asTerminalOutput());
}

public static Record<Data> record(String name, long ttl, Data data) {
return new Record<>(name, data.getType(), CLASS.IN, ttl, data, false);
}

public static Record<Data> record(DNSName name, long ttl, Data data) {
return new Record<>(name, data.getType(), CLASS.IN, ttl, data, false);
}

public static Record<Data> record(String name, Data data) {
return record(name, 3600, data);
}

public static A a(String ipString) {
return a(parseIpV4(ipString));
}

public static A a(byte[] ip) {
return new A(ip);
}

public static byte[] parseIpV4(String ipString) {
String[] split = ipString.split("\\.");
if (split.length != 4) {
throw new IllegalArgumentException(ipString + " is not an valid IPv4 address");
}
byte[] ip = new byte[4];
for (int i = 0; i < 4; i++) {
ip[i] = (byte) Integer.parseInt(split[i]);
}
return ip;
}

public static NS ns(String name) {
return ns(DNSName.from(name));
}

public static NS ns(DNSName name) {
return new NS(name);
}

public static AAAA aaaa(byte[] ip) {
return new AAAA(ip);
}

public static AAAA aaaa(String ipString) {
return aaaa(parseIpV6(ipString));
}

static byte[] parseIpV6(String ipString) {
try {
return InetAddress.getByName(ipString).getAddress();
} catch (UnknownHostException e) {
throw new IllegalArgumentException(ipString + " is not an valid IPv6 address", e);
}
}
}
@@ -3,6 +3,7 @@
// name of the root directory
rootProject.name = 'MiniDNS'

include 'minidns-core'
include 'minidns-client'
include 'minidns-async'
include 'minidns-iterative-resolver'

0 comments on commit 6b665a1

Please sign in to comment.