Package org.jivesoftware.smackx.bytestreams.socks5

Examples of org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession


        // get SOCKS5 Bytestream manager for connection
        Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);

        // build SOCKS5 Bytestream request with the bytestream initialization
        Socks5BytestreamRequest byteStreamRequest = new Socks5BytestreamRequest(byteStreamManager,
                        bytestreamInitialization);

        // accept the stream (this is the call that is tested here)
        InputStream inputStream = byteStreamRequest.accept().getInputStream();

        // create digest to get the socket opened by target
        String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID);

        // test stream by sending some data
View Full Code Here


        Socks5BytestreamListener incomingByteStreamListener = new Socks5BytestreamListener() {

            public void incomingBytestreamRequest(Socks5BytestreamRequest request) {
                InputStream inputStream;
                try {
                    Socks5BytestreamSession session = request.accept();
                    inputStream = session.getInputStream();
                    byte[] receivedData = new byte[3];
                    inputStream.read(receivedData);
                    queue.put(receivedData);
                }
                catch (Exception e) {
                    fail(e.getMessage());
                }
            }

        };
        targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);

        Socks5BytestreamManager initiatorByteStreamManager = Socks5BytestreamManager.getBytestreamManager(initiatorConnection);

        Socks5BytestreamSession session = initiatorByteStreamManager.establishSession(
                        targetConnection.getUser());
        OutputStream outputStream = session.getOutputStream();
       
        assertTrue(session.isDirect());

        // verify stream
        outputStream.write(data);
        outputStream.flush();
        outputStream.close();
View Full Code Here

        Socks5BytestreamListener incomingByteStreamListener = new Socks5BytestreamListener() {

            public void incomingBytestreamRequest(Socks5BytestreamRequest request) {
                InputStream inputStream;
                try {
                    Socks5BytestreamSession session = request.accept();
                    inputStream = session.getInputStream();
                    byte[] receivedData = new byte[3];
                    inputStream.read(receivedData);
                    queue.put(receivedData);
                }
                catch (Exception e) {
                    fail(e.getMessage());
                }
            }

        };
        targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);

        Socks5BytestreamManager initiatorByteStreamManager = Socks5BytestreamManager.getBytestreamManager(initiatorConnection);

        Socks5BytestreamSession session = initiatorByteStreamManager.establishSession(
                        targetConnection.getUser());
        OutputStream outputStream = session.getOutputStream();

        assertTrue(session.isMediated());

        // verify stream
        outputStream.write(data);
        outputStream.flush();
        outputStream.close();
View Full Code Here

        Socks5BytestreamListener incomingByteStreamListener = new Socks5BytestreamListener() {

            public void incomingBytestreamRequest(Socks5BytestreamRequest request) {
                try {
                    Socks5BytestreamSession session = request.accept();
                    OutputStream outputStream = session.getOutputStream();
                    outputStream.write(data);
                    outputStream.flush();
                    InputStream inputStream = session.getInputStream();
                    byte[] receivedData = new byte[3];
                    inputStream.read(receivedData);
                    queue.put(receivedData);
                    session.close();
                }
                catch (Exception e) {
                    fail(e.getMessage());
                }
            }

        };
        targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);

        Socks5BytestreamManager initiatorByteStreamManager = Socks5BytestreamManager.getBytestreamManager(initiatorConnection);

        Socks5BytestreamSession session = initiatorByteStreamManager.establishSession(targetConnection.getUser());
       
        assertTrue(session.isMediated());
       
        // verify stream
        final byte[] receivedData = new byte[3];
        final InputStream inputStream = session.getInputStream();

        FutureTask<Integer> futureTask = new FutureTask<Integer>(new Callable<Integer>() {

            public Integer call() throws Exception {
                return inputStream.read(receivedData);
            }
        });
        Thread executor = new Thread(futureTask);
        executor.start();

        try {
            futureTask.get(2000, TimeUnit.MILLISECONDS);
        }
        catch (TimeoutException e) {
            // reset default configuration
            SmackConfiguration.setLocalSocks5ProxyEnabled(true);
            Socks5Proxy.getSocks5Proxy().start();

            fail("Couldn't send data from target to inititator");
        }

        assertEquals("sent data not equal to received data", data, receivedData);

        OutputStream outputStream = session.getOutputStream();

        outputStream.write(data);
        outputStream.flush();
        outputStream.close();

        assertEquals("received data not equal to sent data", data, queue.take());

        session.close();

        // reset default configuration
        SmackConfiguration.setLocalSocks5ProxyEnabled(true);
        Socks5Proxy.getSocks5Proxy().start();
