mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-27 14:32:06 +01:00
S5B Works now in both directions and with external proxy
This commit is contained in:
parent
d537463a42
commit
a395b11ee9
2 changed files with 35 additions and 16 deletions
|
@ -42,8 +42,8 @@ public class SendTask implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
InputStream inputStream;
|
InputStream inputStream = null;
|
||||||
OutputStream outputStream;
|
OutputStream outputStream = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
inputStream = new FileInputStream(source);
|
inputStream = new FileInputStream(source);
|
||||||
|
@ -56,15 +56,21 @@ public class SendTask implements Runnable {
|
||||||
throw new IOException("Read returned -1");
|
throw new IOException("Read returned -1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGGER.log(Level.INFO, "WRITE");
|
||||||
outputStream.write(filebuf);
|
outputStream.write(filebuf);
|
||||||
outputStream.flush();
|
LOGGER.log(Level.INFO, "WRITING FINISHED");
|
||||||
}
|
}
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
finally {
|
finally {
|
||||||
try {
|
try {
|
||||||
session.close();
|
if (inputStream != null) {
|
||||||
|
inputStream.close();
|
||||||
|
LOGGER.log(Level.INFO, "InputStream 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,9 +78,9 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
||||||
Socks5Utils.createDigest(sid, jingleSession.getLocal(), jingleSession.getRemote()));
|
Socks5Utils.createDigest(sid, jingleSession.getLocal(), jingleSession.getRemote()));
|
||||||
|
|
||||||
//Local host
|
//Local host
|
||||||
for (Bytestream.StreamHost host : transportManager().getLocalStreamHosts()) {
|
//for (Bytestream.StreamHost host : transportManager().getLocalStreamHosts()) {
|
||||||
jb.addTransportCandidate(new JingleS5BTransportCandidate(host, 100));
|
// jb.addTransportCandidate(new JingleS5BTransportCandidate(host, 100));
|
||||||
}
|
//}
|
||||||
|
|
||||||
List<Bytestream.StreamHost> remoteHosts;
|
List<Bytestream.StreamHost> remoteHosts;
|
||||||
try {
|
try {
|
||||||
|
@ -172,10 +172,10 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
||||||
String address = streamHost.getAddress();
|
String address = streamHost.getAddress();
|
||||||
Socks5ClientForInitiator socks5Client = new Socks5ClientForInitiator(
|
Socks5ClientForInitiator socks5Client = new Socks5ClientForInitiator(
|
||||||
streamHost, ourProposal.getDestinationAddress(), jingleSession.getConnection(),
|
streamHost, ourProposal.getDestinationAddress(), jingleSession.getConnection(),
|
||||||
jingleSession.getSessionId(), jingleSession.getRemote());
|
ourProposal.getStreamId(), jingleSession.getRemote());
|
||||||
Socket socket = socks5Client.getSocket(10 * 1000);
|
Socket socket = socks5Client.getSocket(10 * 1000);
|
||||||
LOGGER.log(Level.INFO, "Connected to our StreamHost " + address + " using dstAddr "
|
LOGGER.log(Level.INFO, "Connected to our StreamHost " + address + " using dstAddr "
|
||||||
+ theirProposal.getDestinationAddress());
|
+ ourProposal.getDestinationAddress());
|
||||||
return new UsedCandidate(ourProposal, candidate, socket);
|
return new UsedCandidate(ourProposal, candidate, socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,6 +222,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQ handleCandidateActivate(Jingle jingle) {
|
public IQ handleCandidateActivate(Jingle jingle) {
|
||||||
|
LOGGER.log(Level.INFO, "handleChandidateActivate");
|
||||||
Socks5BytestreamSession bs = new Socks5BytestreamSession(ourChoice.socket,
|
Socks5BytestreamSession bs = new Socks5BytestreamSession(ourChoice.socket,
|
||||||
ourChoice.candidate.getJid().asBareJid().equals(jingleSession.getRemote().asBareJid()));
|
ourChoice.candidate.getJid().asBareJid().equals(jingleSession.getRemote().asBareJid()));
|
||||||
callback.onSessionInitiated(bs);
|
callback.onSessionInitiated(bs);
|
||||||
|
@ -259,6 +260,8 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGGER.log(Level.INFO, "Ready.");
|
||||||
|
|
||||||
//Determine nominated candidate.
|
//Determine nominated candidate.
|
||||||
UsedCandidate nominated;
|
UsedCandidate nominated;
|
||||||
if (ourChoice != CANDIDATE_FAILURE && theirChoice != CANDIDATE_FAILURE) {
|
if (ourChoice != CANDIDATE_FAILURE && theirChoice != CANDIDATE_FAILURE) {
|
||||||
|
@ -275,23 +278,26 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
||||||
nominated = theirChoice;
|
nominated = theirChoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isExternalProxy = !nominated.candidate.getJid().asBareJid().equals(jingleSession.getLocal().asBareJid());
|
boolean ourExternalProxy = !nominated.candidate.getJid().asBareJid().equals(jingleSession.getLocal().asBareJid());
|
||||||
|
boolean theirExternalProxy = !nominated.candidate.getJid().asBareJid().equals(jingleSession.getRemote().asBareJid());
|
||||||
|
|
||||||
if (nominated == theirChoice) {
|
if (nominated == theirChoice) {
|
||||||
|
LOGGER.log(Level.INFO, "Their choice, so our proposed candidate is used.");
|
||||||
try {
|
try {
|
||||||
nominated = connectToOurCandidate(nominated.candidate);
|
nominated = connectToOurCandidate(nominated.candidate);
|
||||||
} catch (InterruptedException | IOException | XMPPException | SmackException | TimeoutException e) {
|
} catch (InterruptedException | IOException | XMPPException | SmackException | TimeoutException e) {
|
||||||
LOGGER.log(Level.INFO, "Could not connect to our candidate.");
|
LOGGER.log(Level.INFO, "Could not connect to our candidate.", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isExternalProxy) {
|
if (ourExternalProxy) {
|
||||||
|
LOGGER.log(Level.INFO, "Is external proxy. Activate it.");
|
||||||
Bytestream activate = new Bytestream(ourProposal.getStreamId());
|
Bytestream activate = new Bytestream(ourProposal.getStreamId());
|
||||||
activate.setMode(null);
|
activate.setMode(null);
|
||||||
activate.setType(IQ.Type.set);
|
activate.setType(IQ.Type.set);
|
||||||
activate.setTo(nominated.candidate.getJid());
|
activate.setTo(nominated.candidate.getJid());
|
||||||
activate.setToActivate(jingleSession.getRemote());
|
activate.setToActivate(jingleSession.getRemote());
|
||||||
|
activate.setFrom(jingleSession.getLocal());
|
||||||
try {
|
try {
|
||||||
jingleSession.getConnection().createStanzaCollectorAndSend(activate).nextResultOrThrow();
|
jingleSession.getConnection().createStanzaCollectorAndSend(activate).nextResultOrThrow();
|
||||||
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
|
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
|
||||||
|
@ -300,6 +306,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGGER.log(Level.INFO, "Send candidate-activate.");
|
||||||
Jingle candidateActivate = transportManager().createCandidateActivated(
|
Jingle candidateActivate = transportManager().createCandidateActivated(
|
||||||
jingleSession.getRemote(), jingleSession.getInitiator(), jingleSession.getSessionId(),
|
jingleSession.getRemote(), jingleSession.getInitiator(), jingleSession.getSessionId(),
|
||||||
content.getSenders(), content.getCreator(), content.getName(), nominated.transport.getStreamId(),
|
content.getSenders(), content.getCreator(), content.getName(), nominated.transport.getStreamId(),
|
||||||
|
@ -312,14 +319,20 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket, !isExternalProxy);
|
LOGGER.log(Level.INFO, "Start transmission.");
|
||||||
|
Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket, !ourExternalProxy);
|
||||||
callback.onSessionInitiated(bs);
|
callback.onSessionInitiated(bs);
|
||||||
|
|
||||||
}
|
}
|
||||||
//Our choice
|
//Our choice
|
||||||
else {
|
else {
|
||||||
if (!nominated.candidate.getJid().asBareJid().equals(jingleSession.getRemote().asBareJid())) {
|
LOGGER.log(Level.INFO, "Our choice, so their candidate was used.");
|
||||||
Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket, !isExternalProxy);
|
if (!theirExternalProxy) {
|
||||||
|
LOGGER.log(Level.INFO, "Direct connection.");
|
||||||
|
Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket, !ourExternalProxy);
|
||||||
callback.onSessionInitiated(bs);
|
callback.onSessionInitiated(bs);
|
||||||
|
} else {
|
||||||
|
LOGGER.log(Level.INFO, "Our choice was their external proxy. wait for candidate-activate.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue