case Forwarded: address = service.getTcpipForwarder().getForwardedPort(portToConnect); break;
}
final ForwardingFilter filter = getSession().getFactoryManager().getTcpipForwardingFilter();
if (address == null || filter == null || !filter.canConnect(address, getSession())) {
super.close(true);
f.setException(new OpenChannelException(SshConstants.SSH_OPEN_ADMINISTRATIVELY_PROHIBITED, "Connection denied"));
return f;
}
// TODO: revisit for better threading. Use async io ?
out = new ChannelOutputStream(this, remoteWindow, log, SshConstants.SSH_MSG_CHANNEL_DATA);
IoHandler handler = new IoHandler() {
public void messageReceived(IoSession session, Readable message) throws Exception {
if (state.get() != OPENED) {
log.debug("Ignoring write to channel {} in CLOSING state", id);
} else {
Buffer buffer = new Buffer();
buffer.putBuffer(message);
out.write(buffer.array(), buffer.rpos(), buffer.available());
out.flush();
}
}
public void sessionCreated(IoSession session) throws Exception {
}
public void sessionClosed(IoSession session) throws Exception {
close(false);
}
public void exceptionCaught(IoSession ioSession, Throwable cause) throws Exception {
close(true);
}
};
connector = getSession().getFactoryManager().getIoServiceFactory()
.createConnector(handler);
IoConnectFuture future = connector.connect(address.toInetSocketAddress());
future.addListener(new SshFutureListener<IoConnectFuture>() {
public void operationComplete(IoConnectFuture future) {
if (future.isConnected()) {
ioSession = future.getSession();
f.setOpened();
} else if (future.getException() != null) {
closeImmediately0();
if (future.getException() instanceof ConnectException) {
f.setException(new OpenChannelException(
SshConstants.SSH_OPEN_CONNECT_FAILED,
future.getException().getMessage(),
future.getException()));
} else {
f.setException(future.getException());