cleanup DNS

This commit is contained in:
nathan 2015-07-17 02:47:02 +02:00
parent e961f395a5
commit 448ffe15dc
9 changed files with 111 additions and 100 deletions

View File

@ -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<String> {
public
class DomainDecoder implements RecordDecoder<String> {
@Override
public String decode(final DnsRecord record, final ByteBuf response) {
public
String decode(final DnsRecord record, final ByteBuf response) {
return DnsNameResolverAccess.decodeDomainName(response);
}
}

View File

@ -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<MailExchangerRecord> {
public
class MailExchangerDecoder implements RecordDecoder<MailExchangerRecord> {
/**
* 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);

View File

@ -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<T> {
public
interface RecordDecoder<T> {
T decode(final DnsRecord record, final ByteBuf response) throws DecoderException;
}

View File

@ -8,17 +8,16 @@ import io.netty.resolver.dns.DnsNameResolverAccess;
/**
* Decodes SRV (service) resource records.
*/
public class ServiceDecoder implements RecordDecoder<ServiceRecord> {
public
class ServiceDecoder implements RecordDecoder<ServiceRecord> {
/**
* 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);
}

View File

@ -8,15 +8,14 @@ import io.netty.resolver.dns.DnsNameResolverAccess;
/**
* Decodes SOA (start of authority) resource records.
*/
public class StartOfAuthorityDecoder implements RecordDecoder<StartOfAuthorityRecord> {
public
class StartOfAuthorityDecoder implements RecordDecoder<StartOfAuthorityRecord> {
/**
* 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<StartOfAuthorityRe
int expire = response.readInt();
long minimum = response.readUnsignedInt();
return new StartOfAuthorityRecord(mName, rName, serial, refresh, retry, expire, minimum);
return new StartOfAuthorityRecord(primaryName, personName, serial, refresh, retry, expire, minimum);
}
}

View File

@ -10,13 +10,12 @@ import java.util.List;
/**
* Decodes TXT (text) resource records.
*/
public class TextDecoder implements RecordDecoder<List<String>> {
public
class TextDecoder implements RecordDecoder<List<String>> {
/**
* Returns a decoded TXT (text) resource record
*/
@Override
public List<String> decode(final DnsRecord record, final ByteBuf response) {
public
List<String> decode(final DnsRecord record, final ByteBuf response) {
List<String> list = new ArrayList<String>();
int index = response.readerIndex();
@ -28,5 +27,4 @@ public class TextDecoder implements RecordDecoder<List<String>> {
return list;
}
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}