From 3742d9db8b6edb10627b0f89336cca5249f1d15a Mon Sep 17 00:00:00 2001 From: Manuel Roman Date: Tue, 13 Sep 2011 15:57:27 -0700 Subject: Uploading the original JmDNS code This code is used by the Broker service to advertise and discover an Active Home using the standard mDNS protocol Change-Id: I5d7068765b4ca771e3f3faf5d12104e2247945f3 --- src/javax/jmdns/impl/constants/DNSConstants.java | 61 ++++ src/javax/jmdns/impl/constants/DNSLabel.java | 87 ++++++ .../jmdns/impl/constants/DNSOperationCode.java | 86 ++++++ src/javax/jmdns/impl/constants/DNSOptionCode.java | 78 ++++++ src/javax/jmdns/impl/constants/DNSRecordClass.java | 138 +++++++++ src/javax/jmdns/impl/constants/DNSRecordType.java | 312 +++++++++++++++++++++ src/javax/jmdns/impl/constants/DNSResultCode.java | 149 ++++++++++ src/javax/jmdns/impl/constants/DNSState.java | 215 ++++++++++++++ src/javax/jmdns/impl/constants/package-info.java | 2 + 9 files changed, 1128 insertions(+) create mode 100644 src/javax/jmdns/impl/constants/DNSConstants.java create mode 100644 src/javax/jmdns/impl/constants/DNSLabel.java create mode 100644 src/javax/jmdns/impl/constants/DNSOperationCode.java create mode 100644 src/javax/jmdns/impl/constants/DNSOptionCode.java create mode 100644 src/javax/jmdns/impl/constants/DNSRecordClass.java create mode 100644 src/javax/jmdns/impl/constants/DNSRecordType.java create mode 100644 src/javax/jmdns/impl/constants/DNSResultCode.java create mode 100644 src/javax/jmdns/impl/constants/DNSState.java create mode 100644 src/javax/jmdns/impl/constants/package-info.java (limited to 'src/javax/jmdns/impl/constants') diff --git a/src/javax/jmdns/impl/constants/DNSConstants.java b/src/javax/jmdns/impl/constants/DNSConstants.java new file mode 100644 index 0000000..2704f94 --- /dev/null +++ b/src/javax/jmdns/impl/constants/DNSConstants.java @@ -0,0 +1,61 @@ +// Copyright 2003-2005 Arthur van Hoff, Rick Blair +// Licensed under Apache License version 2.0 +// Original license LGPL + +package javax.jmdns.impl.constants; + +/** + * DNS constants. + * + * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair + */ +public final class DNSConstants { + // http://www.iana.org/assignments/dns-parameters + + // changed to final class - jeffs + public static final String MDNS_GROUP = "224.0.0.251"; + public static final String MDNS_GROUP_IPV6 = "FF02::FB"; + public static final int MDNS_PORT = Integer.parseInt(System.getProperty("net.mdns.port", "5353")); + public static final int DNS_PORT = 53; + + // One hour expiration time + public static final int DNS_TTL = 60 * 60; + + public static final int MAX_MSG_TYPICAL = 1460; + public static final int MAX_MSG_ABSOLUTE = 8972; + + public static final int FLAGS_QR_MASK = 0x8000; // Query response mask + public static final int FLAGS_QR_QUERY = 0x0000; // Query + public static final int FLAGS_QR_RESPONSE = 0x8000; // Response + + public static final int FLAGS_AA = 0x0400; // Authorative answer + public static final int FLAGS_TC = 0x0200; // Truncated + public static final int FLAGS_RD = 0x0100; // Recursion desired + public static final int FLAGS_RA = 0x8000; // Recursion available + + public static final int FLAGS_Z = 0x0040; // Zero + public static final int FLAGS_AD = 0x0020; // Authentic data + public static final int FLAGS_CD = 0x0010; // Checking disabled + + // Time Intervals for various functions + + public static final int SHARED_QUERY_TIME = 20; // milliseconds before send shared query + public static final int QUERY_WAIT_INTERVAL = 225; // milliseconds between query loops. + public static final int PROBE_WAIT_INTERVAL = 250; // milliseconds between probe loops. + public static final int RESPONSE_MIN_WAIT_INTERVAL = 20; // minimal wait interval for response. + public static final int RESPONSE_MAX_WAIT_INTERVAL = 115; // maximal wait interval for response + public static final int PROBE_CONFLICT_INTERVAL = 1000; // milliseconds to wait after conflict. + public static final int PROBE_THROTTLE_COUNT = 10; // After x tries go 1 time a sec. on probes. + public static final int PROBE_THROTTLE_COUNT_INTERVAL = 5000; // We only increment the throttle count, if the previous increment is inside this interval. + public static final int ANNOUNCE_WAIT_INTERVAL = 1000; // milliseconds between Announce loops. + public static final int RECORD_REAPER_INTERVAL = 10000; // milliseconds between cache cleanups. + public static final int RECORD_EXPIRY_DELAY = 1; // This is 1s delay used in ttl and therefore in seconds + public static final int KNOWN_ANSWER_TTL = 120; + public static final int ANNOUNCED_RENEWAL_TTL_INTERVAL = DNS_TTL * 500; // 50% of the TTL in milliseconds + + public static final long CLOSE_TIMEOUT = ANNOUNCE_WAIT_INTERVAL * 5L; + public static final long SERVICE_INFO_TIMEOUT = ANNOUNCE_WAIT_INTERVAL * 6L; + + public static final int NETWORK_CHECK_INTERVAL = 10 * 1000; // 10 secondes + +} diff --git a/src/javax/jmdns/impl/constants/DNSLabel.java b/src/javax/jmdns/impl/constants/DNSLabel.java new file mode 100644 index 0000000..4e27f84 --- /dev/null +++ b/src/javax/jmdns/impl/constants/DNSLabel.java @@ -0,0 +1,87 @@ +/** + * + */ +package javax.jmdns.impl.constants; + +/** + * DNS label. + * + * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair + */ +public enum DNSLabel { + /** + * This is unallocated. + */ + Unknown("", 0x80), + /** + * Standard label [RFC 1035] + */ + Standard("standard label", 0x00), + /** + * Compressed label [RFC 1035] + */ + Compressed("compressed label", 0xC0), + /** + * Extended label [RFC 2671] + */ + Extended("extended label", 0x40); + + /** + * DNS label types are encoded on the first 2 bits + */ + static final int LABEL_MASK = 0xC0; + static final int LABEL_NOT_MASK = 0x3F; + + private final String _externalName; + + private final int _index; + + DNSLabel(String name, int index) { + _externalName = name; + _index = index; + } + + /** + * Return the string representation of this type + * + * @return String + */ + public String externalName() { + return _externalName; + } + + /** + * Return the numeric value of this type + * + * @return String + */ + public int indexValue() { + return _index; + } + + /** + * @param index + * @return label + */ + public static DNSLabel labelForByte(int index) { + int maskedIndex = index & LABEL_MASK; + for (DNSLabel aLabel : DNSLabel.values()) { + if (aLabel._index == maskedIndex) return aLabel; + } + return Unknown; + } + + /** + * @param index + * @return masked value + */ + public static int labelValue(int index) { + return index & LABEL_NOT_MASK; + } + + @Override + public String toString() { + return this.name() + " index " + this.indexValue(); + } + +} diff --git a/src/javax/jmdns/impl/constants/DNSOperationCode.java b/src/javax/jmdns/impl/constants/DNSOperationCode.java new file mode 100644 index 0000000..86af38f --- /dev/null +++ b/src/javax/jmdns/impl/constants/DNSOperationCode.java @@ -0,0 +1,86 @@ +/** + * + */ +package javax.jmdns.impl.constants; + +/** + * DNS operation code. + * + * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair + */ +public enum DNSOperationCode { + /** + * Query [RFC1035] + */ + Query("Query", 0), + /** + * IQuery (Inverse Query, Obsolete) [RFC3425] + */ + IQuery("Inverse Query", 1), + /** + * Status [RFC1035] + */ + Status("Status", 2), + /** + * Unassigned + */ + Unassigned("Unassigned", 3), + /** + * Notify [RFC1996] + */ + Notify("Notify", 4), + /** + * Update [RFC2136] + */ + Update("Update", 5); + + /** + * DNS RCode types are encoded on the last 4 bits + */ + static final int OpCode_MASK = 0x7800; + + private final String _externalName; + + private final int _index; + + DNSOperationCode(String name, int index) { + _externalName = name; + _index = index; + } + + /** + * Return the string representation of this type + * + * @return String + */ + public String externalName() { + return _externalName; + } + + /** + * Return the numeric value of this type + * + * @return String + */ + public int indexValue() { + return _index; + } + + /** + * @param flags + * @return label + */ + public static DNSOperationCode operationCodeForFlags(int flags) { + int maskedIndex = (flags & OpCode_MASK) >> 11; + for (DNSOperationCode aCode : DNSOperationCode.values()) { + if (aCode._index == maskedIndex) return aCode; + } + return Unassigned; + } + + @Override + public String toString() { + return this.name() + " index " + this.indexValue(); + } + +} diff --git a/src/javax/jmdns/impl/constants/DNSOptionCode.java b/src/javax/jmdns/impl/constants/DNSOptionCode.java new file mode 100644 index 0000000..d039fac --- /dev/null +++ b/src/javax/jmdns/impl/constants/DNSOptionCode.java @@ -0,0 +1,78 @@ +/** + * + */ +package javax.jmdns.impl.constants; + +/** + * DNS option code. + * + * @author Arthur van Hoff, Pierre Frisch, Rick Blair + */ +public enum DNSOptionCode { + + /** + * Token + */ + Unknown("Unknown", 65535), + /** + * Long-Lived Queries Option [http://files.dns-sd.org/draft-sekar-dns-llq.txt] + */ + LLQ("LLQ", 1), + /** + * Update Leases Option [http://files.dns-sd.org/draft-sekar-dns-ul.txt] + */ + UL("UL", 2), + /** + * Name Server Identifier Option [RFC5001] + */ + NSID("NSID", 3), + /** + * Owner Option [draft-cheshire-edns0-owner-option] + */ + Owner("Owner", 4); + + private final String _externalName; + + private final int _index; + + DNSOptionCode(String name, int index) { + _externalName = name; + _index = index; + } + + /** + * Return the string representation of this type + * + * @return String + */ + public String externalName() { + return _externalName; + } + + /** + * Return the numeric value of this type + * + * @return String + */ + public int indexValue() { + return _index; + } + + /** + * @param optioncode + * @return label + */ + public static DNSOptionCode resultCodeForFlags(int optioncode) { + int maskedIndex = optioncode; + for (DNSOptionCode aCode : DNSOptionCode.values()) { + if (aCode._index == maskedIndex) return aCode; + } + return Unknown; + } + + @Override + public String toString() { + return this.name() + " index " + this.indexValue(); + } + +} diff --git a/src/javax/jmdns/impl/constants/DNSRecordClass.java b/src/javax/jmdns/impl/constants/DNSRecordClass.java new file mode 100644 index 0000000..9fa3745 --- /dev/null +++ b/src/javax/jmdns/impl/constants/DNSRecordClass.java @@ -0,0 +1,138 @@ +/** + * + */ +package javax.jmdns.impl.constants; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * DNS Record Class + * + * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair + */ +public enum DNSRecordClass { + /** + * + */ + CLASS_UNKNOWN("?", 0), + /** + * static final Internet + */ + CLASS_IN("in", 1), + /** + * CSNET + */ + CLASS_CS("cs", 2), + /** + * CHAOS + */ + CLASS_CH("ch", 3), + /** + * Hesiod + */ + CLASS_HS("hs", 4), + /** + * Used in DNS UPDATE [RFC 2136] + */ + CLASS_NONE("none", 254), + /** + * Not a DNS class, but a DNS query class, meaning "all classes" + */ + CLASS_ANY("any", 255); + + private static Logger logger = Logger.getLogger(DNSRecordClass.class.getName()); + + /** + * Multicast DNS uses the bottom 15 bits to identify the record class...
+ * Except for pseudo records like OPT. + */ + public static final int CLASS_MASK = 0x7FFF; + + /** + * For answers the top bit indicates that all other cached records are now invalid.
+ * For questions it indicates that we should send a unicast response. + */ + public static final int CLASS_UNIQUE = 0x8000; + + /** + * + */ + public static final boolean UNIQUE = true; + + /** + * + */ + public static final boolean NOT_UNIQUE = false; + + private final String _externalName; + + private final int _index; + + DNSRecordClass(String name, int index) { + _externalName = name; + _index = index; + } + + /** + * Return the string representation of this type + * + * @return String + */ + public String externalName() { + return _externalName; + } + + /** + * Return the numeric value of this type + * + * @return String + */ + public int indexValue() { + return _index; + } + + /** + * Checks if the class is unique + * + * @param index + * @return true is the class is unique, false otherwise. + */ + public boolean isUnique(int index) { + return (this != CLASS_UNKNOWN) && ((index & CLASS_UNIQUE) != 0); + } + + /** + * @param name + * @return class for name + */ + public static DNSRecordClass classForName(String name) { + if (name != null) { + String aName = name.toLowerCase(); + for (DNSRecordClass aClass : DNSRecordClass.values()) { + if (aClass._externalName.equals(aName)) return aClass; + } + } + logger.log(Level.WARNING, "Could not find record class for name: " + name); + return CLASS_UNKNOWN; + } + + /** + * @param index + * @return class for name + */ + public static DNSRecordClass classForIndex(int index) { + int maskedIndex = index & CLASS_MASK; + for (DNSRecordClass aClass : DNSRecordClass.values()) { + if (aClass._index == maskedIndex) return aClass; + } + logger.log(Level.WARNING, "Could not find record class for index: " + index); + return CLASS_UNKNOWN; + } + + @Override + public String toString() { + return this.name() + " index " + this.indexValue(); + } + +} diff --git a/src/javax/jmdns/impl/constants/DNSRecordType.java b/src/javax/jmdns/impl/constants/DNSRecordType.java new file mode 100644 index 0000000..e12698c --- /dev/null +++ b/src/javax/jmdns/impl/constants/DNSRecordType.java @@ -0,0 +1,312 @@ +/** + * + */ +package javax.jmdns.impl.constants; + +import java.util.logging.Logger; + +/** + * DNS Record Type + * + * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair + */ +public enum DNSRecordType { + /** + * Address + */ + TYPE_IGNORE("ignore", 0), + /** + * Address + */ + TYPE_A("a", 1), + /** + * Name Server + */ + TYPE_NS("ns", 2), + /** + * Mail Destination + */ + TYPE_MD("md", 3), + /** + * Mail Forwarder + */ + TYPE_MF("mf", 4), + /** + * Canonical Name + */ + TYPE_CNAME("cname", 5), + /** + * Start of Authority + */ + TYPE_SOA("soa", 6), + /** + * Mailbox + */ + TYPE_MB("mb", 7), + /** + * Mail Group + */ + TYPE_MG("mg", 8), + /** + * Mail Rename + */ + TYPE_MR("mr", 9), + /** + * NULL RR + */ + TYPE_NULL("null", 10), + /** + * Well-known-service + */ + TYPE_WKS("wks", 11), + /** + * Domain Name pointer + */ + TYPE_PTR("ptr", 12), + /** + * Host information + */ + TYPE_HINFO("hinfo", 13), + /** + * Mailbox information + */ + TYPE_MINFO("minfo", 14), + /** + * Mail exchanger + */ + TYPE_MX("mx", 15), + /** + * Arbitrary text string + */ + TYPE_TXT("txt", 16), + /** + * for Responsible Person [RFC1183] + */ + TYPE_RP("rp", 17), + /** + * for AFS Data Base location [RFC1183] + */ + TYPE_AFSDB("afsdb", 18), + /** + * for X.25 PSDN address [RFC1183] + */ + TYPE_X25("x25", 19), + /** + * for ISDN address [RFC1183] + */ + TYPE_ISDN("isdn", 20), + /** + * for Route Through [RFC1183] + */ + TYPE_RT("rt", 21), + /** + * for NSAP address, NSAP style A record [RFC1706] + */ + TYPE_NSAP("nsap", 22), + /** + * + */ + TYPE_NSAP_PTR("nsap-otr", 23), + /** + * for security signature [RFC2931] + */ + TYPE_SIG("sig", 24), + /** + * for security key [RFC2535] + */ + TYPE_KEY("key", 25), + /** + * X.400 mail mapping information [RFC2163] + */ + TYPE_PX("px", 26), + /** + * Geographical Position [RFC1712] + */ + TYPE_GPOS("gpos", 27), + /** + * IP6 Address [Thomson] + */ + TYPE_AAAA("aaaa", 28), + /** + * Location Information [Vixie] + */ + TYPE_LOC("loc", 29), + /** + * Next Domain - OBSOLETE [RFC2535, RFC3755] + */ + TYPE_NXT("nxt", 30), + /** + * Endpoint Identifier [Patton] + */ + TYPE_EID("eid", 31), + /** + * Nimrod Locator [Patton] + */ + TYPE_NIMLOC("nimloc", 32), + /** + * Server Selection [RFC2782] + */ + TYPE_SRV("srv", 33), + /** + * ATM Address [Dobrowski] + */ + TYPE_ATMA("atma", 34), + /** + * Naming Authority Pointer [RFC2168, RFC2915] + */ + TYPE_NAPTR("naptr", 35), + /** + * Key Exchanger [RFC2230] + */ + TYPE_KX("kx", 36), + /** + * CERT [RFC2538] + */ + TYPE_CERT("cert", 37), + /** + * A6 [RFC2874] + */ + TYPE_A6("a6", 38), + /** + * DNAME [RFC2672] + */ + TYPE_DNAME("dname", 39), + /** + * SINK [Eastlake] + */ + TYPE_SINK("sink", 40), + /** + * OPT [RFC2671] + */ + TYPE_OPT("opt", 41), + /** + * APL [RFC3123] + */ + TYPE_APL("apl", 42), + /** + * Delegation Signer [RFC3658] + */ + TYPE_DS("ds", 43), + /** + * SSH Key Fingerprint [RFC-ietf-secsh-dns-05.txt] + */ + TYPE_SSHFP("sshfp", 44), + /** + * RRSIG [RFC3755] + */ + TYPE_RRSIG("rrsig", 46), + /** + * NSEC [RFC3755] + */ + TYPE_NSEC("nsec", 47), + /** + * DNSKEY [RFC3755] + */ + TYPE_DNSKEY("dnskey", 48), + /** + * [IANA-Reserved] + */ + TYPE_UINFO("uinfo", 100), + /** + * [IANA-Reserved] + */ + TYPE_UID("uid", 101), + /** + * [IANA-Reserved] + */ + TYPE_GID("gid", 102), + /** + * [IANA-Reserved] + */ + TYPE_UNSPEC("unspec", 103), + /** + * Transaction Key [RFC2930] + */ + TYPE_TKEY("tkey", 249), + /** + * Transaction Signature [RFC2845] + */ + TYPE_TSIG("tsig", 250), + /** + * Incremental transfer [RFC1995] + */ + TYPE_IXFR("ixfr", 251), + /** + * Transfer of an entire zone [RFC1035] + */ + TYPE_AXFR("axfr", 252), + /** + * Mailbox-related records (MB, MG or MR) [RFC1035] + */ + TYPE_MAILA("mails", 253), + /** + * Mail agent RRs (Obsolete - see MX) [RFC1035] + */ + TYPE_MAILB("mailb", 254), + /** + * Request for all records [RFC1035] + */ + TYPE_ANY("any", 255); + + private static Logger logger = Logger.getLogger(DNSRecordType.class.getName()); + + private final String _externalName; + + private final int _index; + + DNSRecordType(String name, int index) { + _externalName = name; + _index = index; + } + + /** + * Return the string representation of this type + * + * @return String + */ + public String externalName() { + return _externalName; + } + + /** + * Return the numeric value of this type + * + * @return String + */ + public int indexValue() { + return _index; + } + + /** + * @param name + * @return type for name + */ + public static DNSRecordType typeForName(String name) { + if (name != null) { + String aName = name.toLowerCase(); + for (DNSRecordType aType : DNSRecordType.values()) { + if (aType._externalName.equals(aName)) return aType; + } + } + logger.severe("Could not find record type for name: " + name); + return TYPE_IGNORE; + } + + /** + * @param index + * @return type for name + */ + public static DNSRecordType typeForIndex(int index) { + for (DNSRecordType aType : DNSRecordType.values()) { + if (aType._index == index) return aType; + } + logger.severe("Could not find record type for index: " + index); + return TYPE_IGNORE; + } + + @Override + public String toString() { + return this.name() + " index " + this.indexValue(); + } + +} diff --git a/src/javax/jmdns/impl/constants/DNSResultCode.java b/src/javax/jmdns/impl/constants/DNSResultCode.java new file mode 100644 index 0000000..aa089f4 --- /dev/null +++ b/src/javax/jmdns/impl/constants/DNSResultCode.java @@ -0,0 +1,149 @@ +/** + * + */ +package javax.jmdns.impl.constants; + +/** + * DNS result code. + * + * @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Rick Blair + */ +public enum DNSResultCode { + /** + * Token + */ + Unknown("Unknown", 65535), + /** + * No Error [RFC1035] + */ + NoError("No Error", 0), + /** + * Format Error [RFC1035] + */ + FormErr("Format Error", 1), + /** + * Server Failure [RFC1035] + */ + ServFail("Server Failure", 2), + /** + * Non-Existent Domain [RFC1035] + */ + NXDomain("Non-Existent Domain", 3), + /** + * Not Implemented [RFC1035] + */ + NotImp("Not Implemented", 4), + /** + * Query Refused [RFC1035] + */ + Refused("Query Refused", 5), + /** + * Name Exists when it should not [RFC2136] + */ + YXDomain("Name Exists when it should not", 6), + /** + * RR Set Exists when it should not [RFC2136] + */ + YXRRSet("RR Set Exists when it should not", 7), + /** + * RR Set that should exist does not [RFC2136] + */ + NXRRSet("RR Set that should exist does not", 8), + /** + * Server Not Authoritative for zone [RFC2136]] + */ + NotAuth("Server Not Authoritative for zone", 9), + /** + * Name not contained in zone [RFC2136] + */ + NotZone("NotZone Name not contained in zone", 10), + + ; + + // 0 NoError No Error [RFC1035] + // 1 FormErr Format Error [RFC1035] + // 2 ServFail Server Failure [RFC1035] + // 3 NXDomain Non-Existent Domain [RFC1035] + // 4 NotImp Not Implemented [RFC1035] + // 5 Refused Query Refused [RFC1035] + // 6 YXDomain Name Exists when it should not [RFC2136] + // 7 YXRRSet RR Set Exists when it should not [RFC2136] + // 8 NXRRSet RR Set that should exist does not [RFC2136] + // 9 NotAuth Server Not Authoritative for zone [RFC2136] + // 10 NotZone Name not contained in zone [RFC2136] + // 11-15 Unassigned + // 16 BADVERS Bad OPT Version [RFC2671] + // 16 BADSIG TSIG Signature Failure [RFC2845] + // 17 BADKEY Key not recognized [RFC2845] + // 18 BADTIME Signature out of time window [RFC2845] + // 19 BADMODE Bad TKEY Mode [RFC2930] + // 20 BADNAME Duplicate key name [RFC2930] + // 21 BADALG Algorithm not supported [RFC2930] + // 22 BADTRUNC Bad Truncation [RFC4635] + // 23-3840 Unassigned + // 3841-4095 Reserved for Private Use [RFC5395] + // 4096-65534 Unassigned + // 65535 Reserved, can be allocated by Standards Action [RFC5395] + + /** + * DNS Result Code types are encoded on the last 4 bits + */ + final static int RCode_MASK = 0x0F; + /** + * DNS Extended Result Code types are encoded on the first 8 bits + */ + final static int ExtendedRCode_MASK = 0xFF; + + private final String _externalName; + + private final int _index; + + DNSResultCode(String name, int index) { + _externalName = name; + _index = index; + } + + /** + * Return the string representation of this type + * + * @return String + */ + public String externalName() { + return _externalName; + } + + /** + * Return the numeric value of this type + * + * @return String + */ + public int indexValue() { + return _index; + } + + /** + * @param flags + * @return label + */ + public static DNSResultCode resultCodeForFlags(int flags) { + int maskedIndex = flags & RCode_MASK; + for (DNSResultCode aCode : DNSResultCode.values()) { + if (aCode._index == maskedIndex) return aCode; + } + return Unknown; + } + + public static DNSResultCode resultCodeForFlags(int flags, int extendedRCode) { + int maskedIndex = ((extendedRCode >> 28) & ExtendedRCode_MASK) | (flags & RCode_MASK); + for (DNSResultCode aCode : DNSResultCode.values()) { + if (aCode._index == maskedIndex) return aCode; + } + return Unknown; + } + + @Override + public String toString() { + return this.name() + " index " + this.indexValue(); + } + +} diff --git a/src/javax/jmdns/impl/constants/DNSState.java b/src/javax/jmdns/impl/constants/DNSState.java new file mode 100644 index 0000000..8c652f5 --- /dev/null +++ b/src/javax/jmdns/impl/constants/DNSState.java @@ -0,0 +1,215 @@ +// Copyright 2003-2005 Arthur van Hoff, Rick Blair +// Licensed under Apache License version 2.0 +// Original license LGPL + +package javax.jmdns.impl.constants; + +/** + * DNSState defines the possible states for services registered with JmDNS. + * + * @author Werner Randelshofer, Rick Blair, Pierre Frisch + */ +public enum DNSState { + + /** + * + */ + PROBING_1("probing 1", StateClass.probing), + /** + * + */ + PROBING_2("probing 2", StateClass.probing), + /** + * + */ + PROBING_3("probing 3", StateClass.probing), + /** + * + */ + ANNOUNCING_1("announcing 1", StateClass.announcing), + /** + * + */ + ANNOUNCING_2("announcing 2", StateClass.announcing), + /** + * + */ + ANNOUNCED("announced", StateClass.announced), + /** + * + */ + CANCELING_1("canceling 1", StateClass.canceling), + /** + * + */ + CANCELING_2("canceling 2", StateClass.canceling), + /** + * + */ + CANCELING_3("canceling 3", StateClass.canceling), + /** + * + */ + CANCELED("canceled", StateClass.canceled), + /** + * + */ + CLOSING("closing", StateClass.closing), + /** + * + */ + CLOSED("closed", StateClass.closed); + + private enum StateClass { + probing, announcing, announced, canceling, canceled, closing, closed + } + + // private static Logger logger = Logger.getLogger(DNSState.class.getName()); + + private final String _name; + + private final StateClass _state; + + private DNSState(String name, StateClass state) { + _name = name; + _state = state; + } + + @Override + public final String toString() { + return _name; + } + + /** + * Returns the next advanced state.
+ * In general, this advances one step in the following sequence: PROBING_1, PROBING_2, PROBING_3, ANNOUNCING_1, ANNOUNCING_2, ANNOUNCED.
+ * or CANCELING_1, CANCELING_2, CANCELING_3, CANCELED Does not advance for ANNOUNCED and CANCELED state. + * + * @return next state + */ + public final DNSState advance() { + switch (this) { + case PROBING_1: + return PROBING_2; + case PROBING_2: + return PROBING_3; + case PROBING_3: + return ANNOUNCING_1; + case ANNOUNCING_1: + return ANNOUNCING_2; + case ANNOUNCING_2: + return ANNOUNCED; + case ANNOUNCED: + return ANNOUNCED; + case CANCELING_1: + return CANCELING_2; + case CANCELING_2: + return CANCELING_3; + case CANCELING_3: + return CANCELED; + case CANCELED: + return CANCELED; + case CLOSING: + return CLOSED; + case CLOSED: + return CLOSED; + default: + // This is just to keep the compiler happy as we have covered all cases before. + return this; + } + } + + /** + * Returns to the next reverted state. All states except CANCELED revert to PROBING_1. Status CANCELED does not revert. + * + * @return reverted state + */ + public final DNSState revert() { + switch (this) { + case PROBING_1: + case PROBING_2: + case PROBING_3: + case ANNOUNCING_1: + case ANNOUNCING_2: + case ANNOUNCED: + return PROBING_1; + case CANCELING_1: + case CANCELING_2: + case CANCELING_3: + return CANCELING_1; + case CANCELED: + return CANCELED; + case CLOSING: + return CLOSING; + case CLOSED: + return CLOSED; + default: + // This is just to keep the compiler happy as we have covered all cases before. + return this; + } + } + + /** + * Returns true, if this is a probing state. + * + * @return true if probing state, false otherwise + */ + public final boolean isProbing() { + return _state == StateClass.probing; + } + + /** + * Returns true, if this is an announcing state. + * + * @return true if announcing state, false otherwise + */ + public final boolean isAnnouncing() { + return _state == StateClass.announcing; + } + + /** + * Returns true, if this is an announced state. + * + * @return true if announced state, false otherwise + */ + public final boolean isAnnounced() { + return _state == StateClass.announced; + } + + /** + * Returns true, if this is a canceling state. + * + * @return true if canceling state, false otherwise + */ + public final boolean isCanceling() { + return _state == StateClass.canceling; + } + + /** + * Returns true, if this is a canceled state. + * + * @return true if canceled state, false otherwise + */ + public final boolean isCanceled() { + return _state == StateClass.canceled; + } + + /** + * Returns true, if this is a closing state. + * + * @return true if closing state, false otherwise + */ + public final boolean isClosing() { + return _state == StateClass.closing; + } + + /** + * Returns true, if this is a closing state. + * + * @return true if closed state, false otherwise + */ + public final boolean isClosed() { + return _state == StateClass.closed; + } + +} diff --git a/src/javax/jmdns/impl/constants/package-info.java b/src/javax/jmdns/impl/constants/package-info.java new file mode 100644 index 0000000..240b927 --- /dev/null +++ b/src/javax/jmdns/impl/constants/package-info.java @@ -0,0 +1,2 @@ +package javax.jmdns.impl.constants; + -- cgit v1.2.3 From cc85bd38e82cb6e41288a2bb90f77ba92d79c9d7 Mon Sep 17 00:00:00 2001 From: Manuel Roman Date: Thu, 15 Sep 2011 11:32:25 -0700 Subject: Changed DNS Record Default Expiration Time to 25 seconds It was an hour, which was making impossible to detect changes in the Active Home mdns beacon in a reasonable amount of time Change-Id: I283507fa2c4aaf18e7233fc8897d538baeeea561 --- src/javax/jmdns/impl/constants/DNSConstants.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/javax/jmdns/impl/constants') diff --git a/src/javax/jmdns/impl/constants/DNSConstants.java b/src/javax/jmdns/impl/constants/DNSConstants.java index 2704f94..b79400b 100644 --- a/src/javax/jmdns/impl/constants/DNSConstants.java +++ b/src/javax/jmdns/impl/constants/DNSConstants.java @@ -18,8 +18,8 @@ public final class DNSConstants { public static final int MDNS_PORT = Integer.parseInt(System.getProperty("net.mdns.port", "5353")); public static final int DNS_PORT = 53; - // One hour expiration time - public static final int DNS_TTL = 60 * 60; + // DNS Records Expiration Time in Seconds + public static final int DNS_TTL = 25; public static final int MAX_MSG_TYPICAL = 1460; public static final int MAX_MSG_ABSOLUTE = 8972; -- cgit v1.2.3 From b99c4f55163e9c4ac6b123f0e8383b9b9072073b Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Tue, 20 Sep 2011 16:02:43 -0700 Subject: Revert the change to DNS_TTL and fix the renewer's TTL In a previous change, DNSConstants.DNS_TTL had been changed to reduce the TTL of mDNS services advertised by the A@H broker. Instead of changing this for all users of JmDNS, A@H will use the DNSStateTask.setDefaultTTL internal API to control the TTL. Also, patch the Renewer so that the renewal interval is based on the task's own TTL instead of the hardcoded TTL in DNSConstants. Change-Id: I9f42b98e8088267b38d380edfd8b2e737d00414e --- src/javax/jmdns/impl/constants/DNSConstants.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/javax/jmdns/impl/constants') diff --git a/src/javax/jmdns/impl/constants/DNSConstants.java b/src/javax/jmdns/impl/constants/DNSConstants.java index b79400b..2704f94 100644 --- a/src/javax/jmdns/impl/constants/DNSConstants.java +++ b/src/javax/jmdns/impl/constants/DNSConstants.java @@ -18,8 +18,8 @@ public final class DNSConstants { public static final int MDNS_PORT = Integer.parseInt(System.getProperty("net.mdns.port", "5353")); public static final int DNS_PORT = 53; - // DNS Records Expiration Time in Seconds - public static final int DNS_TTL = 25; + // One hour expiration time + public static final int DNS_TTL = 60 * 60; public static final int MAX_MSG_TYPICAL = 1460; public static final int MAX_MSG_ABSOLUTE = 8972; -- cgit v1.2.3 From 76f0067cea0428b683cba2f187d81e723658f964 Mon Sep 17 00:00:00 2001 From: Manuel Roman Date: Sun, 25 Sep 2011 18:32:28 -0700 Subject: Modified the constant for TTL We will bring it back as soon as we find the way to specify the constant value in a constructor parameter. Change-Id: I95be2d237c14df1859f8c48fd21c37fd36c69e50 --- src/javax/jmdns/impl/constants/DNSConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/javax/jmdns/impl/constants') diff --git a/src/javax/jmdns/impl/constants/DNSConstants.java b/src/javax/jmdns/impl/constants/DNSConstants.java index 2704f94..ce9f928 100644 --- a/src/javax/jmdns/impl/constants/DNSConstants.java +++ b/src/javax/jmdns/impl/constants/DNSConstants.java @@ -19,7 +19,7 @@ public final class DNSConstants { public static final int DNS_PORT = 53; // One hour expiration time - public static final int DNS_TTL = 60 * 60; + public static final int DNS_TTL = 25; //60 * 60; public static final int MAX_MSG_TYPICAL = 1460; public static final int MAX_MSG_ABSOLUTE = 8972; -- cgit v1.2.3