Search in sources :

Example 1 with JingleS5BTransportCandidate

use of org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportCandidate in project Smack by igniterealtime.

the class JingleS5BTransportSession method createTransport.

public JingleS5BTransport createTransport(String sid, Bytestream.Mode mode) {
    JingleS5BTransport.Builder jb = JingleS5BTransport.getBuilder().setStreamId(sid).setMode(mode).setDestinationAddress(Socks5Utils.createDigest(sid, jingleSession.getLocal(), jingleSession.getRemote()));
    // Local host
    if (JingleS5BTransportManager.isUseLocalCandidates()) {
        for (Bytestream.StreamHost host : transportManager().getLocalStreamHosts()) {
            jb.addTransportCandidate(new JingleS5BTransportCandidate(host, 100, JingleS5BTransportCandidate.Type.direct));
        }
    }
    List<Bytestream.StreamHost> remoteHosts = Collections.emptyList();
    if (JingleS5BTransportManager.isUseExternalCandidates()) {
        try {
            remoteHosts = transportManager().getAvailableStreamHosts();
        } catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
            LOGGER.log(Level.WARNING, "Could not determine available StreamHosts.", e);
        }
    }
    for (Bytestream.StreamHost host : remoteHosts) {
        jb.addTransportCandidate(new JingleS5BTransportCandidate(host, 0, JingleS5BTransportCandidate.Type.proxy));
    }
    return jb.build();
}
Also used : Bytestream(org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream) JingleS5BTransport(org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport) JingleS5BTransportCandidate(org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportCandidate)

Example 2 with JingleS5BTransportCandidate

use of org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportCandidate in project Smack by igniterealtime.

the class JingleS5BTransportTest method transportCandidateIllegalPortTest.

@Test
public void transportCandidateIllegalPortTest() throws XmppStringprepException, UnknownHostException {
    FullJid jid = JidCreate.fullFrom("test@test.test/test");
    assertThrows(IllegalArgumentException.class, () -> {
        new JingleS5BTransportCandidate("cid", "host", jid, -5555, 30, JingleS5BTransportCandidate.Type.proxy);
    });
}
Also used : FullJid(org.jxmpp.jid.FullJid) JingleS5BTransportCandidate(org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportCandidate) Test(org.junit.jupiter.api.Test)

Example 3 with JingleS5BTransportCandidate

use of org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportCandidate in project Smack by igniterealtime.

the class JingleS5BTransportTest method transportCandidateIllegalPriorityTest.

@Test
public void transportCandidateIllegalPriorityTest() throws XmppStringprepException, UnknownHostException {
    FullJid jid = JidCreate.fullFrom("test@test.test/test");
    assertThrows(IllegalArgumentException.class, () -> {
        new JingleS5BTransportCandidate("cid", "localhost", jid, 5555, -30, JingleS5BTransportCandidate.Type.proxy);
    });
}
Also used : FullJid(org.jxmpp.jid.FullJid) JingleS5BTransportCandidate(org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportCandidate) Test(org.junit.jupiter.api.Test)

Example 4 with JingleS5BTransportCandidate

use of org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportCandidate in project Smack by igniterealtime.

the class JingleS5BTransportTest method candidateFromStreamHostTest.

@Test
public void candidateFromStreamHostTest() throws XmppStringprepException, UnknownHostException {
    FullJid jid = JidCreate.fullFrom("test@test.test/test");
    String host = "localhost";
    int port = 1234;
    Bytestream.StreamHost streamHost = new Bytestream.StreamHost(jid, host, port);
    JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(streamHost, 2000, JingleS5BTransportCandidate.Type.direct);
    assertEquals(2000, candidate.getPriority());
    assertEquals(jid, candidate.getJid());
    assertEquals(host, candidate.getHost().toString());
    assertEquals(port, candidate.getPort());
    assertEquals(streamHost.toXML().toString(), candidate.getStreamHost().toXML().toString());
}
Also used : Bytestream(org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream) FullJid(org.jxmpp.jid.FullJid) JingleS5BTransportCandidate(org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportCandidate) Test(org.junit.jupiter.api.Test)

Example 5 with JingleS5BTransportCandidate

use of org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportCandidate in project Smack by igniterealtime.

