Package org.apache.sshd.common.util

Examples of org.apache.sshd.common.util.Buffer


        byte[] data = reply.getData();
        int offset = reply.getOffset();
        int length = reply.getLength();
        boolean eof = reply.isEof();

        Buffer buffer = new Buffer(length + 5);
        buffer.putByte((byte) SSH_FXP_DATA);
        buffer.putInt(id);
        buffer.putBytes(data, offset, length);
        if (session.getVersion() >= 6 && eof) {
            buffer.putBoolean(eof);
        }
        return buffer;
    }
View Full Code Here


        int id = reply.getId();
        int substatus = reply.getSubstatus();
        String msg = reply.getMsg();
        String lang = reply.getLang();

        Buffer buffer = new Buffer();
        buffer.putByte((byte) SSH_FXP_STATUS);
        buffer.putInt(id);
        buffer.putInt(mapToVersion(substatus));
        buffer.putString(msg);
        buffer.putString(lang);
        return buffer;
    }
View Full Code Here

        if (closeFuture.isClosed()) {
            throw new SshException("Session has been closed");
        }
        openFuture = new DefaultOpenFuture(lock);
        log.info("Send SSH_MSG_CHANNEL_OPEN on channel {}", this);
        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN);
        buffer.putString(type);
        buffer.putInt(id);
        buffer.putInt(localWindow.getSize());
        buffer.putInt(localWindow.getPacketSize());
        buffer.putString(dst.getAddress().getHostAddress());
        buffer.putInt(dst.getPort());
        buffer.putString(src.getAddress().getHostAddress());
        buffer.putInt(src.getPort());
        writePacket(buffer);
        return openFuture;
    }
View Full Code Here

        super.handleEof();
//        close(true);
    }

    protected void doWriteData(byte[] data, int off, int len) throws IOException {
        client.messageReceived(new Buffer(data, off, len));
    }
View Full Code Here

        return CloseableUtils.sequential(serverSession, super.getInnerCloseable());
    }

    protected synchronized void doWriteData(byte[] data, int off, int len) throws IOException {
        // Make sure we copy the data as the incoming buffer may be reused
        Buffer buf = new Buffer(data, off, len);
        buf = new Buffer(buf.getCompactData());
        localWindow.consumeAndCheck(len);
        serverSession.write(buf);
    }
View Full Code Here

        }
        invertedIn = new ChannelOutputStream(this, remoteWindow, log, SshConstants.SSH_MSG_CHANNEL_DATA);
    }

    protected void doWriteData(byte[] data, int off, int len) throws IOException {
        Buffer message = null;
        synchronized (receiveBuffer) {
            receiveBuffer.putBuffer(new Buffer(data, off, len));
            if (receiveBuffer.available() >= 4) {
                off = receiveBuffer.rpos();
                len = receiveBuffer.getInt();
                receiveBuffer.rpos(off);
                if (receiveBuffer.available() >= 4 + len) {
                    message = new Buffer(receiveBuffer.getBytes());
                    receiveBuffer.compact();
                }
            }
        }
        if (message != null) {
View Full Code Here

    }

    protected synchronized void doWriteIfPossible(boolean resume) {
        final IoWriteFutureImpl future = pendingWrite.get();
        if (future != null) {
            final Buffer buffer = future.buffer;
            final int total = buffer.available();
            if (total > 0) {
                final int length = Math.min(Math.min(channel.getRemoteWindow().getSize(), total), channel.getRemoteWindow().getPacketSize());
                if (length > 0) {
                    if (resume) {
                        log.debug("Resuming write due to more space available in the remote window");
                    }
                    Buffer buf = channel.getSession().createBuffer(cmd, length + 12);
                    buf.putInt(channel.getRecipient());
                    if (cmd == SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA) {
                        buf.putInt(1);
                    }
                    buf.putInt(length);
                    buf.putRawBytes(buffer.array(), buffer.rpos(), length);
                    buffer.rpos(buffer.rpos() + length);
                    channel.getRemoteWindow().consume(length);
                    try {
                        channel.getSession().writePacket(buf).addListener(new SshFutureListener<org.apache.sshd.common.io.IoWriteFuture>() {
                            public void operationComplete(org.apache.sshd.common.io.IoWriteFuture f) {
View Full Code Here

        }
    }

    public void messageReceived(IoSession session, Readable message) throws Exception {
        ChannelForwardedX11 channel = (ChannelForwardedX11) session.getAttribute(ChannelForwardedX11.class);
        Buffer buffer = new Buffer();
        buffer.putBuffer(message);
        channel.getInvertedIn().write(buffer.array(), buffer.rpos(), buffer.available());
        channel.getInvertedIn().flush();
    }
View Full Code Here

                    log.debug("Service " + service + " rejected", e);
                    disconnect(SshConstants.SSH2_DISCONNECT_SERVICE_NOT_AVAILABLE, "Bad service request: " + service);
                    break;
                }
                log.debug("Accepted service {}", service);
                Buffer response = createBuffer(SshConstants.SSH_MSG_SERVICE_ACCEPT);
                response.putString(service);
                writePacket(response);
                break;
            case SSH_MSG_SERVICE_ACCEPT:
                log.debug("Received SSH_MSG_SERVICE_ACCEPT");
                if (kexState.get() != KEX_STATE_DONE) {
View Full Code Here

            }
        }
    }

    public synchronized SshdSocketAddress startRemotePortForwarding(SshdSocketAddress remote, SshdSocketAddress local) throws IOException {
        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_GLOBAL_REQUEST);
        buffer.putString("tcpip-forward");
        buffer.putBoolean(true);
        buffer.putString(remote.getHostName());
        buffer.putInt(remote.getPort());
        Buffer result = session.request(buffer);
        if (result == null) {
            throw new SshException("Tcpip forwarding request denied by server");
        }
        int port = remote.getPort() == 0 ? result.getInt() : remote.getPort();
        // TODO: Is it really safe to only store the local address after the request ?
        remoteToLocal.put(port, local);
        return new SshdSocketAddress(remote.getHostName(), port);
    }
View Full Code Here

TOP

Related Classes of org.apache.sshd.common.util.Buffer

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.