2013-03-18 09:53:11 +01:00
|
|
|
/**
|
2014-02-17 18:57:38 +01:00
|
|
|
*
|
2017-01-04 15:35:47 +01:00
|
|
|
* Copyright 2013-2017 Florian Schmaus
|
2013-03-18 09:53:11 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2013-03-18 09:53:11 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smack.util.dns;
|
|
|
|
|
2016-10-31 10:45:38 +01:00
|
|
|
import java.net.InetAddress;
|
|
|
|
import java.util.List;
|
|
|
|
|
2017-01-04 15:35:47 +01:00
|
|
|
import org.jivesoftware.smack.util.StringUtils;
|
|
|
|
|
2013-03-18 09:53:11 +01:00
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* A DNS SRV RR.
|
|
|
|
*
|
2014-03-10 18:31:45 +01:00
|
|
|
* @see <a href="http://tools.ietf.org/html/rfc2782">RFC 2782: A DNS RR for specifying the location of services (DNS
|
|
|
|
* SRV)</a>
|
2013-03-18 09:53:11 +01:00
|
|
|
* @author Florian Schmaus
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class SRVRecord extends HostAddress implements Comparable<SRVRecord> {
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2013-03-18 09:53:11 +01:00
|
|
|
private int weight;
|
|
|
|
private int priority;
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2013-03-18 09:53:11 +01:00
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* SRV Record constructor.
|
2013-03-18 09:53:11 +01:00
|
|
|
*
|
2013-04-01 15:40:02 +02:00
|
|
|
* @param fqdn Fully qualified domain name
|
|
|
|
* @param port The connection port
|
|
|
|
* @param priority Priority of the target host
|
|
|
|
* @param weight Relative weight for records with same priority
|
|
|
|
* @throws IllegalArgumentException fqdn is null or any other field is not in valid range (0-65535).
|
2013-03-18 09:53:11 +01:00
|
|
|
*/
|
2016-10-31 10:45:38 +01:00
|
|
|
public SRVRecord(String fqdn, int port, int priority, int weight, List<InetAddress> inetAddresses) {
|
|
|
|
super(fqdn, port, inetAddresses);
|
2017-01-04 15:35:47 +01:00
|
|
|
StringUtils.requireNotNullOrEmpty(fqdn, "The FQDN must not be null");
|
2013-03-18 09:53:11 +01:00
|
|
|
if (weight < 0 || weight > 65535)
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"DNS SRV records weight must be a 16-bit unsiged integer (i.e. between 0-65535. Weight was: "
|
|
|
|
+ weight);
|
|
|
|
|
|
|
|
if (priority < 0 || priority > 65535)
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"DNS SRV records priority must be a 16-bit unsiged integer (i.e. between 0-65535. Priority was: "
|
|
|
|
+ priority);
|
|
|
|
|
|
|
|
this.priority = priority;
|
|
|
|
this.weight = weight;
|
|
|
|
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2013-03-18 09:53:11 +01:00
|
|
|
public int getPriority() {
|
|
|
|
return priority;
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2013-03-18 09:53:11 +01:00
|
|
|
public int getWeight() {
|
|
|
|
return weight;
|
|
|
|
}
|
|
|
|
|
2013-04-01 15:40:02 +02:00
|
|
|
@Override
|
2013-03-18 09:53:11 +01:00
|
|
|
public int compareTo(SRVRecord other) {
|
|
|
|
// According to RFC2782,
|
|
|
|
// "[a] client MUST attempt to contact the target host with the lowest-numbered priority it can reach".
|
|
|
|
// This means that a SRV record with a higher priority is 'less' then one with a lower.
|
|
|
|
int res = other.priority - this.priority;
|
|
|
|
if (res == 0) {
|
|
|
|
res = this.weight - other.weight;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-04-01 15:40:02 +02:00
|
|
|
@Override
|
2013-03-18 09:53:11 +01:00
|
|
|
public String toString() {
|
|
|
|
return super.toString() + " prio:" + priority + ":w:" + weight;
|
|
|
|
}
|
|
|
|
}
|