Example #1
0
  /**
   * @param channel
   * @param eventListener
   * @return
   * @throws IOException
   * @throws SshException
   */
  public synchronized boolean openChannel(Channel channel, ChannelEventListener eventListener)
      throws IOException {
    synchronized (activeChannels) {
      Long channelId = getChannelId();

      // Create the message
      SshMsgChannelOpen msg =
          new SshMsgChannelOpen(
              channel.getChannelType(),
              channelId.longValue(),
              channel.getLocalWindow().getWindowSpace(),
              channel.getLocalPacketSize(),
              channel.getChannelOpenData());

      // Send the message
      transport.sendMessage(msg, this);

      // Wait for the next message to confirm the open channel (or not)
      int[] messageIdFilter = new int[2];
      messageIdFilter[0] = SshMsgChannelOpenConfirmation.SSH_MSG_CHANNEL_OPEN_CONFIRMATION;
      messageIdFilter[1] = SshMsgChannelOpenFailure.SSH_MSG_CHANNEL_OPEN_FAILURE;

      try {
        SshMessage result = messageStore.getMessage(messageIdFilter);

        if (result.getMessageId()
            == SshMsgChannelOpenConfirmation.SSH_MSG_CHANNEL_OPEN_CONFIRMATION) {
          SshMsgChannelOpenConfirmation conf = (SshMsgChannelOpenConfirmation) result;
          activeChannels.put(channelId, channel);
          log.debug("Initiating channel");
          channel.init(
              this,
              channelId.longValue(),
              conf.getSenderChannel(),
              conf.getInitialWindowSize(),
              conf.getMaximumPacketSize(),
              eventListener);
          channel.open();
          log.info(
              "Channel "
                  + String.valueOf(channel.getLocalChannelId())
                  + " is open ["
                  + channel.getName()
                  + "]");

          return true;
        } else {
          // Make sure the channels state is closed
          channel.getState().setValue(ChannelState.CHANNEL_CLOSED);

          return false;
        }
      } catch (MessageStoreEOFException mse) {
        throw new IOException(mse.getMessage());
      } catch (InterruptedException ex) {
        throw new SshException(
            "The thread was interrupted whilst waiting for a connection protocol message");
      }
    }
  }
Example #2
0
  private void onMsgChannelExtendedData(SshMsgChannelExtendedData msg) throws IOException {
    Channel channel = getChannel(msg.getRecipientChannel());

    if (channel == null) {
      throw new IOException("Remote computer sent data for non existent channel");
    }

    channel.getLocalWindow().consumeWindowSpace(msg.getChannelData().length);
    channel.processChannelData(msg);
  }
Example #3
0
 /**
  * @param channel
  * @throws IOException
  */
 protected void sendChannelOpenConfirmation(Channel channel) throws IOException {
   SshMsgChannelOpenConfirmation msg =
       new SshMsgChannelOpenConfirmation(
           channel.getRemoteChannelId(),
           channel.getLocalChannelId(),
           channel.getLocalWindow().getWindowSpace(),
           channel.getLocalPacketSize(),
           channel.getChannelConfirmationData());
   transport.sendMessage(msg, this);
 }