Search in sources :

Example 31 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project Smack by igniterealtime.

the class Socks5ByteStreamTest method testRespondWithErrorOnSocks5BytestreamRequest.

/**
 * Target should respond with not-acceptable error if no listeners for incoming Socks5
 * bytestream requests are registered.
 *
 * @throws XMPPException should not happen
 */
public void testRespondWithErrorOnSocks5BytestreamRequest() throws XMPPException {
    XMPPConnection targetConnection = getConnection(0);
    XMPPConnection initiatorConnection = getConnection(1);
    Bytestream bytestreamInitiation = Socks5PacketUtils.createBytestreamInitiation(initiatorConnection.getUser(), targetConnection.getUser(), "session_id");
    bytestreamInitiation.addStreamHost("proxy.localhost", "127.0.0.1", 7777);
    StanzaCollector collector = initiatorConnection.createStanzaCollector(new PacketIDFilter(bytestreamInitiation.getStanzaId()));
    initiatorConnection.sendStanza(bytestreamInitiation);
    Packet result = collector.nextResult();
    assertNotNull(result.getError());
    assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) Bytestream(org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream) XMPPConnection(org.jivesoftware.smack.XMPPConnection) StanzaCollector(org.jivesoftware.smack.StanzaCollector) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 32 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project Smack by igniterealtime.

the class CompressionTest method testSuccessCompression.

/**
 * Test that stream compression works fine. It is assumed that the server supports and has
 * stream compression enabled.
 */
public void testSuccessCompression() throws XMPPException {
    // Create the configuration for this new connection
    ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());
    config.setCompressionEnabled(true);
    config.setSASLAuthenticationEnabled(true);
    XMPPTCPConnection connection = new XMPPConnection(config);
    connection.connect();
    // Login with the test account
    connection.login("user0", "user0");
    assertTrue("XMPPConnection is not using stream compression", connection.isUsingCompression());
    // Request the version of the server
    Version version = new Version();
    version.setType(IQ.Type.get);
    version.setTo(getXMPPServiceDomain());
    // Create a packet collector to listen for a response.
    StanzaCollector collector = connection.createStanzaCollector(new PacketIDFilter(version.getStanzaId()));
    connection.sendStanza(version);
    // Wait up to 5 seconds for a result.
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Close the collector
    collector.cancel();
    assertNotNull("No reply was received from the server", result);
    assertEquals("Incorrect IQ type from server", IQ.Type.result, result.getType());
    // Close connection
    connection.disconnect();
}
Also used : Version(org.jivesoftware.smackx.packet.Version) IQ(org.jivesoftware.smack.packet.IQ) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 33 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project Smack by igniterealtime.

the class InBandBytestreamTest method testRespondWithErrorOnInBandBytestreamRequest.

/**
 * Target should respond with not-acceptable error if no listeners for incoming In-Band
 * Bytestream requests are registered.
 *
 * @throws XMPPException should not happen
 */
public void testRespondWithErrorOnInBandBytestreamRequest() throws XMPPException {
    XMPPConnection targetConnection = getConnection(0);
    XMPPConnection initiatorConnection = getConnection(1);
    Open open = new Open("sessionID", 1024);
    open.setFrom(initiatorConnection.getUser());
    open.setTo(targetConnection.getUser());
    StanzaCollector collector = initiatorConnection.createStanzaCollector(new PacketIDFilter(open.getStanzaId()));
    initiatorConnection.sendStanza(open);
    Packet result = collector.nextResult();
    assertNotNull(result.getError());
    assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) XMPPConnection(org.jivesoftware.smack.XMPPConnection) StanzaCollector(org.jivesoftware.smack.StanzaCollector) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter) Open(org.jivesoftware.smackx.bytestreams.ibb.packet.Open)

Example 34 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project Openfire by igniterealtime.

the class ThrottleTestWriter method main.

/**
 * Starts the throttle test write client.
 *
 * @param args application arguments.
 */
