From 448ffe15dc6267ec45567f79025d9b330f9bd53c Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 17 Jul 2015 02:47:02 +0200 Subject: [PATCH] cleanup DNS --- .../network/dns/decoder/DomainDecoder.java | 8 +- .../dns/decoder/MailExchangerDecoder.java | 11 ++- .../network/dns/decoder/RecordDecoder.java | 3 +- .../network/dns/decoder/ServiceDecoder.java | 11 ++- .../dns/decoder/StartOfAuthorityDecoder.java | 15 ++-- .../network/dns/decoder/TextDecoder.java | 10 +-- .../dns/record/MailExchangerRecord.java | 20 ++--- .../network/dns/record/ServiceRecord.java | 55 ++++++------- .../dns/record/StartOfAuthorityRecord.java | 78 ++++++++++--------- 9 files changed, 111 insertions(+), 100 deletions(-) diff --git a/Dorkbox-Network/src/dorkbox/network/dns/decoder/DomainDecoder.java b/Dorkbox-Network/src/dorkbox/network/dns/decoder/DomainDecoder.java index 0d98f905..e2b3c2b3 100644 --- a/Dorkbox-Network/src/dorkbox/network/dns/decoder/DomainDecoder.java +++ b/Dorkbox-Network/src/dorkbox/network/dns/decoder/DomainDecoder.java @@ -5,12 +5,14 @@ import io.netty.handler.codec.dns.DnsRecord; import io.netty.resolver.dns.DnsNameResolverAccess; /** - * Decodes any record that simply returns a domain name, such as NS (name * server) and CNAME (canonical name) resource records. + * Decodes domain names, such as NS (name * server) and CNAME (canonical name) resource records */ -public class DomainDecoder implements RecordDecoder { +public +class DomainDecoder implements RecordDecoder { @Override - public String decode(final DnsRecord record, final ByteBuf response) { + public + String decode(final DnsRecord record, final ByteBuf response) { return DnsNameResolverAccess.decodeDomainName(response); } } diff --git a/Dorkbox-Network/src/dorkbox/network/dns/decoder/MailExchangerDecoder.java b/Dorkbox-Network/src/dorkbox/network/dns/decoder/MailExchangerDecoder.java index b4aabe48..930310b4 100644 --- a/Dorkbox-Network/src/dorkbox/network/dns/decoder/MailExchangerDecoder.java +++ b/Dorkbox-Network/src/dorkbox/network/dns/decoder/MailExchangerDecoder.java @@ -6,15 +6,14 @@ import io.netty.handler.codec.dns.DnsRecord; import io.netty.resolver.dns.DnsNameResolverAccess; /** - * Decodes MX (mail exchanger) resource records. + * Decodes MX (mail exchanger) resource records */ -public class MailExchangerDecoder implements RecordDecoder { +public +class MailExchangerDecoder implements RecordDecoder { - /** - * Returns a decoded MX (mail exchanger) resource record - */ @Override - public MailExchangerRecord decode(final DnsRecord record, final ByteBuf response) { + public + MailExchangerRecord decode(final DnsRecord record, final ByteBuf response) { int priority = response.readUnsignedShort(); String name = DnsNameResolverAccess.decodeDomainName(response); diff --git a/Dorkbox-Network/src/dorkbox/network/dns/decoder/RecordDecoder.java b/Dorkbox-Network/src/dorkbox/network/dns/decoder/RecordDecoder.java index 1d250525..2ff8f508 100644 --- a/Dorkbox-Network/src/dorkbox/network/dns/decoder/RecordDecoder.java +++ b/Dorkbox-Network/src/dorkbox/network/dns/decoder/RecordDecoder.java @@ -4,7 +4,8 @@ import io.netty.buffer.ByteBuf; import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.dns.DnsRecord; -public interface RecordDecoder { +public +interface RecordDecoder { T decode(final DnsRecord record, final ByteBuf response) throws DecoderException; } diff --git a/Dorkbox-Network/src/dorkbox/network/dns/decoder/ServiceDecoder.java b/Dorkbox-Network/src/dorkbox/network/dns/decoder/ServiceDecoder.java index ac3c987e..ffa4f17b 100644 --- a/Dorkbox-Network/src/dorkbox/network/dns/decoder/ServiceDecoder.java +++ b/Dorkbox-Network/src/dorkbox/network/dns/decoder/ServiceDecoder.java @@ -8,17 +8,16 @@ import io.netty.resolver.dns.DnsNameResolverAccess; /** * Decodes SRV (service) resource records. */ -public class ServiceDecoder implements RecordDecoder { +public +class ServiceDecoder implements RecordDecoder { - /** - * Returns a decoded SRV (service) resource record - */ @Override - public ServiceRecord decode(final DnsRecord record, final ByteBuf response) { + public + ServiceRecord decode(final DnsRecord record, final ByteBuf response) { int priority = response.readShort(); int weight = response.readShort(); int port = response.readUnsignedShort(); - String target = DnsNameResolverAccess.decodeDomainName(response); + String target = DnsNameResolverAccess.decodeDomainName(response); return new ServiceRecord(record.name(), priority, weight, port, target); } diff --git a/Dorkbox-Network/src/dorkbox/network/dns/decoder/StartOfAuthorityDecoder.java b/Dorkbox-Network/src/dorkbox/network/dns/decoder/StartOfAuthorityDecoder.java index 10d65f9e..628dfb20 100644 --- a/Dorkbox-Network/src/dorkbox/network/dns/decoder/StartOfAuthorityDecoder.java +++ b/Dorkbox-Network/src/dorkbox/network/dns/decoder/StartOfAuthorityDecoder.java @@ -8,15 +8,14 @@ import io.netty.resolver.dns.DnsNameResolverAccess; /** * Decodes SOA (start of authority) resource records. */ -public class StartOfAuthorityDecoder implements RecordDecoder { +public +class StartOfAuthorityDecoder implements RecordDecoder { - /** - * Returns a decoded SOA (start of authority) resource record - */ @Override - public StartOfAuthorityRecord decode(final DnsRecord record, final ByteBuf response) { - String mName = DnsNameResolverAccess.decodeDomainName(response); - String rName = DnsNameResolverAccess.decodeDomainName(response); + public + StartOfAuthorityRecord decode(final DnsRecord record, final ByteBuf response) { + String primaryName = DnsNameResolverAccess.decodeDomainName(response); + String personName = DnsNameResolverAccess.decodeDomainName(response); long serial = response.readUnsignedInt(); int refresh = response.readInt(); @@ -24,6 +23,6 @@ public class StartOfAuthorityDecoder implements RecordDecoder> { +public +class TextDecoder implements RecordDecoder> { - /** - * Returns a decoded TXT (text) resource record - */ @Override - public List decode(final DnsRecord record, final ByteBuf response) { + public + List decode(final DnsRecord record, final ByteBuf response) { List list = new ArrayList(); int index = response.readerIndex(); @@ -28,5 +27,4 @@ public class TextDecoder implements RecordDecoder> { return list; } - } diff --git a/Dorkbox-Network/src/dorkbox/network/dns/record/MailExchangerRecord.java b/Dorkbox-Network/src/dorkbox/network/dns/record/MailExchangerRecord.java index e726eacb..263c51be 100644 --- a/Dorkbox-Network/src/dorkbox/network/dns/record/MailExchangerRecord.java +++ b/Dorkbox-Network/src/dorkbox/network/dns/record/MailExchangerRecord.java @@ -20,7 +20,8 @@ package dorkbox.network.dns.record; * responsible for accepting e-mail and a preference value for prioritizing mail * servers if multiple servers exist. */ -public class MailExchangerRecord { +public +class MailExchangerRecord { private final int priority; private final String name; @@ -28,13 +29,12 @@ public class MailExchangerRecord { /** * Constructs an MX (mail exchanger) record. * - * @param priority - * the priority of the mail exchanger, lower is more preferred - * @param name - * the e-mail address in the format admin.example.com, which - * represents admin@example.com + * @param priority the priority of the mail exchanger, lower is more preferred + * @param name the e-mail address in the format admin.example.com, which + * represents admin@example.com */ - public MailExchangerRecord(int priority, String name) { + public + MailExchangerRecord(int priority, String name) { this.priority = priority; this.name = name; } @@ -42,7 +42,8 @@ public class MailExchangerRecord { /** * Returns the priority of the mail exchanger, lower is more preferred. */ - public int priority() { + public + int priority() { return this.priority; } @@ -50,7 +51,8 @@ public class MailExchangerRecord { * Returns the mail exchanger (an e-mail address) in the format * admin.example.com, which represents admin@example.com. */ - public String name() { + public + String name() { return this.name; } diff --git a/Dorkbox-Network/src/dorkbox/network/dns/record/ServiceRecord.java b/Dorkbox-Network/src/dorkbox/network/dns/record/ServiceRecord.java index c7bd45b9..cbe2d3e8 100644 --- a/Dorkbox-Network/src/dorkbox/network/dns/record/ServiceRecord.java +++ b/Dorkbox-Network/src/dorkbox/network/dns/record/ServiceRecord.java @@ -20,7 +20,8 @@ package dorkbox.network.dns.record; * and port, of servers for specified services. For example, a service "http" * may be running on the server "example.com" on port 80. */ -public class ServiceRecord { +public +class ServiceRecord { private final int priority; private final int weight; @@ -33,24 +34,20 @@ public class ServiceRecord { /** * Constructs an SRV (service) record. * - * @param fullPath - * the name first read in the SRV record which contains the - * service, the protocol, and the name of the server being - * queried. The format is {@code _service._protocol.hostname}, or - * for example {@code _http._tcp.example.com} - * @param priority - * relative priority of this service, range 0-65535 (lower is - * higher priority) - * @param weight - * determines how often multiple services will be used in the - * event they have the same priority (greater weight means - * service is used more often) - * @param port - * the port for the service - * @param target - * the name of the host for the service + * @param fullPath the name first read in the SRV record which contains the + * service, the protocol, and the name of the server being + * queried. The format is {@code _service._protocol.hostname}, or + * for example {@code _http._tcp.example.com} + * @param priority relative priority of this service, range 0-65535 (lower is + * higher priority) + * @param weight determines how often multiple services will be used in the + * event they have the same priority (greater weight means + * service is used more often) + * @param port the port for the service + * @param target the name of the host for the service */ - public ServiceRecord(String fullPath, int priority, int weight, int port, String target) { + public + ServiceRecord(String fullPath, int priority, int weight, int port, String target) { String[] parts = fullPath.split("\\.", 3); this.service = parts[0]; this.protocol = parts[1]; @@ -64,50 +61,56 @@ public class ServiceRecord { /** * Returns the priority for this service record. */ - public int priority() { + public + int priority() { return this.priority; } /** * Returns the weight of this service record. */ - public int weight() { + public + int weight() { return this.weight; } /** * Returns the port the service is running on. */ - public int port() { + public + int port() { return this.port; } /** * Returns the name for the server being queried. */ - public String name() { + public + String name() { return this.name; } /** * Returns the protocol for the service being queried (i.e. "_tcp"). */ - public String protocol() { + public + String protocol() { return this.protocol; } /** * Returns the service's name (i.e. "_http"). */ - public String service() { + public + String service() { return this.service; } /** * Returns the name of the host for the service. */ - public String target() { + public + String target() { return this.target; } - } diff --git a/Dorkbox-Network/src/dorkbox/network/dns/record/StartOfAuthorityRecord.java b/Dorkbox-Network/src/dorkbox/network/dns/record/StartOfAuthorityRecord.java index 70fe0986..3a54ea68 100644 --- a/Dorkbox-Network/src/dorkbox/network/dns/record/StartOfAuthorityRecord.java +++ b/Dorkbox-Network/src/dorkbox/network/dns/record/StartOfAuthorityRecord.java @@ -19,7 +19,8 @@ package dorkbox.network.dns.record; * Represents an SOA (start of authority) record, which defines global * parameters for a zone (domain). There can only be one SOA record per zone. */ -public class StartOfAuthorityRecord { +public +class StartOfAuthorityRecord { private final String primaryNameServer; private final String responsiblePerson; @@ -32,34 +33,34 @@ public class StartOfAuthorityRecord { /** * Constructs an SOA (start of authority) record. * - * @param primaryNameServer - * any name server that will respond authoritatively for the - * domain - * @param responsiblePerson - * e-mail address of person responsible for this zone - * @param serial - * a serial number that must be incremented when changes are - * made. Recommended format is YYYYMMDDnn. For example, if the - * primary name server is changed on June 19, 2013, then the - * serial would be 2013061901. If it is changed again on the same - * day it would be 2013061902 - * @param refreshTime - * number of seconds a secondary name server waits, after getting - * a copy of the zone, before it checks the zone again for - * changes - * @param retryTime - * number of seconds to wait after a failed refresh attempt - * before another attempt to refresh is made - * @param expireTime - * number of seconds secondary name server can hold information - * before it is considered not authoritative - * @param minimumTtl - * number of seconds that records in the zone are valid for (if a - * record has a higher TTL, it overrides this value which is just - * a minimum) + * @param primaryNameServer any name server that will respond authoritatively for the + * domain + * @param responsiblePerson e-mail address of person responsible for this zone + * @param serial a serial number that must be incremented when changes are + * made. Recommended format is YYYYMMDDnn. For example, if the + * primary name server is changed on June 19, 2013, then the + * serial would be 2013061901. If it is changed again on the same + * day it would be 2013061902 + * @param refreshTime number of seconds a secondary name server waits, after getting + * a copy of the zone, before it checks the zone again for + * changes + * @param retryTime number of seconds to wait after a failed refresh attempt + * before another attempt to refresh is made + * @param expireTime number of seconds secondary name server can hold information + * before it is considered not authoritative + * @param minimumTtl number of seconds that records in the zone are valid for (if a + * record has a higher TTL, it overrides this value which is just + * a minimum) */ - public StartOfAuthorityRecord(String primaryNameServer, String responsiblePerson, long serial, int refreshTime, - int retryTime, int expireTime, long minimumTtl) { + public + StartOfAuthorityRecord(String primaryNameServer, + String responsiblePerson, + long serial, + int refreshTime, + int retryTime, + int expireTime, + long minimumTtl) { + this.primaryNameServer = primaryNameServer; this.responsiblePerson = responsiblePerson; this.serial = serial; @@ -72,35 +73,40 @@ public class StartOfAuthorityRecord { /** * Returns the primary name server. */ - public String primaryNameServer() { + public + String primaryNameServer() { return this.primaryNameServer; } /** * Returns the responsible person's e-mail. */ - public String responsiblePerson() { + public + String responsiblePerson() { return this.responsiblePerson; } /** * Returns the zone's serial number, usually in format YYYYMMDDnn. */ - public long serial() { + public + long serial() { return this.serial; } /** * Returns time between refreshes for secondary name servers. */ - public int refreshTime() { + public + int refreshTime() { return this.refreshTime; } /** * Returns time between retries for failed refresh attempts. */ - public int retryTime() { + public + int retryTime() { return this.retryTime; } @@ -108,7 +114,8 @@ public class StartOfAuthorityRecord { * Returns time before information stored in secondary name servers becomes * non authoritative. */ - public int expireTime() { + public + int expireTime() { return this.expireTime; } @@ -116,7 +123,8 @@ public class StartOfAuthorityRecord { * Returns the minimum TTL for records in the zone (if the record has a * higher TTL, that value should be used as the TTL). */ - public long minimumTtl() { + public + long minimumTtl() { return this.minimumTtl; }