Mercurial > 510Connectbot
annotate src/ch/ethz/ssh2/channel/RemoteAcceptThread.java @ 328:459eb9b6b84e ganymed
pickup compression from trilead
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 31 Jul 2014 11:27:40 -0700 |
parents | 071eccdff8ea |
children |
rev | line source |
---|---|
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
1 /* |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved. |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
3 * Please refer to the LICENSE.txt for licensing details. |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
4 */ |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
5 package ch.ethz.ssh2.channel; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
6 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
7 import java.io.IOException; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
8 import java.net.Socket; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
9 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
10 import ch.ethz.ssh2.log.Logger; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
11 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
12 /** |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
13 * RemoteAcceptThread. |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
14 * |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
15 * @author Christian Plattner |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
16 * @version $Id: RemoteAcceptThread.java 119 2014-04-12 20:30:58Z dkocher@sudo.ch $ |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
17 */ |
307 | 18 public class RemoteAcceptThread extends Thread { |
19 private static final Logger log = Logger.getLogger(RemoteAcceptThread.class); | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
20 |
307 | 21 Channel c; |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
22 |
307 | 23 String remoteConnectedAddress; |
24 int remoteConnectedPort; | |
25 String remoteOriginatorAddress; | |
26 int remoteOriginatorPort; | |
27 String targetAddress; | |
28 int targetPort; | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
29 |
307 | 30 Socket s; |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
31 |
307 | 32 public RemoteAcceptThread(Channel c, String remoteConnectedAddress, int remoteConnectedPort, |
33 String remoteOriginatorAddress, int remoteOriginatorPort, String targetAddress, int targetPort) { | |
34 this.c = c; | |
35 this.remoteConnectedAddress = remoteConnectedAddress; | |
36 this.remoteConnectedPort = remoteConnectedPort; | |
37 this.remoteOriginatorAddress = remoteOriginatorAddress; | |
38 this.remoteOriginatorPort = remoteOriginatorPort; | |
39 this.targetAddress = targetAddress; | |
40 this.targetPort = targetPort; | |
41 log.debug("RemoteAcceptThread: " + remoteConnectedAddress + "/" + remoteConnectedPort + ", R: " | |
42 + remoteOriginatorAddress + "/" + remoteOriginatorPort); | |
43 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
44 |
307 | 45 @Override |
46 public void run() { | |
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(); | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
58 |
307 | 59 while (r2l.isAlive()) { |
60 try { | |
61 r2l.join(); | |
62 } | |
63 catch (InterruptedException ignored) { | |
64 } | |
65 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
66 |
307 | 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()); | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
73 |
307 | 74 try { |
75 c.cm.closeChannel(c, e, true); | |
76 } | |
77 catch (IOException ignored) { | |
78 } | |
79 | |
80 try { | |
81 if (s != null) | |
82 s.close(); | |
83 } | |
84 catch (IOException ignored) { | |
85 } | |
86 } | |
87 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
88 } |