Mercurial > 510Connectbot
annotate app/src/main/java/net/sourceforge/jsocks/SocksSocket.java @ 516:3407f4741240
update copyrights
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 31 May 2024 11:17:53 -0600 |
parents | d29cce60f393 |
children |
rev | line source |
---|---|
349
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
1 package net.sourceforge.jsocks; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
2 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
3 import java.net.*; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
4 import java.io.*; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
5 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
6 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
7 * SocksSocket tryies to look very similar to normal Socket, |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
8 * while allowing connections through the SOCKS4 or 5 proxy. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
9 * To use this class you will have to identify proxy you need |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
10 * to use, CProxy class allows you to set default proxy, which |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
11 * will be used by all Socks aware sockets. You can also create |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
12 * either Socks4Proxy or Socks5Proxy, and use them by passing to the |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
13 * appropriate constructors. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
14 * <P> |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
15 * Using Socks package can be as easy as that: |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
16 * |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
17 * <pre><tt> |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
18 * |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
19 * import Socks.*; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
20 * .... |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
21 * |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
22 * try{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
23 * //Specify SOCKS5 proxy |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
24 * CProxy.setDefaultProxy("socks-proxy",1080); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
25 * |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
26 * //OR you still use SOCKS4 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
27 * //Code below uses SOCKS4 proxy |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
28 * //CProxy.setDefaultProxy("socks-proxy",1080,userName); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
29 * |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
30 * Socket s = SocksSocket("some.host.of.mine",13); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
31 * readTimeFromSock(s); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
32 * }catch(SocksException sock_ex){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
33 * //Usually it will turn in more or less meaningfull message |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
34 * System.err.println("SocksException:"+sock_ex); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
35 * } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
36 * |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
37 * </tt></pre> |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
38 *<P> |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
39 * However if the need exist for more control, like resolving addresses |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
40 * remotely, or using some non-trivial authentication schemes, it can be done. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
41 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
42 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
43 public class SocksSocket extends Socket{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
44 //Data members |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
45 protected CProxy proxy; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
46 protected String localHost, remoteHost; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
47 protected InetAddress localIP, remoteIP; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
48 protected int localPort,remotePort; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
49 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
50 private Socket directSock = null; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
51 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
52 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
53 * Tryies to connect to given host and port |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
54 * using default proxy. If no default proxy speciefied |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
55 * it throws SocksException with error code SOCKS_NO_PROXY. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
56 @param host Machine to connect to. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
57 @param port Port to which to connect. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
58 * @see SocksSocket#SocksSocket(CProxy,String,int) |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
59 * @see Socks5Proxy#resolveAddrLocally |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
60 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
61 public SocksSocket(String host,int port) |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
62 throws SocksException,UnknownHostException{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
63 this(CProxy.defaultProxy,host,port); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
64 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
65 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
66 * Connects to host port using given proxy server. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
67 @param p CProxy to use. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
68 @param host Machine to connect to. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
69 @param port Port to which to connect. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
70 @throws UnknownHostException |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
71 If one of the following happens: |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
72 <ol> |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
73 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
74 <li> CProxy settings say that address should be resolved locally, but |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
75 this fails. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
76 <li> CProxy settings say that the host should be contacted directly but |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
77 host name can't be resolved. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
78 </ol> |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
79 @throws SocksException |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
80 If one of the following happens: |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
81 <ul> |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
82 <li> CProxy is is null. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
83 <li> CProxy settings say that the host should be contacted directly but |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
84 this fails. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
85 <li> Socks Server can't be contacted. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
86 <li> Authentication fails. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
87 <li> Connection is not allowed by the SOCKS proxy. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
88 <li> SOCKS proxy can't establish the connection. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
89 <li> Any IO error occured. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
90 <li> Any protocol error occured. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
91 </ul> |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
92 @throws IOexception if anything is wrong with I/O. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
93 @see Socks5Proxy#resolveAddrLocally |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
94 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
95 public SocksSocket(CProxy p,String host,int port) |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
96 throws SocksException,UnknownHostException{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
97 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
98 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
99 if(p == null) throw new SocksException(CProxy.SOCKS_NO_PROXY); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
100 //proxy=p; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
101 proxy = p.copy(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
102 remoteHost = host; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
103 remotePort = port; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
104 if(proxy.isDirect(host)){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
105 remoteIP = InetAddress.getByName(host); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
106 doDirect(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
107 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
108 else |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
109 processReply(proxy.connect(host,port)); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
110 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
111 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
112 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
113 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
114 * Tryies to connect to given ip and port |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
115 * using default proxy. If no default proxy speciefied |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
116 * it throws SocksException with error code SOCKS_NO_PROXY. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
117 @param ip Machine to connect to. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
118 @param port Port to which to connect. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
119 * @see SocksSocket#SocksSocket(CProxy,String,int) |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
120 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
121 public SocksSocket(InetAddress ip, int port) throws SocksException{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
122 this(CProxy.defaultProxy,ip,port); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
123 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
124 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
125 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
126 Connects to given ip and port using given CProxy server. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
127 @param p CProxy to use. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
128 @param ip Machine to connect to. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
129 @param port Port to which to connect. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
130 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
131 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
132 public SocksSocket(CProxy p,InetAddress ip, int port) throws SocksException{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
133 if(p == null) throw new SocksException(CProxy.SOCKS_NO_PROXY); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
134 this.proxy = p.copy(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
135 this.remoteIP = ip; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
136 this.remotePort = port; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
137 this.remoteHost = ip.getHostName(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
138 if(proxy.isDirect(remoteIP)) |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
139 doDirect(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
140 else |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
141 processReply(proxy.connect(ip,port)); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
142 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
143 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
144 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
145 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
146 * These 2 constructors are used by the SocksServerSocket. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
147 * This socket simply overrides remoteHost, remotePort |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
148 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
149 protected SocksSocket(String host,int port,CProxy proxy){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
150 this.remotePort = port; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
151 this.proxy = proxy; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
152 this.localIP = proxy.proxySocket.getLocalAddress(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
153 this.localPort = proxy.proxySocket.getLocalPort(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
154 this.remoteHost = host; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
155 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
156 protected SocksSocket(InetAddress ip,int port,CProxy proxy){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
157 remoteIP = ip; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
158 remotePort = port; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
159 this.proxy = proxy; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
160 this.localIP = proxy.proxySocket.getLocalAddress(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
161 this.localPort = proxy.proxySocket.getLocalPort(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
162 remoteHost = remoteIP.getHostName(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
163 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
164 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
165 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
166 * Same as Socket |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
167 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
168 public void close() throws IOException{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
169 if(proxy!= null)proxy.endSession(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
170 proxy = null; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
171 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
172 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
173 * Same as Socket |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
174 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
175 public InputStream getInputStream(){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
176 return proxy.in; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
177 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
178 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
179 * Same as Socket |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
180 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
181 public OutputStream getOutputStream(){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
182 return proxy.out; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
183 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
184 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
185 * Same as Socket |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
186 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
187 public int getPort(){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
188 return remotePort; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
189 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
190 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
191 * Returns remote host name, it is usefull in cases when addresses |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
192 * are resolved by proxy, and we can't create InetAddress object. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
193 @return The name of the host this socket is connected to. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
194 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
195 public String getHost(){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
196 return remoteHost; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
197 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
198 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
199 * Get remote host as InetAddress object, might return null if |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
200 * addresses are resolved by proxy, and it is not possible to resolve |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
201 * it locally |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
202 @return Ip address of the host this socket is connected to, or null |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
203 if address was returned by the proxy as DOMAINNAME and can't be |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
204 resolved locally. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
205 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
206 public InetAddress getInetAddress(){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
207 if(remoteIP == null){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
208 try{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
209 remoteIP = InetAddress.getByName(remoteHost); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
210 }catch(UnknownHostException e){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
211 return null; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
212 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
213 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
214 return remoteIP; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
215 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
216 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
217 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
218 * Get the port assigned by the proxy for the socket, not |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
219 * the port on locall machine as in Socket. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
220 @return Port of the socket used on the proxy server. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
221 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
222 public int getLocalPort(){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
223 return localPort; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
224 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
225 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
226 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
227 * Get address assigned by proxy to make a remote connection, |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
228 * it might be different from the host specified for the proxy. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
229 * Can return null if socks server returned this address as hostname |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
230 * and it can't be resolved locally, use getLocalHost() then. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
231 @return Address proxy is using to make a connection. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
232 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
233 public InetAddress getLocalAddress(){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
234 if(localIP == null){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
235 try{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
236 localIP = InetAddress.getByName(localHost); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
237 }catch(UnknownHostException e){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
238 return null; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
239 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
240 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
241 return localIP; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
242 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
243 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
244 Get name of the host, proxy has assigned to make a remote connection |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
245 for this socket. This method is usefull when proxy have returned |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
246 address as hostname, and we can't resolve it on this machine. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
247 @return The name of the host proxy is using to make a connection. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
248 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
249 public String getLocalHost(){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
250 return localHost; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
251 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
252 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
253 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
254 Same as socket. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
255 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
256 public void setSoLinger(boolean on,int val) throws SocketException{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
257 proxy.proxySocket.setSoLinger(on,val); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
258 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
259 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
260 Same as socket. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
261 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
262 public int getSoLinger(int timeout) throws SocketException{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
263 return proxy.proxySocket.getSoLinger(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
264 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
265 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
266 Same as socket. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
267 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
268 public void setSoTimeout(int timeout) throws SocketException{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
269 proxy.proxySocket.setSoTimeout(timeout); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
270 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
271 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
272 Same as socket. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
273 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
274 public int getSoTimeout(int timeout) throws SocketException{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
275 return proxy.proxySocket.getSoTimeout(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
276 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
277 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
278 Same as socket. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
279 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
280 public void setTcpNoDelay(boolean on) throws SocketException{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
281 proxy.proxySocket.setTcpNoDelay(on); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
282 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
283 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
284 Same as socket. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
285 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
286 public boolean getTcpNoDelay() throws SocketException{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
287 return proxy.proxySocket.getTcpNoDelay(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
288 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
289 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
290 /** |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
291 Get string representation of the socket. |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
292 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
293 public String toString(){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
294 if(directSock!=null) return "Direct connection:"+directSock; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
295 return ("Proxy:"+proxy+";"+"addr:"+remoteHost+",port:"+remotePort |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
296 +",localport:"+localPort); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
297 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
298 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
299 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
300 //Private Methods |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
301 ////////////////// |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
302 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
303 private void processReply(ProxyMessage reply)throws SocksException{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
304 localPort = reply.port; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
305 /* |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
306 * If the server have assigned same host as it was contacted on |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
307 * it might return an address of all zeros |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
308 */ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
309 if(reply.host.equals("0.0.0.0")){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
310 localIP = proxy.proxyIP; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
311 localHost = localIP.getHostName(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
312 }else{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
313 localHost = reply.host; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
314 localIP = reply.ip; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
315 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
316 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
317 private void doDirect()throws SocksException{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
318 try{ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
319 //System.out.println("IP:"+remoteIP+":"+remotePort); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
320 directSock = new Socket(remoteIP,remotePort); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
321 proxy.out = directSock.getOutputStream(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
322 proxy.in = directSock.getInputStream(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
323 proxy.proxySocket = directSock; |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
324 localIP = directSock.getLocalAddress(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
325 localPort = directSock.getLocalPort(); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
326 }catch(IOException io_ex){ |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
327 throw new SocksException(CProxy.SOCKS_DIRECT_FAILED, |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
328 "Direct connect failed:"+io_ex); |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
329 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
330 } |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
331 |
205ee2873330
update jsocks to 2011-03-19
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
332 } |