Ejemplo n.º 1
0
 @SuppressWarnings("synthetic-access")
 @Override
 public void sessionCreated(final IoSession session) throws Exception {
   InetSocketAddress local = (InetSocketAddress) session.getLocalAddress();
   int localPort = local.getPort();
   SshdSocketAddress remote = localToRemote.get(localPort);
   final TcpipClientChannel channel;
   if (remote != null) {
     channel = new TcpipClientChannel(TcpipClientChannel.Type.Direct, session, remote);
   } else {
     channel = new TcpipClientChannel(TcpipClientChannel.Type.Forwarded, session, null);
   }
   session.setAttribute(TcpipClientChannel.class, channel);
   service.registerChannel(channel);
   channel
       .open()
       .addListener(
           new SshFutureListener<OpenFuture>() {
             @Override
             public void operationComplete(OpenFuture future) {
               Throwable t = future.getException();
               if (t != null) {
                 DefaultTcpipForwarder.this.service.unregisterChannel(channel);
                 channel.close(false);
               }
             }
           });
 }
Ejemplo n.º 2
0
 @SuppressWarnings("synthetic-access")
 @Override
 public void sessionClosed(IoSession session) throws Exception {
   TcpipClientChannel channel =
       (TcpipClientChannel) session.getAttribute(TcpipClientChannel.class);
   if (channel != null) {
     log.debug("IoSession {} closed, will now close the channel", session);
     channel.close(false);
   }
 }
Ejemplo n.º 3
0
    @Override
    public void messageReceived(IoSession session, Readable message) throws Exception {
      TcpipClientChannel channel =
          (TcpipClientChannel) session.getAttribute(TcpipClientChannel.class);
      Buffer buffer = new ByteArrayBuffer();
      buffer.putBuffer(message);
      channel.waitFor(ClientChannel.OPENED | ClientChannel.CLOSED, Long.MAX_VALUE);

      OutputStream outputStream = channel.getInvertedIn();
      outputStream.write(buffer.array(), buffer.rpos(), buffer.available());
      outputStream.flush();
    }
Ejemplo n.º 4
0
 @Override
 public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
   cause.printStackTrace();
   session.close(false);
 }