public static void main(String[] args) {
    if (args.length != 3) {
        System.out.println("Usage: java ThrottleTestWriter [server] [username] [password]");
        System.exit(0);
    }
    String server = args[0];
    String username = args[1];
    String password = args[2];
    try {
        // Connect to the server, without TLS encryption.
        ConnectionConfiguration config = new ConnectionConfiguration(server);
        config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
        final XMPPConnection con = new XMPPConnection(config);
        System.out.print("Connecting to " + server + "... ");
        con.connect();
        con.login(username, password, "writer");
        System.out.print("success.");
        System.out.println("");
        // Get the "real" server address.
        server = con.getServiceName();
        String writerAddress = username + "@" + server + "/writer";
        final String readerAddress = username + "@" + server + "/reader";
        System.out.println("Registered as " + writerAddress);
        // Look for the reader process.
        System.out.print("Looking for " + readerAddress + "...");
        while (true) {
            IQ testIQ = new Time();
            testIQ.setType(IQ.Type.GET);
            testIQ.setTo(readerAddress);
            PacketCollector collector = con.createPacketCollector(new PacketIDFilter(testIQ.getPacketID()));
            con.sendPacket(testIQ);
            // Wait 5 seconds.
            long start = System.currentTimeMillis();
            Packet result = collector.nextResult(5000);
            collector.cancel();
            // If we got a result, continue.
            if (result != null && result.getError() == null) {
                System.out.println(" found reader. Starting packet flood.");
                break;
            }
            System.out.print(".");
            long end = System.currentTimeMillis();
            if (end - start < 5000) {
                try {
                    Thread.sleep(5000 - (end - start));
                } catch (Exception e) {
                // ignore.
                }
            }
        }
        // Create a process to log how many packets we're writing out.
        Runnable statsRunnable = new Runnable() {

            public void run() {
                while (!done) {
                    try {
                        Thread.sleep(5000);
                    } catch (Exception e) {
                    /* ignore */
                    }
                    int count = packetCount.getAndSet(0);
                    System.out.println("Packets per second: " + (count / 5));
                }
            }
        };
        Thread statsThread = new Thread(statsRunnable);
        statsThread.setDaemon(true);
        statsThread.start();
        // Now start flooding packets.
        Message testMessage = new Message(readerAddress);
        testMessage.setBody("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
        while (!done) {
            con.sendPacket(testMessage);
            packetCount.getAndIncrement();
        }
    } catch (Exception e) {
        System.out.println("\nError: " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) Message(org.jivesoftware.smack.packet.Message) IQ(org.jivesoftware.smack.packet.IQ) Time(org.jivesoftware.smackx.packet.Time) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ConnectionConfiguration(org.jivesoftware.smack.ConnectionConfiguration) PacketCollector(org.jivesoftware.smack.PacketCollector) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 35 with PacketIDFilter

use of org.jivesoftware.smack.filter.PacketIDFilter in project Openfire by igniterealtime.

the class SmackServiceNode method searchDiscoItems.

private static void searchDiscoItems(final XMPPConnection xmppConnection, final int maxEntries, final String startPoint, final MappedNodes mappedNodes, final int maxDepth, final int maxSearchNodes, final String protocol, final ConcurrentHashMap<String, String> visited) {
    final DiscoverItems items = new DiscoverItems();
    items.setTo(startPoint);
    PacketCollector collector = xmppConnection.createPacketCollector(new PacketIDFilter(items.getPacketID()));
    xmppConnection.sendPacket(items);
    DiscoverItems result = (DiscoverItems) collector.nextResult(Math.round(SmackConfiguration.getPacketReplyTimeout() * 1.5));
    if (result != null) {
        final Iterator<DiscoverItems.Item> i = result.getItems();
        for (DiscoverItems.Item item = i.hasNext() ? i.next() : null; item != null; item = i.hasNext() ? i.next() : null) {
            deepSearch(xmppConnection, maxEntries, item.getEntityID(), mappedNodes, maxDepth, maxSearchNodes, protocol, visited);
        }
    }
    collector.cancel();
}
Also used : DiscoverItems(org.jivesoftware.smackx.packet.DiscoverItems) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Aggregations

PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)66 IQ (org.jivesoftware.smack.packet.IQ)38 PacketCollector (org.jivesoftware.smack.PacketCollector)36 XMPPException (org.jivesoftware.smack.XMPPException)34 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)22 Packet (org.jivesoftware.smack.packet.Packet)10 AndFilter (org.jivesoftware.smack.filter.AndFilter)7 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)6 Registration (org.jivesoftware.smack.packet.Registration)6 MUCAdmin (org.jivesoftware.smackx.packet.MUCAdmin)6 MUCOwner (org.jivesoftware.smackx.packet.MUCOwner)6 RosterPacket (org.jivesoftware.smack.packet.RosterPacket)4 ArrayList (java.util.ArrayList)3 XMPPConnection (org.jivesoftware.smack.XMPPConnection)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 HashMap (java.util.HashMap)2 StanzaCollector (org.jivesoftware.smack.StanzaCollector)2 StanzaListener (org.jivesoftware.smack.StanzaListener)2 Authentication (org.jivesoftware.smack.packet.Authentication)2