diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/OutgoingJingleFileOffer.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/OutgoingJingleFileOffer.java index 2626df5ae..68f762905 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/OutgoingJingleFileOffer.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/OutgoingJingleFileOffer.java @@ -104,7 +104,6 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession { return jutil.createErrorOutOfOrder(sessionAccept); } - LOGGER.log(Level.INFO, "Session was accepted. Initiate Bytestream."); state = State.active; transportSession.processJingle(sessionAccept); @@ -112,7 +111,6 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession { transportSession.initiateOutgoingSession(new JingleTransportInitiationCallback() { @Override public void onSessionInitiated(final BytestreamSession session) { - LOGGER.log(Level.INFO, "BytestreamSession initiated. Start transfer."); sendingThread = new SendTask(session, source); queued.add(threadPool.submit(sendingThread)); } @@ -128,8 +126,6 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession { @Override public IQ handleSessionTerminate(Jingle sessionTerminate) { - LOGGER.log(Level.INFO, "Received session-terminate: " + sessionTerminate.getReason().asEnum()); - state = State.terminated; return jutil.createAck(sessionTerminate); } @@ -138,8 +134,6 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession { public IQ handleTransportReplace(final Jingle transportReplace) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException { - LOGGER.log(Level.INFO, "Received transport-replace."); - final JingleTransportManager replacementManager = JingleTransportMethodManager.getInstanceFor(connection) .getTransportManager(transportReplace); diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/ReceiveTask.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/ReceiveTask.java index d562ca4cb..2909f62b9 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/ReceiveTask.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/ReceiveTask.java @@ -45,7 +45,6 @@ public class ReceiveTask implements Runnable { @Override public void run() { - LOGGER.log(Level.INFO, "Start ReceiveTask"); JingleFileTransferChild transfer = (JingleFileTransferChild) fileTransfer.getJingleContentDescriptionChildren().get(0); FileOutputStream outputStream = null; InputStream inputStream; @@ -69,14 +68,12 @@ public class ReceiveTask implements Runnable { } outputStream.write(filebuf); - LOGGER.log(Level.INFO, "Received " + read + " bytes."); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Error while receiving data: ", e); } finally { try { session.close(); - LOGGER.log(Level.INFO, "Session closed."); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Could not close InputStream.", e); } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/SendTask.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/SendTask.java index 33342a164..93697eb9f 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/SendTask.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/SendTask.java @@ -42,7 +42,6 @@ public class SendTask implements Runnable { @Override public void run() { - LOGGER.log(Level.INFO, "Start SendTask"); InputStream inputStream; OutputStream outputStream; @@ -58,7 +57,7 @@ public class SendTask implements Runnable { } outputStream.write(filebuf); - LOGGER.log(Level.INFO, "Written " + r + " bytes."); + outputStream.flush(); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Could not send file: " + e, e); @@ -66,7 +65,6 @@ public class SendTask implements Runnable { finally { try { session.close(); - LOGGER.log(Level.INFO, "Session closed."); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Could not close session.", e); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportSession.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportSession.java index 38efa3395..cb682331e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportSession.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/JingleS5BTransportSession.java @@ -239,7 +239,14 @@ public class JingleS5BTransportSession extends JingleTransportSession theirChoice.candidate.getPriority()) { - nominated = ourChoice; - } else if (ourChoice.candidate.getPriority() < theirChoice.candidate.getPriority()) { - nominated = theirChoice; - } else { - nominated = jingleSession.isInitiator() ? ourChoice : theirChoice; - } - } else if (ourChoice != CANDIDATE_FAILURE) { + return; + } + + //Determine nominated candidate. + UsedCandidate nominated; + if (ourChoice != CANDIDATE_FAILURE && theirChoice != CANDIDATE_FAILURE) { + if (ourChoice.candidate.getPriority() > theirChoice.candidate.getPriority()) { nominated = ourChoice; - } else { + } else if (ourChoice.candidate.getPriority() < theirChoice.candidate.getPriority()) { nominated = theirChoice; + } else { + nominated = jingleSession.isInitiator() ? ourChoice : theirChoice; + } + } else if (ourChoice != CANDIDATE_FAILURE) { + nominated = ourChoice; + } else { + nominated = theirChoice; + } + + boolean isExternalProxy = !nominated.candidate.getJid().asBareJid().equals(jingleSession.getLocal().asBareJid()); + + if (nominated == theirChoice) { + try { + nominated = connectToOurCandidate(nominated.candidate); + } catch (InterruptedException | IOException | XMPPException | SmackException | TimeoutException e) { + LOGGER.log(Level.INFO, "Could not connect to our candidate."); + return; } - // Proxy. Needs activation. - //if (nominated.candidate.getType() == JingleS5BTransportCandidate.Type.proxy) { - if (nominated.candidate.getType() == JingleS5BTransportCandidate.Type.proxy) { - //Our proxy. - if (nominated == theirChoice) { - LOGGER.log(Level.INFO, "Our proxy."); - JingleContent content = jingleSession.getContents().get(0); - //Not a local proxy. Activate it. - if (!nominated.candidate.getJid().asBareJid().equals(jingleSession.getLocal().asBareJid())) { - Bytestream activateProxy = new Bytestream(ourProposal.getStreamId()); - activateProxy.setToActivate(nominated.candidate.getJid()); - activateProxy.setTo(nominated.candidate.getJid()); - //Send proxy activation. - try { - jingleSession.getConnection().createStanzaCollectorAndSend(activateProxy).nextResultOrThrow(); - //Connect - try { - nominated = connectToOurCandidate(nominated.candidate); - Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket, - nominated.candidate.getJid().asBareJid().equals(jingleSession.getLocal().asBareJid())); - callback.onSessionInitiated(bs); - } catch (InterruptedException | TimeoutException | SmackException | IOException | XMPPException e) { - LOGGER.log(Level.WARNING, "Could not connect to our own proxy after activation.", e); - //TODO: ??? - } - } - //Could not activate proxy. Send proxy-error - catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) { - LOGGER.log(Level.WARNING, "Could not activate proxy at " + nominated.candidate.getJid() - + ". Send proxy-error.", e); - Jingle proxyError = transportManager().createProxyError( - jingleSession.getRemote(), jingleSession.getInitiator(), - jingleSession.getSessionId(), content.getSenders(), - content.getCreator(), content.getName(), nominated.transport.getStreamId()); - try { - jingleSession.getConnection().sendStanza(proxyError); - } - //Could not send proxy-error. WTF? - catch (SmackException.NotConnectedException | InterruptedException e1) { - LOGGER.log(Level.WARNING, "Could not send proxy-error.", e1); - } - callback.onException(e); - return; - } - } - //Send candidate-activate. - Jingle candidateActivate = transportManager().createCandidateActivated( - jingleSession.getRemote(), jingleSession.getInitiator(), jingleSession.getSessionId(), - content.getSenders(), content.getCreator(), content.getName(), nominated.transport.getStreamId(), - nominated.candidate.getCandidateId()); - try { - jingleSession.getConnection().createStanzaCollectorAndSend(candidateActivate) - .nextResultOrThrow(); - LOGGER.log(Level.INFO, "Candidate-activate sent."); - } catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) { - LOGGER.log(Level.WARNING, "Could not send candidate-activated", e); - return; - } - Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket, false); - callback.onSessionInitiated(bs); + if (isExternalProxy) { + Bytestream activate = new Bytestream(ourProposal.getStreamId()); + activate.setMode(null); + activate.setType(IQ.Type.set); + activate.setTo(nominated.candidate.getJid()); + activate.setToActivate(jingleSession.getRemote()); + + try { + jingleSession.getConnection().createStanzaCollectorAndSend(activate).nextResultOrThrow(); + } catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) { + LOGGER.log(Level.WARNING, "Could not activate proxy.", e); + return; } - //Else wait for activation. } - // Direct connection. Go ahead. - else { - Socks5BytestreamSession bs; - if (nominated == ourChoice) { - bs = new Socks5BytestreamSession(nominated.socket, - nominated.candidate.getJid().asBareJid().equals(jingleSession.getRemote().asBareJid())); - } else { - try { - nominated = connectToOurCandidate(theirChoice.candidate); - } catch (InterruptedException | IOException | XMPPException | SmackException | TimeoutException e) { - LOGGER.log(Level.SEVERE, "Failed to connect to our own StreamHost!"); - callback.onException(e); - return; - } - bs = new Socks5BytestreamSession(nominated.socket, - nominated.candidate.getJid().asBareJid().equals(jingleSession.getLocal().asBareJid())); - } + + Jingle candidateActivate = transportManager().createCandidateActivated( + jingleSession.getRemote(), jingleSession.getInitiator(), jingleSession.getSessionId(), + content.getSenders(), content.getCreator(), content.getName(), nominated.transport.getStreamId(), + nominated.candidate.getCandidateId()); + try { + jingleSession.getConnection().createStanzaCollectorAndSend(candidateActivate) + .nextResultOrThrow(); + } catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) { + LOGGER.log(Level.WARNING, "Could not send candidate-activated", e); + return; + } + + Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket, !isExternalProxy); + callback.onSessionInitiated(bs); + } + //Our choice + else { + if (!nominated.candidate.getJid().asBareJid().equals(jingleSession.getRemote().asBareJid())) { + Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket, !isExternalProxy); callback.onSessionInitiated(bs); } }