mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-06-16 16:44:48 +02:00
This is a complete redesign of what was previously XmppNioTcpConnection. The new architecture allows to extend an XMPP client to server (c2s) connection with new transport bindings and other extensions.
79 lines
2.6 KiB
Java
79 lines
2.6 KiB
Java
/**
|
|
*
|
|
* Copyright 2020 Florian Schmaus.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* 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.tcp.rce;
|
|
|
|
import java.net.Inet4Address;
|
|
import java.net.Inet6Address;
|
|
import java.net.InetAddress;
|
|
|
|
import org.jivesoftware.smack.datatypes.UInt16;
|
|
import org.jivesoftware.smack.util.rce.SingleAddressRemoteConnectionEndpoint;
|
|
|
|
import org.minidns.record.A;
|
|
import org.minidns.record.AAAA;
|
|
import org.minidns.record.InternetAddressRR;
|
|
|
|
public final class IpTcpRemoteConnectionEndpoint<IARR extends InternetAddressRR>
|
|
implements Rfc6120TcpRemoteConnectionEndpoint, SingleAddressRemoteConnectionEndpoint {
|
|
|
|
private final CharSequence host;
|
|
|
|
private final UInt16 port;
|
|
|
|
private final IARR internetAddressResourceRecord;
|
|
|
|
public IpTcpRemoteConnectionEndpoint(CharSequence host, UInt16 port, IARR internetAddressResourceRecord) {
|
|
this.host = host;
|
|
this.port = port;
|
|
this.internetAddressResourceRecord = internetAddressResourceRecord;
|
|
}
|
|
|
|
public static IpTcpRemoteConnectionEndpoint<InternetAddressRR> from(CharSequence host, int port,
|
|
InetAddress inetAddress) {
|
|
InternetAddressRR internetAddressResourceRecord;
|
|
// TODO: Use InternetAddressRR.from(InetAddress) once MiniDNS is updated.
|
|
if (inetAddress instanceof Inet4Address) {
|
|
internetAddressResourceRecord = new A((Inet4Address) inetAddress);
|
|
} else {
|
|
internetAddressResourceRecord = new AAAA((Inet6Address) inetAddress);
|
|
}
|
|
|
|
return new IpTcpRemoteConnectionEndpoint<InternetAddressRR>(host, UInt16.from(port),
|
|
internetAddressResourceRecord);
|
|
}
|
|
|
|
@Override
|
|
public CharSequence getHost() {
|
|
return host;
|
|
}
|
|
|
|
@Override
|
|
public UInt16 getPort() {
|
|
return port;
|
|
}
|
|
|
|
@Override
|
|
public InetAddress getInetAddress() {
|
|
return internetAddressResourceRecord.getInetAddress();
|
|
}
|
|
|
|
@Override
|
|
public String getDescription() {
|
|
return "RFC 6120 A/AAAA Endpoint + [" + host + ":" + port + "]";
|
|
}
|
|
}
|