int originatorPort = buffer.getInt();
log.info("Receiving request for direct tcpip: hostToConnect={}, portToConnect={}, originatorIpAddress={}, originatorPort={}",
new Object[] { hostToConnect, portToConnect, originatorIpAddress, originatorPort });
final ClientSessionImpl clientSession = (ClientSessionImpl)getSession();
SshdSocketAddress address;
try {
address = clientSession.getForwardedPort(portToConnect);
} catch (RuntimeException e) {
address = null;
}
//final ForwardingFilter filter = clientSession.getClientFactoryManager().getForwardingFilter();
if (address == null /*|| filter == null || !filter.canConnect(address, serverSession)*/) {
super.close(true);
f.setException(new OpenChannelException(SshConstants.SSH_OPEN_ADMINISTRATIVELY_PROHIBITED, "connect denied"));
return f;
}
connector = new NioSocketConnector();
out = new ChannelOutputStream(this, remoteWindow, log, SshConstants.Message.SSH_MSG_CHANNEL_DATA);
IoHandler handler = new IoHandlerAdapter() {
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
IoBuffer ioBuffer = (IoBuffer) message;
int r = ioBuffer.remaining();
byte[] b = new byte[r];
ioBuffer.get(b, 0, r);
out.write(b, 0, r);
out.flush();
}
@Override
public void sessionClosed(IoSession session) throws Exception {
if (!closing) {
sendEof();
}
}
};
connector.setHandler(handler);
ConnectFuture future = connector.connect(address.toInetSocketAddress());
future.addListener(new IoFutureListener<ConnectFuture>() {
public void operationComplete(ConnectFuture future) {
if (future.isConnected()) {
ioSession = future.getSession();
f.setOpened();