View Full Code Here

        Socks5BytestreamSession inSession, Socks5BytestreamSession outSession,
        boolean preferInSession) throws IOException {

        String msg = prefix() + "response connection is mediated, too, ";

        Socks5BytestreamSession session = preferInSession ? inSession
            : outSession;

        // if preferable session did not work, try the other
        if (session == null) {
            preferInSession = !preferInSession;
View Full Code Here

        String peer = request.getFrom();
        log.debug(prefix() + "receiving response connection from " + peer
            + verboseLocalProxyInfo());

        Socks5BytestreamSession inSession = (Socks5BytestreamSession) request
            .accept();

        // get running connect
        Exchanger<Socks5BytestreamSession> exchanger = runningConnects
            .get(peer);
View Full Code Here

        log.debug(prefix() + "receiving request from " + peer
            + verboseLocalProxyInfo());

        // start to establish response
        Future<Socks5BytestreamSession> responseFuture = futureToEstablishResponseSession(peer);
        Socks5BytestreamSession inSession = null;

        try {

            inSession = (Socks5BytestreamSession) request.accept();

            if (inSession.isDirect()) {
                waitToCloseResponse(responseFuture);
                return new BinaryChannel(inSession,
                    NetTransferMode.SOCKS5_DIRECT);
            } else {
                log.debug(prefix() + "incoming connection is mediated.");
            }

        } catch (Exception e) {
            log.warn(prefix()
                + "Couldn't accept request but still trying to establish a response connection: "
                + e.getMessage());
        }

        Socks5BytestreamSession outSession = null;

        try {

            outSession = responseFuture.get();

            if (outSession.isDirect()) {
                log.debug(prefix()
                    + "newly established session is direct! Discarding the other.");
                Utils.closeQuietly(inSession);
                return new BinaryChannel(outSession,
                    NetTransferMode.SOCKS5_DIRECT);
View Full Code Here

            + verboseLocalProxyInfo());

        try {

            Exception exception = null;
            Socks5BytestreamSession outSession = null;
            // Do we get a working connection?
            try {

                outSession = (Socks5BytestreamSession) manager
                    .establishSession(peer);

                if (outSession.isDirect())
                    return new BinaryChannel(outSession,
                        NetTransferMode.SOCKS5_DIRECT);

                log.debug(prefix()
                    + "session is mediated. Waiting for peer to connect ...");

                progress
                    .subTask("SOCKS5 stream is mediated. Waiting for peer to connect ...");
                progress.worked(5);

            } catch (IOException e) {
                exception = e;
            } catch (XMPPException e) {
                exception = e;
            } catch (Exception e) {
                /*
                 * catch any possible RuntimeException because we must wait for
                 * the peer that may attempt to connect
                 */
                exception = e;
            }

            if (exception != null) {

                log.warn(prefix() + "could not connect to " + peer
                    + " because: " + exception.getMessage()
                    + ". Waiting for peer to connect ...");

                progress.subTask("Could not connect to " + peer
                    + ". Waiting for peer to connect ...");
                progress.worked(5);
            }

            Socks5BytestreamSession inSession = null;

            // else wait for request
            try {
                inSession = exchanger.exchange(null,
                    WAIT_FOR_RESPONSE_CONNECTION, TimeUnit.MILLISECONDS);

                if (inSession.isDirect()) {
                    log.debug(prefix()
                        + "response connection is direct! Discarding the other.");
                    Utils.closeQuietly(outSession);
                    return new BinaryChannel(inSession,
                        NetTransferMode.SOCKS5_DIRECT);
View Full Code Here

        // build SOCKS5 Bytestream request
        Socks5BytestreamRequest request = new ByteStreamRequest(this.manager,
                        (Bytestream) streamInitiation);

        // always accept the request
        Socks5BytestreamSession session = request.accept();

        // test input stream
        try {
            PushbackInputStream stream = new PushbackInputStream(session.getInputStream());
            int firstByte = stream.read();
            stream.unread(firstByte);
            return stream;
        }
        catch (IOException e) {
View Full Code Here

            @Override
            public void run() {
                StreamHost streamHost = new StreamHost(proxyJID, serverAddress);
                streamHost.setPort(serverPort);

                Socks5Client socks5Client = new Socks5Client(streamHost, digest);

                try {

                    socks5Client.getSocket(10000);

                    fail("exception should be thrown");
                }
                catch (XMPPException e) {
                    assertTrue(e.getMessage().contains(
View Full Code Here

TOP

Related Classes of org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.