mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-27 14:32:06 +01:00
SOCKS5 works again :)
This commit is contained in:
parent
3058ebe8b9
commit
d537463a42
4 changed files with 65 additions and 102 deletions
|
@ -104,7 +104,6 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
||||||
return jutil.createErrorOutOfOrder(sessionAccept);
|
return jutil.createErrorOutOfOrder(sessionAccept);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.log(Level.INFO, "Session was accepted. Initiate Bytestream.");
|
|
||||||
state = State.active;
|
state = State.active;
|
||||||
|
|
||||||
transportSession.processJingle(sessionAccept);
|
transportSession.processJingle(sessionAccept);
|
||||||
|
@ -112,7 +111,6 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
||||||
transportSession.initiateOutgoingSession(new JingleTransportInitiationCallback() {
|
transportSession.initiateOutgoingSession(new JingleTransportInitiationCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onSessionInitiated(final BytestreamSession session) {
|
public void onSessionInitiated(final BytestreamSession session) {
|
||||||
LOGGER.log(Level.INFO, "BytestreamSession initiated. Start transfer.");
|
|
||||||
sendingThread = new SendTask(session, source);
|
sendingThread = new SendTask(session, source);
|
||||||
queued.add(threadPool.submit(sendingThread));
|
queued.add(threadPool.submit(sendingThread));
|
||||||
}
|
}
|
||||||
|
@ -128,8 +126,6 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IQ handleSessionTerminate(Jingle sessionTerminate) {
|
public IQ handleSessionTerminate(Jingle sessionTerminate) {
|
||||||
LOGGER.log(Level.INFO, "Received session-terminate: " + sessionTerminate.getReason().asEnum());
|
|
||||||
|
|
||||||
state = State.terminated;
|
state = State.terminated;
|
||||||
return jutil.createAck(sessionTerminate);
|
return jutil.createAck(sessionTerminate);
|
||||||
}
|
}
|
||||||
|
@ -138,8 +134,6 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
||||||
public IQ handleTransportReplace(final Jingle transportReplace)
|
public IQ handleTransportReplace(final Jingle transportReplace)
|
||||||
throws InterruptedException, XMPPException.XMPPErrorException,
|
throws InterruptedException, XMPPException.XMPPErrorException,
|
||||||
SmackException.NotConnectedException, SmackException.NoResponseException {
|
SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||||
LOGGER.log(Level.INFO, "Received transport-replace.");
|
|
||||||
|
|
||||||
final JingleTransportManager<?> replacementManager = JingleTransportMethodManager.getInstanceFor(connection)
|
final JingleTransportManager<?> replacementManager = JingleTransportMethodManager.getInstanceFor(connection)
|
||||||
.getTransportManager(transportReplace);
|
.getTransportManager(transportReplace);
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@ public class ReceiveTask implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
LOGGER.log(Level.INFO, "Start ReceiveTask");
|
|
||||||
JingleFileTransferChild transfer = (JingleFileTransferChild) fileTransfer.getJingleContentDescriptionChildren().get(0);
|
JingleFileTransferChild transfer = (JingleFileTransferChild) fileTransfer.getJingleContentDescriptionChildren().get(0);
|
||||||
FileOutputStream outputStream = null;
|
FileOutputStream outputStream = null;
|
||||||
InputStream inputStream;
|
InputStream inputStream;
|
||||||
|
@ -69,14 +68,12 @@ public class ReceiveTask implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
outputStream.write(filebuf);
|
outputStream.write(filebuf);
|
||||||
LOGGER.log(Level.INFO, "Received " + read + " bytes.");
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Error while receiving data: ", e);
|
LOGGER.log(Level.SEVERE, "Error while receiving data: ", e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
session.close();
|
session.close();
|
||||||
LOGGER.log(Level.INFO, "Session closed.");
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Could not close InputStream.", e);
|
LOGGER.log(Level.SEVERE, "Could not close InputStream.", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,6 @@ public class SendTask implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
LOGGER.log(Level.INFO, "Start SendTask");
|
|
||||||
InputStream inputStream;
|
InputStream inputStream;
|
||||||
OutputStream outputStream;
|
OutputStream outputStream;
|
||||||
|
|
||||||
|
@ -58,7 +57,7 @@ public class SendTask implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
outputStream.write(filebuf);
|
outputStream.write(filebuf);
|
||||||
LOGGER.log(Level.INFO, "Written " + r + " bytes.");
|
outputStream.flush();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Could not send file: " + e, e);
|
LOGGER.log(Level.SEVERE, "Could not send file: " + e, e);
|
||||||
|
@ -66,7 +65,6 @@ public class SendTask implements Runnable {
|
||||||
finally {
|
finally {
|
||||||
try {
|
try {
|
||||||
session.close();
|
session.close();
|
||||||
LOGGER.log(Level.INFO, "Session closed.");
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Could not close session.", e);
|
LOGGER.log(Level.SEVERE, "Could not close session.", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -239,7 +239,14 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
||||||
return IQ.createResultIQ(jingle);
|
return IQ.createResultIQ(jingle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine, which candidate (ours/theirs) is the nominated one.
|
||||||
|
* Connect to this candidate. If it is a proxy and it is ours, activate it and connect.
|
||||||
|
* If its a proxy and it is theirs, wait for activation.
|
||||||
|
* If it is not a proxy, just connect.
|
||||||
|
*/
|
||||||
private void connectIfReady() {
|
private void connectIfReady() {
|
||||||
|
JingleContent content = jingleSession.getContents().get(0);
|
||||||
if (ourChoice == null || theirChoice == null) {
|
if (ourChoice == null || theirChoice == null) {
|
||||||
// Not yet ready.
|
// Not yet ready.
|
||||||
LOGGER.log(Level.INFO, "Not ready.");
|
LOGGER.log(Level.INFO, "Not ready.");
|
||||||
|
@ -249,102 +256,69 @@ 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.");
|
LOGGER.log(Level.INFO, "Failure.");
|
||||||
// TODO: Transport failed.
|
// TODO: Transport failed.
|
||||||
} else {
|
return;
|
||||||
UsedCandidate nominated;
|
}
|
||||||
if (ourChoice != CANDIDATE_FAILURE && theirChoice != CANDIDATE_FAILURE) {
|
|
||||||
if (ourChoice.candidate.getPriority() > theirChoice.candidate.getPriority()) {
|
//Determine nominated candidate.
|
||||||
nominated = ourChoice;
|
UsedCandidate nominated;
|
||||||
} else if (ourChoice.candidate.getPriority() < theirChoice.candidate.getPriority()) {
|
if (ourChoice != CANDIDATE_FAILURE && theirChoice != CANDIDATE_FAILURE) {
|
||||||
nominated = theirChoice;
|
if (ourChoice.candidate.getPriority() > theirChoice.candidate.getPriority()) {
|
||||||
} else {
|
|
||||||
nominated = jingleSession.isInitiator() ? ourChoice : theirChoice;
|
|
||||||
}
|
|
||||||
} else if (ourChoice != CANDIDATE_FAILURE) {
|
|
||||||
nominated = ourChoice;
|
nominated = ourChoice;
|
||||||
} else {
|
} else if (ourChoice.candidate.getPriority() < theirChoice.candidate.getPriority()) {
|
||||||
nominated = theirChoice;
|
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 (isExternalProxy) {
|
||||||
//if (nominated.candidate.getType() == JingleS5BTransportCandidate.Type.proxy) {
|
Bytestream activate = new Bytestream(ourProposal.getStreamId());
|
||||||
if (nominated.candidate.getType() == JingleS5BTransportCandidate.Type.proxy) {
|
activate.setMode(null);
|
||||||
//Our proxy.
|
activate.setType(IQ.Type.set);
|
||||||
if (nominated == theirChoice) {
|
activate.setTo(nominated.candidate.getJid());
|
||||||
LOGGER.log(Level.INFO, "Our proxy.");
|
activate.setToActivate(jingleSession.getRemote());
|
||||||
JingleContent content = jingleSession.getContents().get(0);
|
|
||||||
//Not a local proxy. Activate it.
|
try {
|
||||||
if (!nominated.candidate.getJid().asBareJid().equals(jingleSession.getLocal().asBareJid())) {
|
jingleSession.getConnection().createStanzaCollectorAndSend(activate).nextResultOrThrow();
|
||||||
Bytestream activateProxy = new Bytestream(ourProposal.getStreamId());
|
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
|
||||||
activateProxy.setToActivate(nominated.candidate.getJid());
|
LOGGER.log(Level.WARNING, "Could not activate proxy.", e);
|
||||||
activateProxy.setTo(nominated.candidate.getJid());
|
return;
|
||||||
//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);
|
|
||||||
}
|
}
|
||||||
//Else wait for activation.
|
|
||||||
}
|
}
|
||||||
// Direct connection. Go ahead.
|
|
||||||
else {
|
Jingle candidateActivate = transportManager().createCandidateActivated(
|
||||||
Socks5BytestreamSession bs;
|
jingleSession.getRemote(), jingleSession.getInitiator(), jingleSession.getSessionId(),
|
||||||
if (nominated == ourChoice) {
|
content.getSenders(), content.getCreator(), content.getName(), nominated.transport.getStreamId(),
|
||||||
bs = new Socks5BytestreamSession(nominated.socket,
|
nominated.candidate.getCandidateId());
|
||||||
nominated.candidate.getJid().asBareJid().equals(jingleSession.getRemote().asBareJid()));
|
try {
|
||||||
} else {
|
jingleSession.getConnection().createStanzaCollectorAndSend(candidateActivate)
|
||||||
try {
|
.nextResultOrThrow();
|
||||||
nominated = connectToOurCandidate(theirChoice.candidate);
|
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
|
||||||
} catch (InterruptedException | IOException | XMPPException | SmackException | TimeoutException e) {
|
LOGGER.log(Level.WARNING, "Could not send candidate-activated", e);
|
||||||
LOGGER.log(Level.SEVERE, "Failed to connect to our own StreamHost!");
|
return;
|
||||||
callback.onException(e);
|
}
|
||||||
return;
|
|
||||||
}
|
Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket, !isExternalProxy);
|
||||||
bs = new Socks5BytestreamSession(nominated.socket,
|
callback.onSessionInitiated(bs);
|
||||||
nominated.candidate.getJid().asBareJid().equals(jingleSession.getLocal().asBareJid()));
|
}
|
||||||
}
|
//Our choice
|
||||||
|
else {
|
||||||
|
if (!nominated.candidate.getJid().asBareJid().equals(jingleSession.getRemote().asBareJid())) {
|
||||||
|
Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket, !isExternalProxy);
|
||||||
callback.onSessionInitiated(bs);
|
callback.onSessionInitiated(bs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue