mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
JS5B test works
This commit is contained in:
parent
1c72fdfa14
commit
aa8e8592af
4 changed files with 65 additions and 45 deletions
|
@ -79,6 +79,12 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
this(sid, Socks5Utils.createDigest(sid, initiator, responder), Bytestream.Mode.tcp, candidates);
|
this(sid, Socks5Utils.createDigest(sid, initiator, responder), Bytestream.Mode.tcp, candidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a JingleS5BTransport as response to another JingleS5BTransport proposal.
|
||||||
|
* @param content content which this transport will be child of.
|
||||||
|
* @param other other JingleS5BTransport proposal.
|
||||||
|
* @param candidates list of available JingleS5BTransportCandidates.
|
||||||
|
*/
|
||||||
public JingleS5BTransport(JingleContent content, JingleS5BTransport other, List<JingleTransportCandidate<?>> candidates) {
|
public JingleS5BTransport(JingleContent content, JingleS5BTransport other, List<JingleTransportCandidate<?>> candidates) {
|
||||||
this(other.getSid(),
|
this(other.getSid(),
|
||||||
Socks5Utils.createDigest(other.getSid(), content.getParent().getInitiator(), content.getParent().getResponder()),
|
Socks5Utils.createDigest(other.getSid(), content.getParent().getInitiator(), content.getParent().getResponder()),
|
||||||
|
@ -86,6 +92,13 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
setPeersProposal(other);
|
setPeersProposal(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new JingleS5BTransport.
|
||||||
|
* @param sid
|
||||||
|
* @param dstAddr
|
||||||
|
* @param mode
|
||||||
|
* @param candidates
|
||||||
|
*/
|
||||||
public JingleS5BTransport(String sid, String dstAddr, Bytestream.Mode mode, List<JingleTransportCandidate<?>> candidates) {
|
public JingleS5BTransport(String sid, String dstAddr, Bytestream.Mode mode, List<JingleTransportCandidate<?>> candidates) {
|
||||||
this.sid = sid;
|
this.sid = sid;
|
||||||
this.dstAddr = dstAddr;
|
this.dstAddr = dstAddr;
|
||||||
|
@ -97,8 +110,15 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy constructor.
|
||||||
|
* @param transport which will be copied.
|
||||||
|
*/
|
||||||
public JingleS5BTransport(JingleS5BTransport transport) {
|
public JingleS5BTransport(JingleS5BTransport transport) {
|
||||||
this(transport.sid, transport.dstAddr, transport.mode, transport.getCandidates());
|
this(transport.sid, transport.dstAddr, transport.mode, null);
|
||||||
|
for (JingleTransportCandidate<?> c : transport.getCandidates()) {
|
||||||
|
this.addCandidate(new JingleS5BTransportCandidate((JingleS5BTransportCandidate) c));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -196,7 +216,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.log(Level.INFO, "Ready.");
|
LOGGER.log(Level.INFO, (session.isInitiator() ? "Initiator" : "Responder") + " is ready.");
|
||||||
|
|
||||||
//Determine nominated candidate.
|
//Determine nominated candidate.
|
||||||
JingleS5BTransportCandidate nominated;
|
JingleS5BTransportCandidate nominated;
|
||||||
|
@ -219,7 +239,6 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
if (nominated == peers.getSelectedCandidate()) {
|
if (nominated == peers.getSelectedCandidate()) {
|
||||||
|
|
||||||
LOGGER.log(Level.INFO, "Their choice, so our proposed candidate is used.");
|
LOGGER.log(Level.INFO, "Their choice, so our proposed candidate is used.");
|
||||||
boolean isProxy = nominated.getType() == JingleS5BTransportCandidateElement.Type.proxy;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
nominated = nominated.connect(MAX_TIMEOUT, false);
|
nominated = nominated.connect(MAX_TIMEOUT, false);
|
||||||
|
@ -229,24 +248,9 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isProxy = nominated.getType() == JingleS5BTransportCandidateElement.Type.proxy;
|
||||||
|
|
||||||
if (isProxy) {
|
if (isProxy) {
|
||||||
|
|
||||||
LOGGER.log(Level.INFO, "Is external proxy. Activate it.");
|
|
||||||
Bytestream activate = new Bytestream(getSid());
|
|
||||||
activate.setMode(null);
|
|
||||||
activate.setType(IQ.Type.set);
|
|
||||||
activate.setTo(nominated.getStreamHost().getJID());
|
|
||||||
activate.setToActivate(getParent().getParent().getPeer());
|
|
||||||
activate.setFrom(getParent().getParent().getOurJid());
|
|
||||||
|
|
||||||
try {
|
|
||||||
getParent().getParent().getJingleManager().getConnection().createStanzaCollectorAndSend(activate).nextResultOrThrow();
|
|
||||||
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
|
|
||||||
LOGGER.log(Level.WARNING, "Could not activate proxy.", e);
|
|
||||||
callback.onTransportFailed(new S5BTransportException.ProxyError(e));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGGER.log(Level.INFO, "Send candidate-activate.");
|
LOGGER.log(Level.INFO, "Send candidate-activate.");
|
||||||
JingleElement candidateActivate = jingleS5BTransportManager.createCandidateActivated((JingleS5BTransport) nominated.getParent(), nominated);
|
JingleElement candidateActivate = jingleS5BTransportManager.createCandidateActivated((JingleS5BTransport) nominated.getParent(), nominated);
|
||||||
|
|
||||||
|
@ -279,6 +283,17 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void activateProxy(JingleS5BTransportCandidate candidate) throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, SmackException.NoResponseException {
|
||||||
|
LOGGER.log(Level.INFO, "Activate proxy: " + candidate.getCandidateId() + " " + candidate.getStreamHost().getAddress() + ":" + candidate.getStreamHost().getPort() + " " + candidate.getStreamHost().getJID());
|
||||||
|
Bytestream activate = new Bytestream(getSid());
|
||||||
|
activate.setMode(null);
|
||||||
|
activate.setType(IQ.Type.set);
|
||||||
|
activate.setTo(candidate.getStreamHost().getJID());
|
||||||
|
activate.setToActivate(getParent().getParent().getPeer());
|
||||||
|
activate.setFrom(getParent().getParent().getOurJid());
|
||||||
|
getParent().getParent().getJingleManager().getConnection().createStanzaCollectorAndSend(activate).nextResultOrThrow();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IQ handleTransportInfo(JingleContentTransportInfoElement info, JingleElement wrapping) {
|
public IQ handleTransportInfo(JingleContentTransportInfoElement info, JingleElement wrapping) {
|
||||||
switch (info.getElementName()) {
|
switch (info.getElementName()) {
|
||||||
|
@ -326,7 +341,6 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
Iterator<JingleTransportCandidate<?>> ourCandidates = getCandidates().iterator();
|
Iterator<JingleTransportCandidate<?>> ourCandidates = getCandidates().iterator();
|
||||||
while (ourCandidates.hasNext()) {
|
while (ourCandidates.hasNext()) {
|
||||||
JingleS5BTransportCandidate candidate = (JingleS5BTransportCandidate) ourCandidates.next();
|
JingleS5BTransportCandidate candidate = (JingleS5BTransportCandidate) ourCandidates.next();
|
||||||
LOGGER.log(Level.INFO, "CandidateID: " + candidate.getCandidateId() + " " + candidateId);
|
|
||||||
if (candidate.getCandidateId().equals(candidateId)) {
|
if (candidate.getCandidateId().equals(candidateId)) {
|
||||||
peers.setSelectedCandidate(candidate);
|
peers.setSelectedCandidate(candidate);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.jivesoftware.smackx.bytestreams.socks5.Socks5ClientForInitiator;
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||||
import org.jivesoftware.smackx.jingle.components.JingleContent;
|
import org.jivesoftware.smackx.jingle.components.JingleContent;
|
||||||
import org.jivesoftware.smackx.jingle.components.JingleSession;
|
import org.jivesoftware.smackx.jingle.components.JingleSession;
|
||||||
import org.jivesoftware.smackx.jingle.components.JingleTransport;
|
|
||||||
import org.jivesoftware.smackx.jingle.components.JingleTransportCandidate;
|
import org.jivesoftware.smackx.jingle.components.JingleTransportCandidate;
|
||||||
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportCandidateElement;
|
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportCandidateElement;
|
||||||
|
|
||||||
|
@ -56,6 +55,13 @@ public class JingleS5BTransportCandidate extends JingleTransportCandidate<Jingle
|
||||||
setPriority(priority);
|
setPriority(priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JingleS5BTransportCandidate(JingleS5BTransportCandidate other) {
|
||||||
|
this(other.candidateId,
|
||||||
|
other.getStreamHost(),
|
||||||
|
other.getPriority(),
|
||||||
|
other.type);
|
||||||
|
}
|
||||||
|
|
||||||
public static JingleS5BTransportCandidate fromElement(JingleS5BTransportCandidateElement element) {
|
public static JingleS5BTransportCandidate fromElement(JingleS5BTransportCandidateElement element) {
|
||||||
return new JingleS5BTransportCandidate(element.getCandidateId(), element.getStreamHost(), element.getPriority(), element.getType());
|
return new JingleS5BTransportCandidate(element.getCandidateId(), element.getStreamHost(), element.getPriority(), element.getType());
|
||||||
}
|
}
|
||||||
|
@ -81,19 +87,18 @@ public class JingleS5BTransportCandidate extends JingleTransportCandidate<Jingle
|
||||||
}
|
}
|
||||||
|
|
||||||
public JingleS5BTransportCandidate connect(int timeout, boolean peersProposal) throws InterruptedException, TimeoutException, SmackException, XMPPException, IOException {
|
public JingleS5BTransportCandidate connect(int timeout, boolean peersProposal) throws InterruptedException, TimeoutException, SmackException, XMPPException, IOException {
|
||||||
Socks5Client client;
|
JingleS5BTransport transport = (JingleS5BTransport) getParent();
|
||||||
|
|
||||||
|
Socks5Client client;
|
||||||
if (peersProposal) {
|
if (peersProposal) {
|
||||||
LOGGER.log(Level.INFO, "Connect to foreign candidate " + getCandidateId());
|
LOGGER.log(Level.INFO, "Connect to foreign candidate " + getCandidateId() + " using " + transport.getDstAddr());
|
||||||
client = new Socks5Client(getStreamHost(), ((JingleS5BTransport) getParent()).getDstAddr());
|
client = new Socks5Client(getStreamHost(), transport.getDstAddr());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOGGER.log(Level.INFO, "Connect to our candidate " + getCandidateId());
|
LOGGER.log(Level.INFO, "Connect to our candidate " + getCandidateId() + " using " + ((JingleS5BTransport) getParent()).getDstAddr());
|
||||||
JingleTransport<?> transport = getParent();
|
|
||||||
JingleContent content = transport.getParent();
|
JingleContent content = transport.getParent();
|
||||||
JingleSession session = content.getParent();
|
JingleSession session = content.getParent();
|
||||||
client = new Socks5ClientForInitiator(getStreamHost(), ((JingleS5BTransport) getParent()).getDstAddr(),
|
client = new Socks5ClientForInitiator(getStreamHost(), transport.getDstAddr(), session.getJingleManager().getConnection(), transport.getSid(), session.getPeer());
|
||||||
session.getJingleManager().getConnection(), ((JingleS5BTransport) getParent()).getSid(), getStreamHost().getJID());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.socket = client.getSocket(timeout);
|
this.socket = client.getSocket(timeout);
|
||||||
|
|
|
@ -106,7 +106,9 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
|
||||||
public JingleTransport<?> createTransport(JingleContent content, JingleTransport<?> peersTransport) {
|
public JingleTransport<?> createTransport(JingleContent content, JingleTransport<?> peersTransport) {
|
||||||
JingleS5BTransport transport = (JingleS5BTransport) peersTransport;
|
JingleS5BTransport transport = (JingleS5BTransport) peersTransport;
|
||||||
List<JingleTransportCandidate<?>> candidates = collectCandidates();
|
List<JingleTransportCandidate<?>> candidates = collectCandidates();
|
||||||
return new JingleS5BTransport(content, transport, candidates);
|
JingleS5BTransport mTransport = new JingleS5BTransport(content, transport, candidates);
|
||||||
|
mTransport.setPeersProposal(transport);
|
||||||
|
return mTransport;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -120,7 +122,7 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
|
||||||
//Local host
|
//Local host
|
||||||
if (JingleS5BTransportManager.isUseLocalCandidates()) {
|
if (JingleS5BTransportManager.isUseLocalCandidates()) {
|
||||||
for (Bytestream.StreamHost host : getLocalStreamHosts()) {
|
for (Bytestream.StreamHost host : getLocalStreamHosts()) {
|
||||||
candidates.add(new JingleS5BTransportCandidate(StringUtils.randomString(16), host, 100, JingleS5BTransportCandidateElement.Type.direct));
|
candidates.add(new JingleS5BTransportCandidate(StringUtils.randomString(16), host, 100, JingleS5BTransportCandidateElement.Type.proxy));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@ import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
||||||
import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint;
|
import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the JingleIBBTransport in a very basic case.
|
* Test the JingleIBBTransport in a very basic case.
|
||||||
|
@ -56,27 +55,27 @@ public class JingleTransportTest extends AbstractSmackIntegrationTest {
|
||||||
super(environment);
|
super(environment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
//@SmackIntegrationTest
|
||||||
public void setup() {
|
|
||||||
Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy();
|
|
||||||
if (!socks5Proxy.isRunning()) {
|
|
||||||
socks5Proxy.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SmackIntegrationTest
|
|
||||||
public void JingleIBBTest() throws Exception {
|
public void JingleIBBTest() throws Exception {
|
||||||
JingleIBBTransport sTransport = new JingleIBBTransport();
|
XMPPConnection sender = conOne;
|
||||||
final JingleIBBTransport rTransport = new JingleIBBTransport(sTransport.getSid(), sTransport.getBlockSize());
|
XMPPConnection receiver = conTwo;
|
||||||
|
|
||||||
JingleSession sSession = new JingleSession(JingleManager.getInstanceFor(conOne), conOne.getUser().asFullJidOrThrow(), conTwo.getUser().asFullJidOrThrow(), Role.initiator, "session");
|
JingleIBBTransport sTransport = new JingleIBBTransport();
|
||||||
JingleSession rSession = new JingleSession(JingleManager.getInstanceFor(conTwo), conOne.getUser().asFullJidOrThrow(), conTwo.getUser().asFullJidOrThrow(), Role.responder, "session");
|
JingleIBBTransport rTransport = new JingleIBBTransport(sTransport.getSid(), sTransport.getBlockSize());
|
||||||
|
|
||||||
|
JingleSession sSession = new JingleSession(JingleManager.getInstanceFor(sender), sender.getUser().asFullJidOrThrow(), receiver.getUser().asFullJidOrThrow(), Role.initiator, "session");
|
||||||
|
JingleSession rSession = new JingleSession(JingleManager.getInstanceFor(receiver), sender.getUser().asFullJidOrThrow(), receiver.getUser().asFullJidOrThrow(), Role.responder, "session");
|
||||||
|
|
||||||
basicTransportTest(sSession, rSession, sTransport, rTransport);
|
basicTransportTest(sSession, rSession, sTransport, rTransport);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmackIntegrationTest
|
@SmackIntegrationTest
|
||||||
public void JingleS5BTest() throws Exception {
|
public void JingleS5BTest() throws Exception {
|
||||||
|
Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy();
|
||||||
|
if (!socks5Proxy.isRunning()) {
|
||||||
|
socks5Proxy.start();
|
||||||
|
}
|
||||||
|
|
||||||
XMPPConnection sender = conOne;
|
XMPPConnection sender = conOne;
|
||||||
XMPPConnection receiver = conTwo;
|
XMPPConnection receiver = conTwo;
|
||||||
JingleSession sSession = new JingleSession(JingleManager.getInstanceFor(sender), sender.getUser().asFullJidOrThrow(), receiver.getUser().asFullJidOrThrow(), Role.initiator, "session");
|
JingleSession sSession = new JingleSession(JingleManager.getInstanceFor(sender), sender.getUser().asFullJidOrThrow(), receiver.getUser().asFullJidOrThrow(), Role.initiator, "session");
|
||||||
|
|
Loading…
Reference in a new issue