1 19 20 package com.sslexplorer.tunnels.agent; 21 22 import java.io.IOException ; 23 import java.net.Socket ; 24 25 import com.maverick.multiplex.Channel; 26 import com.maverick.multiplex.IOStreamConnector; 27 import com.maverick.util.ByteArrayWriter; 28 import com.sslexplorer.policyframework.LaunchSession; 29 import com.sslexplorer.tunnels.Tunnel; 30 31 public class RemoteForwardingChannel extends Channel { 32 33 public static final String CHANNEL_TYPE = "remote-tunnel"; 34 35 private Tunnel tunnel; 36 37 Socket incomingConnection = null; 38 IOStreamConnector input; 39 IOStreamConnector output; 40 RemoteTunnel remoteTunnel; 41 LaunchSession launchSession; 42 43 public RemoteForwardingChannel(RemoteTunnel remoteTunnel, Socket incomingConnection, Tunnel tunnel, LaunchSession launchSession) { 44 super(CHANNEL_TYPE, 32768, 35000); 45 this.launchSession = launchSession; 46 this.remoteTunnel = remoteTunnel; 47 this.tunnel = tunnel; 48 this.incomingConnection = incomingConnection; 49 } 50 51 public RemoteTunnel getRemoteTunnel() { 52 return remoteTunnel; 53 } 54 55 public byte[] create() throws IOException { 56 ByteArrayWriter msg = new ByteArrayWriter(); 57 msg.writeString(launchSession == null ? "" : launchSession.getId()); 58 msg.writeInt(tunnel.getResourceId()); 59 msg.writeString(tunnel.getResourceName()); 60 msg.writeInt(tunnel.getType()); 61 msg.writeString(tunnel.getTransport()); 62 msg.writeString(tunnel.getSourceInterface()); 63 msg.writeInt(tunnel.getSourcePort()); 64 msg.writeInt(tunnel.getDestination().getPort()); 65 msg.writeString(tunnel.getDestination().getHost()); 66 msg.writeBoolean(false); 67 return msg.toByteArray(); 68 } 69 70 public void onChannelClose() { 71 if (input != null) 72 input.close(); 73 if (output != null) 74 output.close(); 75 try { 76 if (incomingConnection != null) 77 incomingConnection.close(); 78 } catch (IOException e) { 79 } 80 } 81 82 public void onChannelOpen(byte[] data) { 83 if (incomingConnection != null) { 84 try { 85 input = new IOStreamConnector(getInputStream(), incomingConnection.getOutputStream()); 86 output = new IOStreamConnector(incomingConnection.getInputStream(), getOutputStream()); 87 } catch (IOException ex) { 88 close(); 89 } 90 } 91 } 92 93 public byte[] open(byte[] data) throws IOException { 94 return null; 95 } 96 97 } 98 | Popular Tags |