mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-22 20:47:57 +01:00
[core] Use UInt16 for ConnectionConfiguration 'port'
This commit is contained in:
parent
9a8ee3c8e3
commit
cac874bdc7
3 changed files with 17 additions and 10 deletions
|
@ -35,6 +35,7 @@ import javax.net.ssl.SSLContext;
|
|||
import javax.net.ssl.X509TrustManager;
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
|
||||
import org.jivesoftware.smack.datatypes.UInt16;
|
||||
import org.jivesoftware.smack.debugger.SmackDebuggerFactory;
|
||||
import org.jivesoftware.smack.packet.id.StandardStanzaIdSource;
|
||||
import org.jivesoftware.smack.packet.id.StanzaIdSource;
|
||||
|
@ -101,7 +102,7 @@ public abstract class ConnectionConfiguration {
|
|||
|
||||
protected final InetAddress hostAddress;
|
||||
protected final DnsName host;
|
||||
protected final int port;
|
||||
protected final UInt16 port;
|
||||
|
||||
private final String keystorePath;
|
||||
private final String keystoreType;
|
||||
|
@ -237,7 +238,7 @@ public abstract class ConnectionConfiguration {
|
|||
return hostAddress;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
public UInt16 getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
|
@ -621,7 +622,7 @@ public abstract class ConnectionConfiguration {
|
|||
private DomainBareJid xmppServiceDomain;
|
||||
private InetAddress hostAddress;
|
||||
private DnsName host;
|
||||
private int port = 5222;
|
||||
private UInt16 port = UInt16.from(5222);
|
||||
private boolean allowEmptyOrNullUsername = false;
|
||||
private boolean saslMechanismsSealed;
|
||||
private Set<String> enabledSaslMechanisms;
|
||||
|
@ -837,7 +838,12 @@ public abstract class ConnectionConfiguration {
|
|||
throw new IllegalArgumentException(
|
||||
"Port must be a 16-bit unsigned integer (i.e. between 0-65535. Port was: " + port);
|
||||
}
|
||||
this.port = port;
|
||||
UInt16 portUint16 = UInt16.from(port);
|
||||
return setPort(portUint16);
|
||||
}
|
||||
|
||||
public B setPort(UInt16 port) {
|
||||
this.port = Objects.requireNonNull(port);
|
||||
return getThis();
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public final class IpTcpRemoteConnectionEndpoint<IARR extends InternetAddressRR>
|
|||
this.internetAddressResourceRecord = internetAddressResourceRecord;
|
||||
}
|
||||
|
||||
public static IpTcpRemoteConnectionEndpoint<InternetAddressRR> from(CharSequence host, int port,
|
||||
public static IpTcpRemoteConnectionEndpoint<InternetAddressRR> from(CharSequence host, UInt16 port,
|
||||
InetAddress inetAddress) {
|
||||
InternetAddressRR internetAddressResourceRecord;
|
||||
// TODO: Use InternetAddressRR.from(InetAddress) once MiniDNS is updated.
|
||||
|
@ -52,7 +52,7 @@ public final class IpTcpRemoteConnectionEndpoint<IARR extends InternetAddressRR>
|
|||
internetAddressResourceRecord = new AAAA((Inet6Address) inetAddress);
|
||||
}
|
||||
|
||||
return new IpTcpRemoteConnectionEndpoint<InternetAddressRR>(host, UInt16.from(port),
|
||||
return new IpTcpRemoteConnectionEndpoint<InternetAddressRR>(host, port,
|
||||
internetAddressResourceRecord);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.logging.Logger;
|
|||
|
||||
import org.jivesoftware.smack.ConnectionConfiguration;
|
||||
import org.jivesoftware.smack.ConnectionConfiguration.DnssecMode;
|
||||
import org.jivesoftware.smack.datatypes.UInt16;
|
||||
import org.jivesoftware.smack.util.DNSUtil;
|
||||
import org.jivesoftware.smack.util.dns.DNSResolver;
|
||||
import org.jivesoftware.smack.util.rce.RemoteConnectionEndpoint;
|
||||
|
@ -72,7 +73,7 @@ public class RemoteXmppTcpConnectionEndpoints {
|
|||
|
||||
if (hostAddresses != null) {
|
||||
discoveredRemoteConnectionEndpoints = new ArrayList<>(hostAddresses.size());
|
||||
int port = config.getPort();
|
||||
UInt16 port = config.getPort();
|
||||
for (InetAddress inetAddress : hostAddresses) {
|
||||
IpTcpRemoteConnectionEndpoint<InternetAddressRR> connectionEndpoint = IpTcpRemoteConnectionEndpoint.from(
|
||||
host, port, inetAddress);
|
||||
|
@ -198,13 +199,13 @@ public class RemoteXmppTcpConnectionEndpoints {
|
|||
LOGGER.info("Could not resolve DNS SRV resource records for " + srvDomain + ". Consider adding those.");
|
||||
}
|
||||
|
||||
int defaultPort;
|
||||
UInt16 defaultPort;
|
||||
switch (domainType) {
|
||||
case client:
|
||||
defaultPort = 5222;
|
||||
defaultPort = UInt16.from(5222);
|
||||
break;
|
||||
case server:
|
||||
defaultPort = 5269;
|
||||
defaultPort = UInt16.from(5269);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
|
|
Loading…
Reference in a new issue