mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
So close...
This commit is contained in:
parent
69b3f5837e
commit
9d6a858b23
3 changed files with 46 additions and 32 deletions
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,43 +266,49 @@ 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.
|
||||||
Bytestream activateProxy = new Bytestream(ourProposal.getStreamId());
|
if (!nominated.candidate.getJid().asBareJid().equals(jingleSession.getLocal().asBareJid())) {
|
||||||
activateProxy.setToActivate(nominated.candidate.getJid());
|
Bytestream activateProxy = new Bytestream(ourProposal.getStreamId());
|
||||||
activateProxy.setTo(nominated.candidate.getJid());
|
activateProxy.setToActivate(nominated.candidate.getJid());
|
||||||
//Send proxy activation.
|
activateProxy.setTo(nominated.candidate.getJid());
|
||||||
try {
|
//Send proxy activation.
|
||||||
jingleSession.getConnection().createStanzaCollectorAndSend(activateProxy).nextResultOrThrow();
|
|
||||||
//Connect
|
|
||||||
try {
|
try {
|
||||||
nominated = connectToOurCandidate(nominated.candidate);
|
jingleSession.getConnection().createStanzaCollectorAndSend(activateProxy).nextResultOrThrow();
|
||||||
Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket,
|
//Connect
|
||||||
nominated.candidate.getJid().asBareJid().equals(jingleSession.getLocal().asBareJid()));
|
try {
|
||||||
callback.onSessionInitiated(bs);
|
nominated = connectToOurCandidate(nominated.candidate);
|
||||||
} catch (TimeoutException | SmackException | IOException | XMPPException e) {
|
Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket,
|
||||||
LOGGER.log(Level.WARNING, "Could not connect to our own proxy after activation.", e);
|
nominated.candidate.getJid().asBareJid().equals(jingleSession.getLocal().asBareJid()));
|
||||||
//TODO: ???
|
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
|
||||||
//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()
|
||||||
LOGGER.log(Level.WARNING, "Could not activate proxy at " + nominated.candidate.getJid(), e);
|
+ ". 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(),
|
||||||
content.getCreator(), content.getName(), nominated.transport.getStreamId());
|
content.getCreator(), content.getName(), nominated.transport.getStreamId());
|
||||||
try {
|
try {
|
||||||
jingleSession.getConnection().sendStanza(proxyError);
|
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;
|
||||||
}
|
}
|
||||||
//Could not send proxy-error. WTF?
|
|
||||||
catch (SmackException.NotConnectedException | InterruptedException e1) {
|
|
||||||
LOGGER.log(Level.WARNING, "Could not send proxy-error.", e1);
|
|
||||||
}
|
|
||||||
callback.onException(e);
|
|
||||||
}
|
}
|
||||||
//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.
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue