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() {
|
||||
@Override
|
||||
public void onSessionInitiated(BytestreamSession bytestreamSession) {
|
||||
LOGGER.log(Level.INFO, "Bytestream initiated. Start receiving.");
|
||||
receivingThread = new ReceiveTask(bytestreamSession, file, target);
|
||||
queued.add(threadPool.submit(receivingThread));
|
||||
}
|
||||
|
|
|
@ -348,7 +348,7 @@ public final class Socks5Proxy {
|
|||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.jivesoftware.smack.packet.IQ;
|
|||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Client;
|
||||
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.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
|
@ -113,6 +114,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
}
|
||||
|
||||
private void initiateSession() {
|
||||
Socks5Proxy.getSocks5Proxy().addTransfer(createTransport().getDestinationAddress());
|
||||
JingleContent content = jingleSession.getContents().get(0);
|
||||
UsedCandidate usedCandidate = chooseFromProposedCandidates(theirProposal);
|
||||
if (usedCandidate == null) {
|
||||
|
@ -245,6 +247,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
}
|
||||
|
||||
if (ourChoice == CANDIDATE_FAILURE && theirChoice == CANDIDATE_FAILURE) {
|
||||
LOGGER.log(Level.INFO, "Failure.");
|
||||
// TODO: Transport failed.
|
||||
} else {
|
||||
UsedCandidate nominated;
|
||||
|
@ -263,11 +266,14 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
}
|
||||
|
||||
// Proxy. Needs activation.
|
||||
//if (nominated.candidate.getType() == JingleS5BTransportCandidate.Type.proxy) {
|
||||
if (nominated.candidate.getType() == JingleS5BTransportCandidate.Type.proxy) {
|
||||
//Our proxy. Activate it.
|
||||
//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());
|
||||
|
@ -280,14 +286,15 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket,
|
||||
nominated.candidate.getJid().asBareJid().equals(jingleSession.getLocal().asBareJid()));
|
||||
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);
|
||||
//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(), 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(),
|
||||
|
@ -300,6 +307,8 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
LOGGER.log(Level.WARNING, "Could not send proxy-error.", e1);
|
||||
}
|
||||
callback.onException(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
//Send candidate-activate.
|
||||
Jingle candidateActivate = transportManager().createCandidateActivated(
|
||||
|
@ -309,9 +318,13 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
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);
|
||||
}
|
||||
//Else wait for activation.
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue