2007-03-03 06:20:17 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2003-2006 Jive Software.
|
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2007-03-03 06:20:17 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
2014-02-19 10:38:30 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-03-03 06:20:17 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-08-20 00:25:57 +02:00
|
|
|
package org.jivesoftware.smackx.jingleold.nat;
|
2007-01-04 18:25:30 +01:00
|
|
|
|
2014-03-19 14:22:20 +01:00
|
|
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
2007-01-04 18:25:30 +01:00
|
|
|
import org.jivesoftware.smack.XMPPException;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-08-20 00:25:57 +02:00
|
|
|
import org.jivesoftware.smackx.jingleold.JingleSession;
|
2007-01-04 18:25:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The FixedResolver is a resolver where
|
|
|
|
* the external address and port are previously known when the object is
|
|
|
|
* initialized.
|
|
|
|
*
|
2017-12-25 12:51:41 +01:00
|
|
|
* @author Alvaro Saurin
|
2007-01-04 18:25:30 +01:00
|
|
|
*/
|
|
|
|
public class FixedResolver extends TransportResolver {
|
|
|
|
|
|
|
|
TransportCandidate fixedCandidate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
2019-08-30 12:08:30 +02:00
|
|
|
*
|
|
|
|
* @param ip the IP address.
|
|
|
|
* @param port the port number.
|
2007-01-04 18:25:30 +01:00
|
|
|
*/
|
|
|
|
public FixedResolver(String ip, int port) {
|
|
|
|
super();
|
|
|
|
setFixedCandidate(ip, port);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a basic resolver, where we provide the IP and port.
|
|
|
|
*
|
|
|
|
* @param ip an IP address
|
|
|
|
* @param port a port
|
|
|
|
*/
|
|
|
|
public void setFixedCandidate(String ip, int port) {
|
|
|
|
fixedCandidate = new TransportCandidate.Fixed(ip, port);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve the IP address.
|
2019-08-30 12:08:30 +02:00
|
|
|
* @throws NotConnectedException if the XMPP connection is not connected.
|
|
|
|
* @throws InterruptedException if the calling thread was interrupted.
|
2007-01-04 18:25:30 +01:00
|
|
|
*/
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2015-02-14 09:43:44 +01:00
|
|
|
public synchronized void resolve(JingleSession session) throws XMPPException, NotConnectedException, InterruptedException {
|
2007-01-04 18:25:30 +01:00
|
|
|
if (!isResolving()) {
|
|
|
|
setResolveInit();
|
|
|
|
|
|
|
|
clearCandidates();
|
|
|
|
|
|
|
|
if (fixedCandidate.getLocalIp() == null)
|
|
|
|
fixedCandidate.setLocalIp(fixedCandidate.getIp());
|
|
|
|
|
|
|
|
if (fixedCandidate != null) {
|
|
|
|
addCandidate(fixedCandidate);
|
|
|
|
}
|
|
|
|
|
|
|
|
setResolveEnd();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the resolver.
|
|
|
|
*
|
2019-08-30 12:08:30 +02:00
|
|
|
* @throws XMPPException if an XMPP protocol error was received.
|
2007-01-04 18:25:30 +01:00
|
|
|
*/
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2007-01-04 18:25:30 +01:00
|
|
|
public void initialize() throws XMPPException {
|
|
|
|
setInitialized();
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2007-01-04 18:25:30 +01:00
|
|
|
public void cancel() throws XMPPException {
|
|
|
|
// Nothing to do here
|
|
|
|
}
|
|
|
|
}
|