001/** 002 * 003 * Copyright 2020 Florian Schmaus. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smack.tcp.rce; 018 019import java.net.InetAddress; 020import java.util.Collection; 021import java.util.List; 022 023import org.jivesoftware.smack.datatypes.UInt16; 024import org.jivesoftware.smack.util.Objects; 025import org.jivesoftware.smack.util.rce.RemoteConnectionEndpoint; 026 027import org.minidns.record.SRV; 028 029public abstract class SrvRemoteConnectionEndpoint implements RemoteConnectionEndpoint { 030 031 protected final SRV srv; 032 033 protected final UInt16 port; 034 035 private final List<? extends InetAddress> inetAddresses; 036 037 protected SrvRemoteConnectionEndpoint(SRV srv, List<? extends InetAddress> inetAddresses) { 038 this.srv = srv; 039 this.port = UInt16.from(srv.port); 040 this.inetAddresses = Objects.requireNonNull(inetAddresses); 041 } 042 043 @Override 044 public final CharSequence getHost() { 045 return srv.target; 046 } 047 048 @Override 049 public final UInt16 getPort() { 050 return port; 051 } 052 053 @Override 054 public final Collection<? extends InetAddress> getInetAddresses() { 055 return inetAddresses; 056 } 057 058}