the class JingleS5BTransportTest method candidatesProviderTest.

@Test
public void candidatesProviderTest() throws Exception {
    String xml = "<transport " + "xmlns='urn:xmpp:jingle:transports:s5b:1' " + "dstaddr='972b7bf47291ca609517f67f86b5081086052dad' " + "mode='tcp' " + "sid='vj3hs98y'>" + "<candidate " + "cid='hft54dqy' " + "host='192.168.4.1' " + "jid='romeo@montague.lit/orchard' " + "port='5086' " + "priority='8257636' " + "type='direct'/>" + "<candidate " + "cid='hutr46fe' " + "host='24.24.24.1' " + "jid='romeo@montague.lit/orchard' " + "port='5087' " + "priority='8258636' " + "type='direct'/>" + "<candidate " + "cid='xmdh4b7i' " + "host='123.456.7.8' " + "jid='streamer.shakespeare.lit' " + "port='7625' " + "priority='7878787' " + "type='proxy'/>" + "</transport>";
    JingleS5BTransport transport = new JingleS5BTransportProvider().parse(TestUtils.getParser(xml));
    assertEquals("972b7bf47291ca609517f67f86b5081086052dad", transport.getDestinationAddress());
    assertEquals("vj3hs98y", transport.getStreamId());
    assertEquals(Bytestream.Mode.tcp, transport.getMode());
    assertEquals(3, transport.getCandidates().size());
    assertTrue(transport.hasCandidate("hft54dqy"));
    assertFalse(transport.hasCandidate("invalidId"));
    JingleS5BTransportCandidate candidate1 = (JingleS5BTransportCandidate) transport.getCandidates().get(0);
    assertEquals(candidate1, transport.getCandidate("hft54dqy"));
    assertNotNull(candidate1.getStreamHost());
    assertEquals(JingleS5BTransportCandidate.Type.direct.getWeight(), candidate1.getType().getWeight());
    assertEquals("hft54dqy", candidate1.getCandidateId());
    assertEquals("192.168.4.1", candidate1.getHost().toString());
    assertEquals(JidCreate.from("romeo@montague.lit/orchard"), candidate1.getJid());
    assertEquals(5086, candidate1.getPort());
    assertEquals(8257636, candidate1.getPriority());
    assertEquals(JingleS5BTransportCandidate.Type.direct, candidate1.getType());
    JingleS5BTransportCandidate candidate2 = (JingleS5BTransportCandidate) transport.getCandidates().get(1);
    assertEquals("hutr46fe", candidate2.getCandidateId());
    assertEquals("24.24.24.1", candidate2.getHost().toString());
    assertEquals(JidCreate.from("romeo@montague.lit/orchard"), candidate2.getJid());
    assertEquals(5087, candidate2.getPort());
    assertEquals(8258636, candidate2.getPriority());
    assertEquals(JingleS5BTransportCandidate.Type.direct, candidate2.getType());
    JingleS5BTransportCandidate candidate3 = (JingleS5BTransportCandidate) transport.getCandidates().get(2);
    assertEquals("xmdh4b7i", candidate3.getCandidateId());
    assertEquals("123.456.7.8", candidate3.getHost().toString());
    assertEquals(JidCreate.domainBareFrom("streamer.shakespeare.lit"), candidate3.getJid());
    assertEquals(7625, candidate3.getPort());
    assertEquals(7878787, candidate3.getPriority());
    assertEquals(JingleS5BTransportCandidate.Type.proxy, candidate3.getType());
    assertEquals(xml, transport.toXML().toString());
}
Also used : JingleS5BTransport(org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport) JingleS5BTransportProvider(org.jivesoftware.smackx.jingle.transports.jingle_s5b.provider.JingleS5BTransportProvider) JingleS5BTransportCandidate(org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportCandidate) Test(org.junit.jupiter.api.Test)

Aggregations

JingleS5BTransportCandidate (org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransportCandidate)5 Test (org.junit.jupiter.api.Test)4 FullJid (org.jxmpp.jid.FullJid)3 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)2 JingleS5BTransport (org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport)2 JingleS5BTransportProvider (org.jivesoftware.smackx.jingle.transports.jingle_s5b.provider.JingleS5BTransportProvider)1