*/
public Channel createChannel(String channelType, byte[] requestData)
throws InvalidChannelException {
if (channelType.equals(ForwardingSocketChannel.X11_FORWARDING_CHANNEL)) {
if (xDisplay == null) {
throw new InvalidChannelException(
"Local display has not been set for X11 forwarding.");
}
try {
ByteArrayReader bar = new ByteArrayReader(requestData);
String originatingHost = bar.readString();
int originatingPort = (int) bar.readInt();
log.debug("Creating socket to " +
x11ForwardingConfiguration.getHostToConnect() + "/" +
x11ForwardingConfiguration.getPortToConnect());
Socket socket = new Socket(x11ForwardingConfiguration.getHostToConnect(),
x11ForwardingConfiguration.getPortToConnect());
// Create the channel adding it to the active channels
ForwardingSocketChannel channel = x11ForwardingConfiguration.createForwardingSocketChannel(channelType,
x11ForwardingConfiguration.getHostToConnect(),
x11ForwardingConfiguration.getPortToConnect(),
originatingHost, originatingPort);
channel.bindSocket(socket);
channel.addEventListener(x11ForwardingConfiguration.monitor);
return channel;
} catch (IOException ioe) {
throw new InvalidChannelException(ioe.getMessage());
}
}
if (channelType.equals(
ForwardingSocketChannel.REMOTE_FORWARDING_CHANNEL)) {
try {
ByteArrayReader bar = new ByteArrayReader(requestData);
String addressBound = bar.readString();
int portBound = (int) bar.readInt();
String originatingHost = bar.readString();
int originatingPort = (int) bar.readInt();
ForwardingConfiguration config = getRemoteForwardingByAddress(addressBound,
portBound);
Socket socket = new Socket(config.getHostToConnect(),
config.getPortToConnect());
/*Socket socket = new Socket();
socket.connect(new InetSocketAddress(
config.getHostToConnect(), config.getPortToConnect()));*/
// Create the channel adding it to the active channels
ForwardingSocketChannel channel = config.createForwardingSocketChannel(channelType,
config.getHostToConnect(), config.getPortToConnect(),
originatingHost, originatingPort);
channel.bindSocket(socket);
channel.addEventListener(config.monitor);
return channel;
} catch (ForwardingConfigurationException fce) {
throw new InvalidChannelException(
"No valid forwarding configuration was available for the request address");
} catch (IOException ioe) {
throw new InvalidChannelException(ioe.getMessage());
}
}
throw new InvalidChannelException(
"The server can only request a remote forwarding channel or an" +
"X11 forwarding channel");
}