comparison src/ch/ethz/ssh2/channel/RemoteAcceptThread.java @ 308:42b15aaa7ac7 ganymed

merge
author Carl Byington <carl@five-ten-sg.com>
date Wed, 30 Jul 2014 14:21:50 -0700
parents 071eccdff8ea
children
comparison
equal deleted inserted replaced
306:90e47d99ea54 308:42b15aaa7ac7
13 * RemoteAcceptThread. 13 * RemoteAcceptThread.
14 * 14 *
15 * @author Christian Plattner 15 * @author Christian Plattner
16 * @version $Id: RemoteAcceptThread.java 119 2014-04-12 20:30:58Z dkocher@sudo.ch $ 16 * @version $Id: RemoteAcceptThread.java 119 2014-04-12 20:30:58Z dkocher@sudo.ch $
17 */ 17 */
18 public class RemoteAcceptThread extends Thread 18 public class RemoteAcceptThread extends Thread {
19 { 19 private static final Logger log = Logger.getLogger(RemoteAcceptThread.class);
20 private static final Logger log = Logger.getLogger(RemoteAcceptThread.class);
21 20
22 Channel c; 21 Channel c;
23 22
24 String remoteConnectedAddress; 23 String remoteConnectedAddress;
25 int remoteConnectedPort; 24 int remoteConnectedPort;
26 String remoteOriginatorAddress; 25 String remoteOriginatorAddress;
27 int remoteOriginatorPort; 26 int remoteOriginatorPort;
28 String targetAddress; 27 String targetAddress;
29 int targetPort; 28 int targetPort;
30 29
31 Socket s; 30 Socket s;
32 31
33 public RemoteAcceptThread(Channel c, String remoteConnectedAddress, int remoteConnectedPort, 32 public RemoteAcceptThread(Channel c, String remoteConnectedAddress, int remoteConnectedPort,
34 String remoteOriginatorAddress, int remoteOriginatorPort, String targetAddress, int targetPort) 33 String remoteOriginatorAddress, int remoteOriginatorPort, String targetAddress, int targetPort) {
35 { 34 this.c = c;
36 this.c = c; 35 this.remoteConnectedAddress = remoteConnectedAddress;
37 this.remoteConnectedAddress = remoteConnectedAddress; 36 this.remoteConnectedPort = remoteConnectedPort;
38 this.remoteConnectedPort = remoteConnectedPort; 37 this.remoteOriginatorAddress = remoteOriginatorAddress;
39 this.remoteOriginatorAddress = remoteOriginatorAddress; 38 this.remoteOriginatorPort = remoteOriginatorPort;
40 this.remoteOriginatorPort = remoteOriginatorPort; 39 this.targetAddress = targetAddress;
41 this.targetAddress = targetAddress; 40 this.targetPort = targetPort;
42 this.targetPort = targetPort; 41 log.debug("RemoteAcceptThread: " + remoteConnectedAddress + "/" + remoteConnectedPort + ", R: "
42 + remoteOriginatorAddress + "/" + remoteOriginatorPort);
43 }
43 44
44 log.debug("RemoteAcceptThread: " + remoteConnectedAddress + "/" + remoteConnectedPort + ", R: " 45 @Override
45 + remoteOriginatorAddress + "/" + remoteOriginatorPort); 46 public void run() {
46 } 47 try {
48 c.cm.sendOpenConfirmation(c);
49 s = new Socket(targetAddress, targetPort);
50 StreamForwarder r2l = new StreamForwarder(c, null, null, c.getStdoutStream(), s.getOutputStream(),
51 "RemoteToLocal");
52 StreamForwarder l2r = new StreamForwarder(c, null, null, s.getInputStream(), c.getStdinStream(),
53 "LocalToRemote");
54 /* No need to start two threads, one can be executed in the current thread */
55 r2l.setDaemon(true);
56 r2l.start();
57 l2r.run();
47 58
48 @Override 59 while (r2l.isAlive()) {
49 public void run() 60 try {
50 { 61 r2l.join();
51 try 62 }
52 { 63 catch (InterruptedException ignored) {
53 c.cm.sendOpenConfirmation(c); 64 }
65 }
54 66
55 s = new Socket(targetAddress, targetPort); 67 /* If the channel is already closed, then this is a no-op */
68 c.cm.closeChannel(c, "EOF on both streams reached.", true);
69 s.close();
70 }
71 catch (IOException e) {
72 log.warning("IOException in proxy code: " + e.getMessage());
56 73
57 StreamForwarder r2l = new StreamForwarder(c, null, null, c.getStdoutStream(), s.getOutputStream(), 74 try {
58 "RemoteToLocal"); 75 c.cm.closeChannel(c, e, true);
59 StreamForwarder l2r = new StreamForwarder(c, null, null, s.getInputStream(), c.getStdinStream(), 76 }
60 "LocalToRemote"); 77 catch (IOException ignored) {
78 }
61 79
62 /* No need to start two threads, one can be executed in the current thread */ 80 try {
63 81 if (s != null)
64 r2l.setDaemon(true); 82 s.close();
65 r2l.start(); 83 }
66 l2r.run(); 84 catch (IOException ignored) {
67 85 }
68 while (r2l.isAlive()) 86 }
69 { 87 }
70 try
71 {
72 r2l.join();
73 }
74 catch (InterruptedException ignored)
75 {
76 }
77 }
78
79 /* If the channel is already closed, then this is a no-op */
80
81 c.cm.closeChannel(c, "EOF on both streams reached.", true);
82 s.close();
83 }
84 catch (IOException e)
85 {
86 log.warning("IOException in proxy code: " + e.getMessage());
87
88 try
89 {
90 c.cm.closeChannel(c, e, true);
91 }
92 catch (IOException ignored)
93 {
94 }
95 try
96 {
97 if (s != null)
98 s.close();
99 }
100 catch (IOException ignored)
101 {
102 }
103 }
104 }
105 } 88 }