1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 20:42:06 +01:00

Cleanup code

This commit is contained in:
vanitasvitae 2017-08-16 15:36:49 +02:00
parent e53165a96c
commit e1655aa344
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
30 changed files with 92 additions and 109 deletions

View file

@ -35,9 +35,9 @@ public abstract class AesGcmNoPadding {
private final int length; private final int length;
protected final Cipher cipher; protected final Cipher cipher;
protected final byte[] key, iv, keyAndIv; private final byte[] key, iv, keyAndIv;
protected AesGcmNoPadding(int bits, int MODE) throws NoSuchAlgorithmException, NoSuchProviderException, AesGcmNoPadding(int bits, int MODE) throws NoSuchAlgorithmException, NoSuchProviderException,
NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException { NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException {
this.length = bits; this.length = bits;
int bytes = bits / 8; int bytes = bits / 8;
@ -136,7 +136,7 @@ public abstract class AesGcmNoPadding {
public abstract String getNamespace(); public abstract String getNamespace();
public static byte[] copyOfRange(byte[] source, int start, int end) { static byte[] copyOfRange(byte[] source, int start, int end) {
byte[] copy = new byte[end - start]; byte[] copy = new byte[end - start];
System.arraycopy(source, start, copy, 0, end - start); System.arraycopy(source, start, copy, 0, end - start);
return copy; return copy;

View file

@ -52,19 +52,19 @@ public class JetSecurity extends JingleSecurity<JetSecurityElement> {
private final String methodNamespace; private final String methodNamespace;
private AesGcmNoPadding aesKey; private AesGcmNoPadding aesKey;
private ExtensionElement child; private final ExtensionElement child;
private String cipherName; private final String cipherName;
private String name; private final String contentName;
public JetSecurity(JetSecurityElement element) { public JetSecurity(JetSecurityElement element) {
super(); super();
this.child = element.getChild(); this.child = element.getChild();
this.methodNamespace = element.getMethodNamespace(); this.methodNamespace = element.getMethodNamespace();
this.name = element.getName(); this.contentName = element.getContentName();
this.cipherName = element.getCipherName(); this.cipherName = element.getCipherName();
} }
public JetSecurity(JingleEncryptionMethod method, FullJid recipient, String name, String cipherName) public JetSecurity(JingleEncryptionMethod method, FullJid recipient, String contentName, String cipherName)
throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException,
InvalidAlgorithmParameterException, InvalidKeyException, InterruptedException, InvalidAlgorithmParameterException, InvalidKeyException, InterruptedException,
JingleEncryptionMethod.JingleEncryptionException, SmackException.NotConnectedException, JingleEncryptionMethod.JingleEncryptionException, SmackException.NotConnectedException,
@ -73,11 +73,11 @@ public class JetSecurity extends JingleSecurity<JetSecurityElement> {
this.methodNamespace = method.getNamespace(); this.methodNamespace = method.getNamespace();
this.aesKey = AesGcmNoPadding.createEncryptionKey(cipherName); this.aesKey = AesGcmNoPadding.createEncryptionKey(cipherName);
this.child = method.encryptJingleTransfer(recipient, aesKey.getKeyAndIv()); this.child = method.encryptJingleTransfer(recipient, aesKey.getKeyAndIv());
this.name = name; this.contentName = contentName;
this.cipherName = cipherName; this.cipherName = cipherName;
} }
public void decryptEncryptionKey(JingleEncryptionMethod method, FullJid sender) private void decryptEncryptionKey(JingleEncryptionMethod method, FullJid sender)
throws InterruptedException, JingleEncryptionMethod.JingleEncryptionException, XMPPException.XMPPErrorException, throws InterruptedException, JingleEncryptionMethod.JingleEncryptionException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException, NoSuchAlgorithmException, SmackException.NotConnectedException, SmackException.NoResponseException, NoSuchAlgorithmException,
InvalidAlgorithmParameterException, NoSuchProviderException, InvalidKeyException, NoSuchPaddingException { InvalidAlgorithmParameterException, NoSuchProviderException, InvalidKeyException, NoSuchPaddingException {
@ -87,7 +87,7 @@ public class JetSecurity extends JingleSecurity<JetSecurityElement> {
@Override @Override
public JetSecurityElement getElement() { public JetSecurityElement getElement() {
return new JetSecurityElement(name, cipherName, child); return new JetSecurityElement(contentName, cipherName, child);
} }
@Override @Override

View file

@ -71,7 +71,7 @@ public class JetSecurityElement extends JingleContentSecurityElement {
return child; return child;
} }
public String getName() { public String getContentName() {
return name; return name;
} }

View file

@ -60,6 +60,7 @@ import org.jxmpp.jid.FullJid;
* Created by vanitas on 22.07.17. * Created by vanitas on 22.07.17.
*/ */
public final class JingleFileTransferManager extends Manager implements JingleDescriptionManager { public final class JingleFileTransferManager extends Manager implements JingleDescriptionManager {
private static final Logger LOGGER = Logger.getLogger(JingleFileTransferManager.class.getName()); private static final Logger LOGGER = Logger.getLogger(JingleFileTransferManager.class.getName());
private static final WeakHashMap<XMPPConnection, JingleFileTransferManager> INSTANCES = new WeakHashMap<>(); private static final WeakHashMap<XMPPConnection, JingleFileTransferManager> INSTANCES = new WeakHashMap<>();

View file

@ -21,7 +21,7 @@ package org.jivesoftware.smackx.jingle_filetransfer.component;
*/ */
public abstract class AbstractJingleFileOffer<D extends JingleFileTransferFile> extends JingleFileTransfer { public abstract class AbstractJingleFileOffer<D extends JingleFileTransferFile> extends JingleFileTransfer {
public AbstractJingleFileOffer(D fileTransferFile) { AbstractJingleFileOffer(D fileTransferFile) {
super(fileTransferFile); super(fileTransferFile);
} }

View file

@ -21,7 +21,7 @@ package org.jivesoftware.smackx.jingle_filetransfer.component;
*/ */
public abstract class AbstractJingleFileRequest<D extends JingleFileTransferFile> extends JingleFileTransfer { public abstract class AbstractJingleFileRequest<D extends JingleFileTransferFile> extends JingleFileTransfer {
public AbstractJingleFileRequest(D fileTransferFile) { AbstractJingleFileRequest(D fileTransferFile) {
super(fileTransferFile); super(fileTransferFile);
} }

View file

@ -39,9 +39,9 @@ public abstract class JingleFileTransfer extends JingleDescription<JingleFileTra
protected State state; protected State state;
protected JingleFileTransferFile file; protected JingleFileTransferFile file;
protected final List<ProgressListener> progressListeners = Collections.synchronizedList(new ArrayList<ProgressListener>()); private final List<ProgressListener> progressListeners = Collections.synchronizedList(new ArrayList<ProgressListener>());
public JingleFileTransfer(JingleFileTransferFile file) { JingleFileTransfer(JingleFileTransferFile file) {
this.file = file; this.file = file;
} }
@ -56,6 +56,11 @@ public abstract class JingleFileTransfer extends JingleDescription<JingleFileTra
progressListeners.remove(listener); progressListeners.remove(listener);
} }
@Override
public void cancel() {
//TODO
}
public void notifyProgressListeners(float progress) { public void notifyProgressListeners(float progress) {
for (ProgressListener p : progressListeners) { for (ProgressListener p : progressListeners) {
p.progress(progress); p.progress(progress);

View file

@ -58,7 +58,7 @@ public abstract class JingleFileTransferFile {
public static class LocalFile extends JingleFileTransferFile { public static class LocalFile extends JingleFileTransferFile {
private File file; private final File file;
private String name; private String name;
private String description; private String description;
private String mediaType; private String mediaType;
@ -137,7 +137,7 @@ public abstract class JingleFileTransferFile {
public static class RemoteFile extends JingleFileTransferFile { public static class RemoteFile extends JingleFileTransferFile {
private JingleFileTransferChildElement file; private final JingleFileTransferChildElement file;
public RemoteFile(JingleFileTransferChildElement file) { public RemoteFile(JingleFileTransferChildElement file) {
super(); super();

View file

@ -28,6 +28,8 @@ import org.jivesoftware.smack.XMPPException;
* User interface for an incoming Jingle file offer. * User interface for an incoming Jingle file offer.
*/ */
public interface IncomingFileOfferController extends JingleFileTransferController { public interface IncomingFileOfferController extends JingleFileTransferController {
void accept(XMPPConnection connection, File target) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, IOException; void accept(XMPPConnection connection, File target) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, IOException;
void accept(XMPPConnection connection, OutputStream outputStream) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, IOException; void accept(XMPPConnection connection, OutputStream outputStream) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, IOException;
} }

View file

@ -20,5 +20,5 @@ package org.jivesoftware.smackx.jingle_filetransfer.controller;
* Created by vanitas on 27.07.17. * Created by vanitas on 27.07.17.
*/ */
public interface IncomingFileRequestController extends JingleFileTransferController { public interface IncomingFileRequestController extends JingleFileTransferController {
//TODO: Declare methods.
} }

View file

@ -30,4 +30,6 @@ public interface JingleFileTransferController extends JingleDescriptionControlle
void removeProgressListener(ProgressListener listener); void removeProgressListener(ProgressListener listener);
JingleFileTransferFile getFile(); JingleFileTransferFile getFile();
void cancel();
} }

View file

@ -20,5 +20,5 @@ package org.jivesoftware.smackx.jingle_filetransfer.controller;
* Created by vanitas on 27.07.17. * Created by vanitas on 27.07.17.
*/ */
public interface OutgoingFileOfferController extends JingleFileTransferController { public interface OutgoingFileOfferController extends JingleFileTransferController {
//TODO: Declare methods.
} }

View file

@ -20,4 +20,5 @@ package org.jivesoftware.smackx.jingle_filetransfer.controller;
* Created by vanitas on 27.07.17. * Created by vanitas on 27.07.17.
*/ */
public interface OutgoingFileRequestController extends JingleFileTransferController { public interface OutgoingFileRequestController extends JingleFileTransferController {
//TODO: Declare methods.
} }

View file

@ -26,6 +26,7 @@ import org.jivesoftware.smackx.jingle_filetransfer.component.JingleFileTransfer;
* Checksum element. * Checksum element.
*/ */
public class ChecksumElement implements ExtensionElement { public class ChecksumElement implements ExtensionElement {
public static final String ELEMENT = "checksum"; public static final String ELEMENT = "checksum";
public static final String ATTR_CREATOR = "creator"; public static final String ATTR_CREATOR = "creator";
public static final String ATTR_NAME = "name"; public static final String ATTR_NAME = "name";

View file

@ -27,6 +27,7 @@ import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildEleme
* Content of type File. * Content of type File.
*/ */
public class JingleFileTransferChildElement extends JingleContentDescriptionChildElement { public class JingleFileTransferChildElement extends JingleContentDescriptionChildElement {
public static final String ELEMENT = "file"; public static final String ELEMENT = "file";
public static final String ELEM_DATE = "date"; public static final String ELEM_DATE = "date";
public static final String ELEM_DESC = "desc"; public static final String ELEM_DESC = "desc";
@ -139,8 +140,8 @@ public class JingleFileTransferChildElement extends JingleContentDescriptionChil
* This is a MIME type from this list: * This is a MIME type from this list:
* https://www.iana.org/assignments/media-types/media-types.xhtml * https://www.iana.org/assignments/media-types/media-types.xhtml
* Default should be application/octet-stream. * Default should be application/octet-stream.
* @param mediaType * @param mediaType new media type.
* @return * @return builder.
*/ */
public Builder setMediaType(String mediaType) { public Builder setMediaType(String mediaType) {
this.mediaType = mediaType; this.mediaType = mediaType;

View file

@ -35,6 +35,7 @@ import org.xmlpull.v1.XmlPullParser;
* Provider for the Checksum element. * Provider for the Checksum element.
*/ */
public class ChecksumProvider extends ExtensionElementProvider<ChecksumElement> { public class ChecksumProvider extends ExtensionElementProvider<ChecksumElement> {
@Override @Override
public ChecksumElement parse(XmlPullParser parser, int initialDepth) throws Exception { public ChecksumElement parse(XmlPullParser parser, int initialDepth) throws Exception {
JingleContentElement.Creator creator = null; JingleContentElement.Creator creator = null;

View file

@ -45,7 +45,7 @@ public class JetElementTest extends SmackTestSuite {
assertEquals(SecurityStub.NAMESPACE, security.getMethodNamespace()); assertEquals(SecurityStub.NAMESPACE, security.getMethodNamespace());
assertEquals(Aes128GcmNoPadding.NAMESPACE, element.getCipherName()); assertEquals(Aes128GcmNoPadding.NAMESPACE, element.getCipherName());
assertEquals(SecurityStub.NAMESPACE, element.getMethodNamespace()); assertEquals(SecurityStub.NAMESPACE, element.getMethodNamespace());
assertEquals("content1", element.getName()); assertEquals("content1", element.getContentName());
String xml = "<security xmlns='" + JetSecurity.NAMESPACE + "' " + String xml = "<security xmlns='" + JetSecurity.NAMESPACE + "' " +
"name='content1' " + "name='content1' " +

View file

@ -1,33 +0,0 @@
/**
*
* Copyright 2017 Paul Schaub
*
* 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.smackx.jingle.callbacks;
import org.jivesoftware.smackx.jingle.JingleDescriptionController;
/**
* Created by vanitas on 27.07.17.
*/
public interface JingleCallback<P extends JingleCallback.Parameters> {
JingleDescriptionController accept(P parameters);
void decline();
class Parameters {
}
}

View file

@ -56,8 +56,8 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
private JingleSession parent; private JingleSession parent;
private JingleContentElement.Creator creator; private JingleContentElement.Creator creator;
private String name; private final String name;
private String disposition; private final String disposition;
private JingleContentElement.Senders senders; private JingleContentElement.Senders senders;
private JingleDescription<?> description; private JingleDescription<?> description;
private JingleTransport<?> transport; private JingleTransport<?> transport;
@ -120,6 +120,10 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
return new JingleContent(description, transport, security, content.getName(), content.getDisposition(), content.getCreator(), content.getSenders()); return new JingleContent(description, transport, security, content.getName(), content.getDisposition(), content.getCreator(), content.getSenders());
} }
public void setSenders(JingleContentElement.Senders senders) {
this.senders = senders;
}
/* HANDLE_XYZ */ /* HANDLE_XYZ */
public IQ handleJingleRequest(JingleElement request, XMPPConnection connection) { public IQ handleJingleRequest(JingleElement request, XMPPConnection connection) {
@ -145,12 +149,12 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
} }
} }
public void handleContentAccept(JingleElement request, XMPPConnection connection) { void handleContentAccept(JingleElement request, XMPPConnection connection) {
start(connection); start(connection);
} }
public IQ handleSessionAccept(JingleElement request, XMPPConnection connection) { IQ handleSessionAccept(JingleElement request, XMPPConnection connection) {
LOGGER.log(Level.INFO, "RECEIVED SESSION ACCEPT!"); LOGGER.log(Level.INFO, "RECEIVED SESSION ACCEPT!");
JingleContentElement contentElement = null; JingleContentElement contentElement = null;
for (JingleContentElement c : request.getContents()) { for (JingleContentElement c : request.getContents()) {
@ -169,26 +173,26 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
return IQ.createResultIQ(request); return IQ.createResultIQ(request);
} }
public IQ handleContentModify(JingleElement request, XMPPConnection connection) { private IQ handleContentModify(JingleElement request, XMPPConnection connection) {
return IQ.createErrorResponse(request, XMPPError.Condition.feature_not_implemented); return IQ.createErrorResponse(request, XMPPError.Condition.feature_not_implemented);
} }
public IQ handleDescriptionInfo(JingleElement request, XMPPConnection connection) { private IQ handleDescriptionInfo(JingleElement request, XMPPConnection connection) {
return IQ.createErrorResponse(request, XMPPError.Condition.feature_not_implemented); return IQ.createErrorResponse(request, XMPPError.Condition.feature_not_implemented);
} }
public void handleContentRemove(JingleSession session, XMPPConnection connection) { public void handleContentRemove(JingleSession session, XMPPConnection connection) {
} }
public IQ handleSecurityInfo(JingleElement request, XMPPConnection connection) { private IQ handleSecurityInfo(JingleElement request, XMPPConnection connection) {
return IQ.createErrorResponse(request, XMPPError.Condition.feature_not_implemented); return IQ.createErrorResponse(request, XMPPError.Condition.feature_not_implemented);
} }
public IQ handleSessionInfo(JingleElement request, XMPPConnection connection) { private IQ handleSessionInfo(JingleElement request, XMPPConnection connection) {
return IQ.createResultIQ(request); return IQ.createResultIQ(request);
} }
public IQ handleTransportAccept(JingleElement request, XMPPConnection connection) { private IQ handleTransportAccept(JingleElement request, XMPPConnection connection) {
if (pendingReplacingTransport == null) { if (pendingReplacingTransport == null) {
LOGGER.log(Level.WARNING, "Received transport-accept, but apparently we did not try to replace the transport."); LOGGER.log(Level.WARNING, "Received transport-accept, but apparently we did not try to replace the transport.");
@ -203,14 +207,14 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
return IQ.createResultIQ(request); return IQ.createResultIQ(request);
} }
public IQ handleTransportInfo(JingleElement request, XMPPConnection connection) { private IQ handleTransportInfo(JingleElement request, XMPPConnection connection) {
assert request.getContents().size() == 1; assert request.getContents().size() == 1;
JingleContentElement content = request.getContents().get(0); JingleContentElement content = request.getContents().get(0);
return transport.handleTransportInfo(content.getTransport().getInfo(), request); return transport.handleTransportInfo(content.getTransport().getInfo(), request);
} }
public IQ handleTransportReject(JingleElement request, XMPPConnection connection) { private IQ handleTransportReject(JingleElement request, XMPPConnection connection) {
if (pendingReplacingTransport == null) { if (pendingReplacingTransport == null) {
throw new AssertionError("We didn't try to replace the transport."); throw new AssertionError("We didn't try to replace the transport.");
} }
@ -224,7 +228,7 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
return IQ.createResultIQ(request); return IQ.createResultIQ(request);
} }
public IQ handleTransportReplace(final JingleElement request, final XMPPConnection connection) { private IQ handleTransportReplace(final JingleElement request, final XMPPConnection connection) {
//Tie Break? //Tie Break?
if (pendingReplacingTransport != null) { if (pendingReplacingTransport != null) {
Async.go(new Runnable() { Async.go(new Runnable() {
@ -490,7 +494,7 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
connection.createStanzaCollectorAndSend(transportReplace).nextResultOrThrow(); connection.createStanzaCollectorAndSend(transportReplace).nextResultOrThrow();
} }
public static String randomName() { private static String randomName() {
return "cont-" + StringUtils.randomString(16); return "cont-" + StringUtils.randomString(16);
} }
} }

View file

@ -370,7 +370,7 @@ public class JingleSession {
return content; return content;
} }
private JingleContent getSoleProposedContentOrThrow(JingleElement request) { private static JingleContent getSoleProposedContentOrThrow(JingleElement request) {
if (request.getContents().size() != 1) { if (request.getContents().size() != 1) {
throw new AssertionError("More/less than 1 content in request!"); throw new AssertionError("More/less than 1 content in request!");
} }

View file

@ -44,7 +44,7 @@ public enum JingleAction {
transport_replace, transport_replace,
; ;
private static final Map<String, JingleAction> map = new HashMap<String, JingleAction>( private static final Map<String, JingleAction> map = new HashMap<>(
JingleAction.values().length); JingleAction.values().length);
static { static {
for (JingleAction jingleAction : JingleAction.values()) { for (JingleAction jingleAction : JingleAction.values()) {
@ -54,7 +54,7 @@ public enum JingleAction {
private final String asString; private final String asString;
private JingleAction() { JingleAction() {
asString = this.name().replace('_', '-'); asString = this.name().replace('_', '-');
} }

View file

@ -26,13 +26,13 @@ public final class JingleErrorElement implements ExtensionElement {
public static String NAMESPACE = "urn:xmpp:jingle:errors:1"; public static String NAMESPACE = "urn:xmpp:jingle:errors:1";
public static final JingleErrorElement OUT_OF_ORDER = new JingleErrorElement("out-of-order"); static final JingleErrorElement OUT_OF_ORDER = new JingleErrorElement("out-of-order");
public static final JingleErrorElement TIE_BREAK = new JingleErrorElement("tie-break"); static final JingleErrorElement TIE_BREAK = new JingleErrorElement("tie-break");
public static final JingleErrorElement UNKNOWN_SESSION = new JingleErrorElement("unknown-session"); static final JingleErrorElement UNKNOWN_SESSION = new JingleErrorElement("unknown-session");
public static final JingleErrorElement UNSUPPORTED_INFO = new JingleErrorElement("unsupported-info"); static final JingleErrorElement UNSUPPORTED_INFO = new JingleErrorElement("unsupported-info");
private final String errorName; private final String errorName;

View file

@ -131,7 +131,7 @@ public class JingleReasonElement implements NamedElement {
public static class AlternativeSession extends JingleReasonElement { public static class AlternativeSession extends JingleReasonElement {
public static final String SID = "sid"; public static final String ATTR_SID = "sid";
private final String sessionId; private final String sessionId;
public AlternativeSession(String sessionId) { public AlternativeSession(String sessionId) {
@ -148,9 +148,9 @@ public class JingleReasonElement implements NamedElement {
xml.rightAngleBracket(); xml.rightAngleBracket();
xml.openElement(reason.asString); xml.openElement(reason.asString);
xml.openElement(SID); xml.openElement(ATTR_SID);
xml.append(sessionId); xml.append(sessionId);
xml.closeElement(SID); xml.closeElement(ATTR_SID);
xml.closeElement(reason.asString); xml.closeElement(reason.asString);
xml.closeElement(this); xml.closeElement(this);

View file

@ -99,7 +99,7 @@ public class JingleProvider extends IQProvider<JingleElement> {
return builder.build(); return builder.build();
} }
public static JingleContentElement parseJingleContent(XmlPullParser parser, final int initialDepth) private static JingleContentElement parseJingleContent(XmlPullParser parser, final int initialDepth)
throws Exception { throws Exception {
JingleContentElement.Builder builder = JingleContentElement.getBuilder(); JingleContentElement.Builder builder = JingleContentElement.getBuilder();

View file

@ -18,7 +18,6 @@ package org.jivesoftware.smackx.jingle.transport.jingle_s5b;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.logging.Level; import java.util.logging.Level;
@ -234,7 +233,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
} }
@SuppressWarnings("ReferenceEquality") @SuppressWarnings("ReferenceEquality")
void establishBytestreamSession(XMPPConnection connection) private void establishBytestreamSession(XMPPConnection connection)
throws SmackException.NotConnectedException, InterruptedException { throws SmackException.NotConnectedException, InterruptedException {
Socks5Proxy.getSocks5Proxy().addTransfer(ourDstAddr); Socks5Proxy.getSocks5Proxy().addTransfer(ourDstAddr);
JingleS5BTransportManager transportManager = JingleS5BTransportManager.getInstanceFor(connection); JingleS5BTransportManager transportManager = JingleS5BTransportManager.getInstanceFor(connection);
@ -254,7 +253,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
} }
@SuppressWarnings("ReferenceEquality") @SuppressWarnings("ReferenceEquality")
public JingleS5BTransportCandidate connectToCandidates(int timeout) { private JingleS5BTransportCandidate connectToCandidates(int timeout) {
if (getTheirCandidates().size() == 0) { if (getTheirCandidates().size() == 0) {
LOGGER.log(Level.INFO, "They provided 0 candidates."); LOGGER.log(Level.INFO, "They provided 0 candidates.");
@ -281,7 +280,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
} }
@SuppressWarnings("ReferenceEquality") @SuppressWarnings("ReferenceEquality")
void connectIfReady() { private void connectIfReady() {
final JingleS5BTransportManager jingleS5BTransportManager = JingleS5BTransportManager.getInstanceFor(getParent().getParent().getJingleManager().getConnection()); final JingleS5BTransportManager jingleS5BTransportManager = JingleS5BTransportManager.getInstanceFor(getParent().getParent().getJingleManager().getConnection());
final JingleSession session = getParent().getParent(); final JingleSession session = getParent().getParent();
@ -427,9 +426,8 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
return; return;
} }
Iterator<JingleTransportCandidate<?>> ourCandidates = getOurCandidates().iterator(); for (JingleTransportCandidate<?> jingleTransportCandidate : getOurCandidates()) {
while (ourCandidates.hasNext()) { JingleS5BTransportCandidate candidate = (JingleS5BTransportCandidate) jingleTransportCandidate;
JingleS5BTransportCandidate candidate = (JingleS5BTransportCandidate) ourCandidates.next();
if (candidate.getCandidateId().equals(candidateId)) { if (candidate.getCandidateId().equals(candidateId)) {
theirSelectedCandidate = candidate; theirSelectedCandidate = candidate;
} }

View file

@ -45,11 +45,11 @@ public class JingleS5BTransportCandidate extends JingleTransportCandidate<Jingle
private Socket socket; private Socket socket;
public JingleS5BTransportCandidate(JingleS5BTransportCandidateElement element) { JingleS5BTransportCandidate(JingleS5BTransportCandidateElement element) {
this(element.getCandidateId(), new Bytestream.StreamHost(element.getJid(), element.getHost(), element.getPort()), element.getPriority(), element.getType()); this(element.getCandidateId(), new Bytestream.StreamHost(element.getJid(), element.getHost(), element.getPort()), element.getPriority(), element.getType());
} }
public JingleS5BTransportCandidate(String candidateId, JingleS5BTransportCandidate(String candidateId,
Bytestream.StreamHost streamHost, Bytestream.StreamHost streamHost,
int priority, int priority,
JingleS5BTransportCandidateElement.Type type) { JingleS5BTransportCandidateElement.Type type) {
@ -60,18 +60,18 @@ public class JingleS5BTransportCandidate extends JingleTransportCandidate<Jingle
setPriority(priority); setPriority(priority);
} }
public JingleS5BTransportCandidate(JingleS5BTransportCandidate other) { JingleS5BTransportCandidate(JingleS5BTransportCandidate other) {
this(other.candidateId, this(other.candidateId,
other.getStreamHost(), other.getStreamHost(),
other.getPriority(), other.getPriority(),
other.type); other.type);
} }
public static JingleS5BTransportCandidate fromElement(JingleS5BTransportCandidateElement element) { static JingleS5BTransportCandidate fromElement(JingleS5BTransportCandidateElement element) {
return new JingleS5BTransportCandidate(element.getCandidateId(), element.getStreamHost(), element.getPriority(), element.getType()); return new JingleS5BTransportCandidate(element.getCandidateId(), element.getStreamHost(), element.getPriority(), element.getType());
} }
public String getCandidateId() { String getCandidateId() {
return candidateId; return candidateId;
} }

View file

@ -121,7 +121,7 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
return 10000; // SOCKS5 has a high priority return 10000; // SOCKS5 has a high priority
} }
public List<JingleTransportCandidate<?>> collectCandidates() { List<JingleTransportCandidate<?>> collectCandidates() {
List<JingleTransportCandidate<?>> candidates = new ArrayList<>(); List<JingleTransportCandidate<?>> candidates = new ArrayList<>();
//Local host //Local host
@ -156,21 +156,21 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
return socks5BytestreamManager.getLocalStreamHost(); return socks5BytestreamManager.getLocalStreamHost();
} }
public List<Bytestream.StreamHost> getServersStreamHosts() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException { private List<Bytestream.StreamHost> getServersStreamHosts() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
if (availableStreamHosts == null) { if (availableStreamHosts == null) {
availableStreamHosts = queryServersStreamHosts(); availableStreamHosts = queryServersStreamHosts();
} }
return availableStreamHosts; return availableStreamHosts;
} }
public List<Bytestream.StreamHost> getLocalStreamHosts() { private List<Bytestream.StreamHost> getLocalStreamHosts() {
if (localStreamHosts == null) { if (localStreamHosts == null) {
localStreamHosts = queryLocalStreamHosts(); localStreamHosts = queryLocalStreamHosts();
} }
return localStreamHosts; return localStreamHosts;
} }
public List<Bytestream.StreamHost> determineStreamHostInfo(List<Jid> proxies) { private List<Bytestream.StreamHost> determineStreamHostInfo(List<Jid> proxies) {
List<Bytestream.StreamHost> streamHosts = new ArrayList<>(); List<Bytestream.StreamHost> streamHosts = new ArrayList<>();
Iterator<Jid> iterator = proxies.iterator(); Iterator<Jid> iterator = proxies.iterator();
@ -192,7 +192,7 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
return streamHosts; return streamHosts;
} }
private JingleElement createTransportInfo(JingleS5BTransport transport, JingleS5BTransportInfoElement info) { private static JingleElement createTransportInfo(JingleS5BTransport transport, JingleS5BTransportInfoElement info) {
JingleContent content = transport.getParent(); JingleContent content = transport.getParent();
JingleSession session = content.getParent(); JingleSession session = content.getParent();
@ -222,19 +222,19 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
return jingle; return jingle;
} }
JingleElement createCandidateUsed(JingleS5BTransport transport, JingleS5BTransportCandidate candidate) { static JingleElement createCandidateUsed(JingleS5BTransport transport, JingleS5BTransportCandidate candidate) {
return createTransportInfo(transport, new JingleS5BTransportInfoElement.CandidateUsed(candidate.getCandidateId())); return createTransportInfo(transport, new JingleS5BTransportInfoElement.CandidateUsed(candidate.getCandidateId()));
} }
JingleElement createCandidateError(JingleS5BTransport transport) { static JingleElement createCandidateError(JingleS5BTransport transport) {
return createTransportInfo(transport, JingleS5BTransportInfoElement.CandidateError.INSTANCE); return createTransportInfo(transport, JingleS5BTransportInfoElement.CandidateError.INSTANCE);
} }
JingleElement createProxyError(JingleS5BTransport transport) { static JingleElement createProxyError(JingleS5BTransport transport) {
return createTransportInfo(transport, JingleS5BTransportInfoElement.ProxyError.INSTANCE); return createTransportInfo(transport, JingleS5BTransportInfoElement.ProxyError.INSTANCE);
} }
JingleElement createCandidateActivated(JingleS5BTransport transport, JingleS5BTransportCandidate candidate) { static JingleElement createCandidateActivated(JingleS5BTransport transport, JingleS5BTransportCandidate candidate) {
return createTransportInfo(transport, new JingleS5BTransportInfoElement.CandidateActivated(candidate.getCandidateId())); return createTransportInfo(transport, new JingleS5BTransportInfoElement.CandidateActivated(candidate.getCandidateId()));
} }
@ -259,7 +259,7 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
return getPriority() > other.getPriority() ? 1 : -1; return getPriority() > other.getPriority() ? 1 : -1;
} }
private ConnectionListener connectionListener = new ConnectionListener() { private final ConnectionListener connectionListener = new ConnectionListener() {
@Override @Override
public void connected(XMPPConnection connection) { public void connected(XMPPConnection connection) {

View file

@ -32,7 +32,7 @@ public class S5BTransportException extends FailedTransportException {
public static class CandidateError extends S5BTransportException { public static class CandidateError extends S5BTransportException {
protected static final long serialVersionUID = 1L; protected static final long serialVersionUID = 1L;
public CandidateError(Throwable throwable) { CandidateError(Throwable throwable) {
super(throwable); super(throwable);
} }
} }
@ -40,7 +40,7 @@ public class S5BTransportException extends FailedTransportException {
public static class ProxyError extends S5BTransportException { public static class ProxyError extends S5BTransportException {
protected static final long serialVersionUID = 1L; protected static final long serialVersionUID = 1L;
public ProxyError(Throwable throwable) { ProxyError(Throwable throwable) {
super(throwable); super(throwable);
} }
} }

View file

@ -29,7 +29,7 @@ public abstract class JingleS5BTransportInfoElement extends JingleContentTranspo
private final String candidateId; private final String candidateId;
protected JingleS5BCandidateTransportInfoElement(String candidateId) { JingleS5BCandidateTransportInfoElement(String candidateId) {
this.candidateId = candidateId; this.candidateId = candidateId;
} }

View file

@ -172,7 +172,7 @@ public class JingleFileTransferIntegrationTest extends AbstractSmackIntegrationT
} }
@AfterClass @AfterClass
public void cleanup() { public static void cleanup() {
Socks5Proxy.getSocks5Proxy().stop(); Socks5Proxy.getSocks5Proxy().stop();
} }
} }