1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-27 14:32:06 +01:00

So close...

This commit is contained in:
vanitasvitae 2017-06-26 23:18:34 +02:00
parent 69b3f5837e
commit 9d6a858b23
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 46 additions and 32 deletions

View file

@ -146,6 +146,7 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
transportSession.initiateIncomingSession(new JingleTransportInitiationCallback() { transportSession.initiateIncomingSession(new JingleTransportInitiationCallback() {
@Override @Override
public void onSessionInitiated(BytestreamSession bytestreamSession) { public void onSessionInitiated(BytestreamSession bytestreamSession) {
LOGGER.log(Level.INFO, "Bytestream initiated. Start receiving.");
receivingThread = new ReceiveTask(bytestreamSession, file, target); receivingThread = new ReceiveTask(bytestreamSession, file, target);
queued.add(threadPool.submit(receivingThread)); queued.add(threadPool.submit(receivingThread));
} }

View file

@ -348,7 +348,7 @@ public final class Socks5Proxy {
* *
* @param digest to be added to the list of allowed transfers * @param digest to be added to the list of allowed transfers
*/ */
protected void addTransfer(String digest) { public void addTransfer(String digest) {
this.allowedConnections.add(digest); this.allowedConnections.add(digest);
} }

View file

@ -30,6 +30,7 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession; import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Client; import org.jivesoftware.smackx.bytestreams.socks5.Socks5Client;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5ClientForInitiator; import org.jivesoftware.smackx.bytestreams.socks5.Socks5ClientForInitiator;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Utils; import org.jivesoftware.smackx.bytestreams.socks5.Socks5Utils;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream; import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.jingle.JingleManager; import org.jivesoftware.smackx.jingle.JingleManager;
@ -113,6 +114,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
} }
private void initiateSession() { private void initiateSession() {
Socks5Proxy.getSocks5Proxy().addTransfer(createTransport().getDestinationAddress());
JingleContent content = jingleSession.getContents().get(0); JingleContent content = jingleSession.getContents().get(0);
UsedCandidate usedCandidate = chooseFromProposedCandidates(theirProposal); UsedCandidate usedCandidate = chooseFromProposedCandidates(theirProposal);
if (usedCandidate == null) { if (usedCandidate == null) {
@ -245,6 +247,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
} }
if (ourChoice == CANDIDATE_FAILURE && theirChoice == CANDIDATE_FAILURE) { if (ourChoice == CANDIDATE_FAILURE && theirChoice == CANDIDATE_FAILURE) {
LOGGER.log(Level.INFO, "Failure.");
// TODO: Transport failed. // TODO: Transport failed.
} else { } else {
UsedCandidate nominated; UsedCandidate nominated;
@ -263,11 +266,14 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
} }
// Proxy. Needs activation. // Proxy. Needs activation.
//if (nominated.candidate.getType() == JingleS5BTransportCandidate.Type.proxy) {
if (nominated.candidate.getType() == JingleS5BTransportCandidate.Type.proxy) { if (nominated.candidate.getType() == JingleS5BTransportCandidate.Type.proxy) {
//Our proxy. Activate it. //Our proxy.
if (nominated == theirChoice) { if (nominated == theirChoice) {
LOGGER.log(Level.INFO, "Our proxy.");
JingleContent content = jingleSession.getContents().get(0); 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()); Bytestream activateProxy = new Bytestream(ourProposal.getStreamId());
activateProxy.setToActivate(nominated.candidate.getJid()); activateProxy.setToActivate(nominated.candidate.getJid());
activateProxy.setTo(nominated.candidate.getJid()); activateProxy.setTo(nominated.candidate.getJid());
@ -280,14 +286,15 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket, Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket,
nominated.candidate.getJid().asBareJid().equals(jingleSession.getLocal().asBareJid())); nominated.candidate.getJid().asBareJid().equals(jingleSession.getLocal().asBareJid()));
callback.onSessionInitiated(bs); callback.onSessionInitiated(bs);
} catch (TimeoutException | SmackException | IOException | XMPPException e) { } catch (InterruptedException | TimeoutException | SmackException | IOException | XMPPException e) {
LOGGER.log(Level.WARNING, "Could not connect to our own proxy after activation.", e); LOGGER.log(Level.WARNING, "Could not connect to our own proxy after activation.", e);
//TODO: ??? //TODO: ???
} }
} }
//Could not activate proxy. Send proxy-error //Could not activate proxy. Send proxy-error
catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) { catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
LOGGER.log(Level.WARNING, "Could not activate proxy at " + nominated.candidate.getJid(), e); LOGGER.log(Level.WARNING, "Could not activate proxy at " + nominated.candidate.getJid()
+ ". Send proxy-error.", e);
Jingle proxyError = transportManager().createProxyError( Jingle proxyError = transportManager().createProxyError(
jingleSession.getRemote(), jingleSession.getInitiator(), jingleSession.getRemote(), jingleSession.getInitiator(),
jingleSession.getSessionId(), content.getSenders(), jingleSession.getSessionId(), content.getSenders(),
@ -300,6 +307,8 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
LOGGER.log(Level.WARNING, "Could not send proxy-error.", e1); LOGGER.log(Level.WARNING, "Could not send proxy-error.", e1);
} }
callback.onException(e); callback.onException(e);
return;
}
} }
//Send candidate-activate. //Send candidate-activate.
Jingle candidateActivate = transportManager().createCandidateActivated( Jingle candidateActivate = transportManager().createCandidateActivated(
@ -309,9 +318,13 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
try { try {
jingleSession.getConnection().createStanzaCollectorAndSend(candidateActivate) jingleSession.getConnection().createStanzaCollectorAndSend(candidateActivate)
.nextResultOrThrow(); .nextResultOrThrow();
LOGGER.log(Level.INFO, "Candidate-activate sent.");
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) { } catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
LOGGER.log(Level.WARNING, "Could not send candidate-activated", e); LOGGER.log(Level.WARNING, "Could not send candidate-activated", e);
return;
} }
Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket, false);
callback.onSessionInitiated(bs);
} }
//Else wait for activation. //Else wait for activation.
} }