snf4j / snf4j
Showing 7 of 24 files from the diff.

@@ -33,6 +33,8 @@
Loading
33 33
import java.util.List;
34 34
import java.util.Random;
35 35
36 +
import org.snf4j.core.util.Base64Util;
37 +
36 38
class HandshakeUtils {
37 39
38 40
	final static String SEC_WEB_SOCKET_KEY = "Sec-WebSocket-Key";
@@ -86,7 +88,7 @@
Loading
86 88
	}
87 89
	
88 90
	static String generateKey(byte[] bytes) {
89 -
		bytes = Base64.encode(bytes);
91 +
		bytes = Base64Util.encode(bytes);
90 92
		return HttpUtils.ascii(bytes, 0, bytes.length);
91 93
	}
92 94
	
@@ -96,7 +98,7 @@
Loading
96 98
			byte[] bytes;
97 99
			
98 100
			md.update(HttpUtils.bytes(key));
99 -
			bytes = Base64.encode(md.digest(KEY_GUID));
101 +
			bytes = Base64Util.encode(md.digest(KEY_GUID));
100 102
			return HttpUtils.ascii(bytes, 0, bytes.length);
101 103
		}
102 104
		catch (Exception e) {
@@ -105,10 +107,15 @@
Loading
105 107
	}
106 108
	
107 109
	static byte[] parseKey(String key) {
108 -
		byte[] bytes = Base64.decode(HttpUtils.bytes(key));
109 -
			
110 -
		if (bytes != null && bytes.length == 16) {
111 -
			return bytes;
110 +
		try {
111 +
			byte[] bytes = Base64Util.decode(HttpUtils.bytes(key));
112 +
113 +
			if (bytes.length == 16) {
114 +
				return bytes;
115 +
			}
116 +
		}
117 +
		catch (Exception e) {
118 +
			//Ignore
112 119
		}
113 120
		return null;
114 121
	}

@@ -36,6 +36,7 @@
Loading
36 36
import org.snf4j.core.handler.SessionEvent;
37 37
import org.snf4j.core.session.ISessionConfig;
38 38
import org.snf4j.core.session.IStreamSession;
39 +
import org.snf4j.core.util.Base64Util;
39 40
40 41
/**
41 42
 * Handles client proxy connections via the HTTP tunneling protocol. For more
@@ -69,14 +70,20 @@
Loading
69 70
70 71
	private final static byte[] HOST = toBytes("Host");
71 72
	
73 +
	private final static byte[] PROXY_AUTHORIZATION = toBytes("Proxy-Authorization");
74 +
	
72 75
	private final static int OK = 200;
73 76
	
74 77
	private final List<byte[]> headers = new LinkedList<byte[]>(); 
75 78
76 -
	private final int minEof;
79 +
	private volatile int minEof = 2;
77 80
	
78 81
	private final URI uri;
79 82
	
83 +
	private final String username;
84 +
	
85 +
	private final String password;
86 +
	
80 87
	private Integer statusCode;
81 88
	
82 89
	private int headersLength;
@@ -93,257 +100,118 @@
Loading
93 100
	 * @throws IllegalArgumentException if the uri is null
94 101
	 */
95 102
	public HttpProxyHandler(URI uri) {	
96 -
		this(uri, false, null, null);
103 +
		this(uri, (ISessionConfig)null, null);
97 104
	}
98 105
99 106
	/**
100 107
	 * Constructs an HTTP tunnel connection handler with the default (10 seconds)
101 -
	 * connection timeout and configuration.
108 +
	 * connection timeout and user's name/password for the 'Basic' HTTP
109 +
	 * authentication scheme.
102 110
	 * <p>
103 111
	 * NOTE: The connection timeout will have no effect if the associated session
104 112
	 * does not support a session timer.
105 113
	 * 
106 -
	 * @param uri    the URI identifying the remote host to which the HTTP tunnel
107 -
	 *               should be established
108 -
	 * @param config the session configuration object, or {@code null} to use the
109 -
	 *               default configuration
110 -
	 * @throws IllegalArgumentException if the uri is null
114 +
	 * @param uri      the URI identifying the remote host to which the HTTP tunnel
115 +
	 *                 should be established
116 +
	 * @param username the user's name
117 +
	 * @param password the user's password
118 +
	 * @throws IllegalArgumentException if the uri, username or password is null
111 119
	 */
112 -
	public HttpProxyHandler(URI uri, ISessionConfig config) {	
113 -
		this(uri, false, config, null);
120 +
	public HttpProxyHandler(URI uri, String username, String password) {	
121 +
		this(uri, username, password, null, null);
114 122
	}
115 -
116 -
	/**
117 -
	 * Constructs an HTTP tunnel connection handler with the default (10 seconds)
118 -
	 * connection timeout, configuration and factory.
119 -
	 * <p>
120 -
	 * NOTE: The connection timeout will have no effect if the associated session
121 -
	 * does not support a session timer.
122 -
	 * 
123 -
	 * @param uri     the URI identifying the remote host to which the HTTP tunnel
124 -
	 *                should be established
125 -
	 * @param config  the session configuration object, or {@code null} to use the
126 -
	 *                default configuration
127 -
	 * @param factory the factory that will be used to configure the internal
128 -
	 *                structure of the associated session, or {@code null} to use
129 -
	 *                the default factory
130 -
	 * @throws IllegalArgumentException if the uri is null
131 -
	 */
132 -
	public HttpProxyHandler(URI uri, ISessionConfig config, ISessionStructureFactory factory) {	
133 -
		this(uri, false, config, factory);
134 -
	}
135 -
123 +
	
136 124
	/**
137 125
	 * Constructs an HTTP tunnel connection handler with the default (10 seconds)
138 -
	 * connection timeout and an option to change the default handling of line
139 -
	 * terminators.
126 +
	 * connection timeout and configuration.
140 127
	 * <p>
141 128
	 * NOTE: The connection timeout will have no effect if the associated session
142 129
	 * does not support a session timer.
143 130
	 * 
144 -
	 * @param uri                  the URI identifying the remote host to which the
145 -
	 *                             HTTP tunnel should be established
146 -
	 * @param allowBothTerminators {@code true} to allow both CRLF and LF line
147 -
	 *                             terminators in the responses from a HTTP proxy
148 -
	 *                             server, or otherwise (default option) only CRLF
149 -
	 *                             will be allowed
131 +
	 * @param uri    the URI identifying the remote host to which the HTTP tunnel
132 +
	 *               should be established
133 +
	 * @param config the session configuration object, or {@code null} to use the
134 +
	 *               default configuration
150 135
	 * @throws IllegalArgumentException if the uri is null
151 136
	 */
152 -
	public HttpProxyHandler(URI uri, boolean allowBothTerminators) {	
153 -
		this(uri, allowBothTerminators, null, null);
137 +
	public HttpProxyHandler(URI uri, ISessionConfig config) {	
138 +
		this(uri, config, null);
154 139
	}
155 140
156 141
	/**
157 142
	 * Constructs an HTTP tunnel connection handler with the default (10 seconds)
158 -
	 * connection timeout, an option to change the default handling of line
159 -
	 * terminators and configuration.
143 +
	 * connection timeout, user's name/password for the 'Basic' HTTP authentication
144 +
	 * scheme and configuration.
160 145
	 * <p>
161 146
	 * NOTE: The connection timeout will have no effect if the associated session
162 147
	 * does not support a session timer.
163 148
	 * 
164 -
	 * @param uri                  the URI identifying the remote host to which the
165 -
	 *                             HTTP tunnel should be established
166 -
	 * @param allowBothTerminators {@code true} to allow both CRLF and LF line
167 -
	 *                             terminators in the responses from a HTTP proxy
168 -
	 *                             server, or otherwise (default option) only CRLF
169 -
	 *                             will be allowed
170 -
	 * @param config               the session configuration object, or {@code null}
171 -
	 *                             to use the default configuration
172 -
	 * @throws IllegalArgumentException if the uri is null
149 +
	 * @param uri      the URI identifying the remote host to which the HTTP tunnel
150 +
	 *                 should be established
151 +
	 * @param username the user's name
152 +
	 * @param password the user's password
153 +
	 * @param config   the session configuration object, or {@code null} to use the
154 +
	 *                 default configuration
155 +
	 * @throws IllegalArgumentException if the uri, username or password is null
173 156
	 */
174 -
	public HttpProxyHandler(URI uri, boolean allowBothTerminators, ISessionConfig config) {	
175 -
		this(uri, allowBothTerminators, config, null);
157 +
	public HttpProxyHandler(URI uri, String username, String password, ISessionConfig config) {
158 +
		this(uri, username, password, config, null);
176 159
	}
177 160
	
178 161
	/**
179 162
	 * Constructs an HTTP tunnel connection handler with the default (10 seconds)
180 -
	 * connection timeout, an option to change the default handling of line
181 -
	 * terminators, configuration and factory.
163 +
	 * connection timeout, configuration and factory.
182 164
	 * <p>
183 165
	 * NOTE: The connection timeout will have no effect if the associated session
184 166
	 * does not support a session timer.
185 167
	 * 
186 -
	 * @param uri                  the URI identifying the remote host to which the
187 -
	 *                             HTTP tunnel should be established
188 -
	 * @param allowBothTerminators {@code true} to allow both CRLF and LF line
189 -
	 *                             terminators in the responses from a HTTP proxy
190 -
	 *                             server, or otherwise (default option) only CRLF
191 -
	 *                             will be allowed
192 -
	 * @param config               the session configuration object, or {@code null}
193 -
	 *                             to use the default configuration
194 -
	 * @param factory              the factory that will be used to configure the
195 -
	 *                             internal structure of the associated session, or
196 -
	 *                             {@code null} to use the default factory
168 +
	 * @param uri     the URI identifying the remote host to which the HTTP tunnel
169 +
	 *                should be established
170 +
	 * @param config  the session configuration object, or {@code null} to use the
171 +
	 *                default configuration
172 +
	 * @param factory the factory that will be used to configure the internal
173 +
	 *                structure of the associated session, or {@code null} to use
174 +
	 *                the default factory
197 175
	 * @throws IllegalArgumentException if the uri is null
198 176
	 */
199 -
	public HttpProxyHandler(URI uri, boolean allowBothTerminators, ISessionConfig config, ISessionStructureFactory factory) {	
177 +
	public HttpProxyHandler(URI uri, ISessionConfig config, ISessionStructureFactory factory) {
200 178
		super(config, factory);
201 -
		if (uri == null) {
202 -
			throw new IllegalArgumentException("uri is null");
203 -
		}
179 +
		checkNull(uri, "uri");
204 180
		this.uri = uri;
205 -
		minEof = allowBothTerminators ? 1 : 2;
206 -
	}
207 -
	
208 -
	/**
209 -
	 * Constructs an HTTP tunnel connection handler with the specified connection
210 -
	 * timeout.
211 -
	 * <p>
212 -
	 * NOTE: The connection timeout will have no effect if the associated session
213 -
	 * does not support a session timer.
214 -
	 * 
215 -
	 * @param uri               the URI identifying the remote host to which the
216 -
	 *                          HTTP tunnel should be established
217 -
	 * @param connectionTimeout the proxy connection timeout in milliseconds, or
218 -
	 *                          {@code 0} to wait an infinite amount of time for 
219 -
	 *                          establishing the HTTP tunnel.
220 -
	 * @throws IllegalArgumentException if the uri is null
221 -
	 */
222 -
	public HttpProxyHandler(URI uri, long connectionTimeout) {
223 -
		this(uri, connectionTimeout, false);
224 -
	}
225 -
226 -
	/**
227 -
	 * Constructs an HTTP tunnel connection handler with the specified connection
228 -
	 * timeout and configuration.
229 -
	 * <p>
230 -
	 * NOTE: The connection timeout will have no effect if the associated session
231 -
	 * does not support a session timer.
232 -
	 * 
233 -
	 * @param uri               the URI identifying the remote host to which the
234 -
	 *                          HTTP tunnel should be established
235 -
	 * @param connectionTimeout the proxy connection timeout in milliseconds, or
236 -
	 *                          {@code 0} to wait an infinite amount of time for
237 -
	 *                          establishing the HTTP tunnel.
238 -
	 * @param config            the session configuration object, or {@code null} to
239 -
	 *                          use the default configuration
240 -
	 * @throws IllegalArgumentException if the uri is null
241 -
	 */
242 -
	public HttpProxyHandler(URI uri, long connectionTimeout, ISessionConfig config) {
243 -
		this(uri, connectionTimeout, false, config, null);
244 -
	}
245 -
246 -
	/**
247 -
	 * Constructs an HTTP tunnel connection handler with the specified connection
248 -
	 * timeout, configuration and factory.
249 -
	 * <p>
250 -
	 * NOTE: The connection timeout will have no effect if the associated session
251 -
	 * does not support a session timer.
252 -
	 * 
253 -
	 * @param uri               the URI identifying the remote host to which the
254 -
	 *                          HTTP tunnel should be established
255 -
	 * @param connectionTimeout the proxy connection timeout in milliseconds, or
256 -
	 *                          {@code 0} to wait an infinite amount of time for
257 -
	 *                          establishing the HTTP tunnel.
258 -
	 * @param config            the session configuration object, or {@code null} to
259 -
	 *                          use the default configuration
260 -
	 * @param factory           the factory that will be used to configure the
261 -
	 *                          internal structure of the associated session, or
262 -
	 *                          {@code null} to use the default factory
263 -
	 * @throws IllegalArgumentException if the uri is null
264 -
	 */
265 -
	public HttpProxyHandler(URI uri, long connectionTimeout, ISessionConfig config, ISessionStructureFactory factory) {
266 -
		this(uri, connectionTimeout, false, config, factory);
267 -
	}
268 -
269 -
	/**
270 -
	 * Constructs an HTTP tunnel connection handler with the specified connection
271 -
	 * timeout and an option to change the default handling of line terminators.
272 -
	 * <p>
273 -
	 * NOTE: The connection timeout will have no effect if the associated session
274 -
	 * does not support a session timer.
275 -
	 * 
276 -
	 * @param uri                  the URI identifying the remote host to which the
277 -
	 *                             HTTP tunnel should be established
278 -
	 * @param connectionTimeout    the proxy connection timeout in milliseconds, or
279 -
	 *                             {@code 0} to wait an infinite amount of time for
280 -
	 *                             establishing the HTTP tunnel.
281 -
	 * @param allowBothTerminators {@code true} to allow both CRLF and LF line
282 -
	 *                             terminators in the responses from a HTTP proxy
283 -
	 *                             server, or otherwise (default option) only CRLF
284 -
	 *                             will be allowed
285 -
	 * @throws IllegalArgumentException if the uri is null
286 -
	 */
287 -
	public HttpProxyHandler(URI uri, long connectionTimeout, boolean allowBothTerminators) {
288 -
		this(uri, connectionTimeout, allowBothTerminators, null, null);
289 -
	}
290 -
291 -
	/**
292 -
	 * Constructs an HTTP tunnel connection handler with the specified connection
293 -
	 * timeout and an option to change the default handling of line terminators and
294 -
	 * configuration.
295 -
	 * <p>
296 -
	 * NOTE: The connection timeout will have no effect if the associated session
297 -
	 * does not support a session timer.
298 -
	 * 
299 -
	 * @param uri                  the URI identifying the remote host to which the
300 -
	 *                             HTTP tunnel should be established
301 -
	 * @param connectionTimeout    the proxy connection timeout in milliseconds, or
302 -
	 *                             {@code 0} to wait an infinite amount of time for
303 -
	 *                             establishing the HTTP tunnel.
304 -
	 * @param allowBothTerminators {@code true} to allow both CRLF and LF line
305 -
	 *                             terminators in the responses from a HTTP proxy
306 -
	 *                             server, or otherwise (default option) only CRLF
307 -
	 *                             will be allowed
308 -
	 * @param config               the session configuration object, or {@code null}
309 -
	 *                             to use the default configuration
310 -
	 * @throws IllegalArgumentException if the uri is null
311 -
	 */
312 -
	public HttpProxyHandler(URI uri, long connectionTimeout, boolean allowBothTerminators, ISessionConfig config) {
313 -
		this(uri, connectionTimeout, allowBothTerminators, config, null);
181 +
		username = null;
182 +
		password = null;
314 183
	}
315 184
	
316 185
	/**
317 -
	 * Constructs an HTTP tunnel connection handler with the specified connection
318 -
	 * timeout, an option to change the default handling of line terminators,
319 -
	 * configuration and factory.
186 +
	 * Constructs an HTTP tunnel connection handler with the default (10 seconds)
187 +
	 * connection timeout, user's name/password for the 'Basic' HTTP authentication
188 +
	 * scheme, configuration and factory.
320 189
	 * <p>
321 190
	 * NOTE: The connection timeout will have no effect if the associated session
322 191
	 * does not support a session timer.
323 192
	 * 
324 -
	 * @param uri                  the URI identifying the remote host to which the
325 -
	 *                             HTTP tunnel should be established
326 -
	 * @param connectionTimeout    the proxy connection timeout in milliseconds, or
327 -
	 *                             {@code 0} to wait an infinite amount of time for
328 -
	 *                             establishing the HTTP tunnel.
329 -
	 * @param allowBothTerminators {@code true} to allow both CRLF and LF line
330 -
	 *                             terminators in the responses from a HTTP proxy
331 -
	 *                             server, or otherwise (default option) only CRLF
332 -
	 *                             will be allowed
333 -
	 * @param config               the session configuration object, or {@code null}
334 -
	 *                             to use the default configuration
335 -
	 * @param factory              the factory that will be used to configure the
336 -
	 *                             internal structure of the associated session, or
337 -
	 *                             {@code null} to use the default factory
338 -
	 * @throws IllegalArgumentException if the uri is null
193 +
	 * @param uri      the URI identifying the remote host to which the HTTP tunnel
194 +
	 *                 should be established
195 +
	 * @param username the user's name
196 +
	 * @param password the user's password
197 +
	 * @param config   the session configuration object, or {@code null} to use the
198 +
	 *                 default configuration
199 +
	 * @param factory  the factory that will be used to configure the internal
200 +
	 *                 structure of the associated session, or {@code null} to use
201 +
	 *                 the default factory
202 +
	 * @throws IllegalArgumentException if the uri, username or password is null
339 203
	 */
340 -
	public HttpProxyHandler(URI uri, long connectionTimeout, boolean allowBothTerminators, ISessionConfig config, ISessionStructureFactory factory) {
341 -
		super(connectionTimeout, config, factory);
342 -
		if (uri == null) {
343 -
			throw new IllegalArgumentException("uri is null");
344 -
		}
204 +
	public HttpProxyHandler(URI uri, String username, String password, ISessionConfig config, ISessionStructureFactory factory) {
205 +
		super(config, factory);
206 +
		checkNull(uri, "uri");
207 +
		checkNull(username, "username");
208 +
		checkNull(password, "password");
345 209
		this.uri = uri;
346 -
		minEof = allowBothTerminators ? 1 : 2;
210 +
		if (username.indexOf(COLON_TEXT) >= 0) {
211 +
			throw new IllegalArgumentException("username contains a colon");
212 +
		}
213 +
		this.username = username;
214 +
		this.password = password;
347 215
	}
348 216
	
349 217
	private static final byte[] toBytes(String s) {
@@ -368,6 +236,31 @@
Loading
368 236
		}
369 237
	}
370 238
	
239 +
	/**
240 +
	 * {@inheritDoc}
241 +
	 * 
242 +
	 * @throws IllegalArgumentException if the connection timeout is negative 
243 +
	 */
244 +
	@Override
245 +
	public HttpProxyHandler connectionTimeout(long connectionTimeout) {
246 +
		super.connectionTimeout(connectionTimeout);
247 +
		return this;
248 +
	}
249 +
250 +
	/**
251 +
	 * Configures the handling of line terminators in responses from a HTTP proxy
252 +
	 * server
253 +
	 * 
254 +
	 * @param allow {@code true} to allow both CRLF and LF line terminators in
255 +
	 *              responses from a HTTP proxy server, or otherwise (default
256 +
	 *              option) only CRLF will be allowed.
257 +
	 * @return this handler
258 +
	 */
259 +
	public HttpProxyHandler allowBothTerminators(boolean allow) {
260 +
		minEof = allow ? 1 : 2;
261 +
		return this;
262 +
	}
263 +
	
371 264
	@Override
372 265
	public int available(byte[] data, int off, int len) {
373 266
		int lastEol = off;
@@ -531,6 +424,7 @@
Loading
531 424
		
532 425
		byte[] fullHost;
533 426
		byte[] host;
427 +
		byte[] proxyAuth;
534 428
		
535 429
		if (uriPort != -1) {
536 430
			fullHost = toBytes(uriHost + COLON_TEXT + Integer.toString(uriPort));
@@ -545,6 +439,15 @@
Loading
545 439
			host = toBytes(uriHost);
546 440
		}
547 441
		
442 +
		if (username != null) {
443 +
			proxyAuth = toBytes("Basic " + Base64Util.encode(
444 +
					(username + COLON_TEXT + password).getBytes(StandardCharsets.UTF_8), 
445 +
					StandardCharsets.US_ASCII));
446 +
		}
447 +
		else {
448 +
			proxyAuth = null;
449 +
		}
450 +
		
548 451
		IStreamSession session = getSession();
549 452
		ByteBuffer frame;
550 453
		
@@ -562,6 +465,13 @@
Loading
562 465
				+ headersLength
563 466
				+ CRLF.length;
564 467
		
468 +
			if (proxyAuth != null) {
469 +
				length += PROXY_AUTHORIZATION.length 
470 +
					+ 2 /* COLON + SP */
471 +
					+ proxyAuth.length
472 +
					+CRLF.length;
473 +
			}
474 +
			
565 475
			frame = session.allocate(length);
566 476
			frame.put(HTTP_CONNECT);
567 477
			frame.put(SP);
@@ -570,6 +480,9 @@
Loading
570 480
			frame.put(HTTP_VERSION);
571 481
			frame.put(CRLF);
572 482
			append(frame, HOST, host);
483 +
			if (proxyAuth != null) {
484 +
				append(frame, PROXY_AUTHORIZATION, proxyAuth);
485 +
			}
573 486
574 487
			Iterator<byte[]> i = headers.iterator();
575 488
			

@@ -0,0 +1,303 @@
Loading
1 +
/*
2 +
 * -------------------------------- MIT License --------------------------------
3 +
 * 
4 +
 * Copyright (c) 2021 SNF4J contributors
5 +
 * 
6 +
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 +
 * of this software and associated documentation files (the "Software"), to deal
8 +
 * in the Software without restriction, including without limitation the rights
9 +
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 +
 * copies of the Software, and to permit persons to whom the Software is
11 +
 * furnished to do so, subject to the following conditions:
12 +
 * 
13 +
 * The above copyright notice and this permission notice shall be included in all
14 +
 * copies or substantial portions of the Software.
15 +
 * 
16 +
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 +
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 +
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 +
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 +
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 +
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 +
 * SOFTWARE.
23 +
 *
24 +
 * -----------------------------------------------------------------------------
25 +
 */
26 +
package org.snf4j.core.util;
27 +
28 +
import java.nio.charset.Charset;
29 +
import java.util.Arrays;
30 +
31 +
/**
32 +
 * A class with Base64 utility functions.
33 +
 * <p>
34 +
 * For JDK8 and above it uses the {@link java.util.Base64 java.util.Base64}
35 +
 * implementation.
36 +
 * 
37 +
 * @author <a href="http://snf4j.org">SNF4J.ORG</a>
38 +
 */
39 +
public final class Base64Util {
40 +
41 +
	private final static byte PAD = (byte) '=';
42 +
43 +
	private final static int PAD_INDEX = 64;
44 +
45 +
	private final static byte[] ALPHABET = new byte[('Z' - 'A' + 1) * 2 + 10 + 2 + 1];
46 +
47 +
	private final static byte[] DECODING = new byte[256];
48 +
49 +
	private final static String JAVA_UTIL_BASE64 = "java.util.Base64";
50 +
51 +
	private final static boolean USE_JDK;
52 +
53 +
	static {
54 +
		int i = 0;
55 +
56 +
		for (byte c = 'A'; c <= 'Z'; c++) {
57 +
			ALPHABET[i++] = c;
58 +
		}
59 +
		for (byte c = 'a'; c <= 'z'; c++) {
60 +
			ALPHABET[i++] = c;
61 +
		}
62 +
		for (byte c = '0'; c <= '9'; c++) {
63 +
			ALPHABET[i++] = c;
64 +
		}
65 +
		ALPHABET[i++] = '+';
66 +
		ALPHABET[i++] = '/';
67 +
		ALPHABET[i++] = PAD;
68 +
69 +
		Arrays.fill(DECODING, (byte) -1);
70 +
		for (i = 0; i < ALPHABET.length - 1; ++i) {
71 +
			DECODING[ALPHABET[i]] = (byte) i;
72 +
		}
73 +
		USE_JDK = isClass(JAVA_UTIL_BASE64);
74 +
	}
75 +
76 +
	private Base64Util() {
77 +
	}
78 +
79 +
	static boolean isClass(String className) {
80 +
		try {
81 +
			Class.forName(className);
82 +
			return true;
83 +
		} catch (Exception e) {
84 +
			return false;
85 +
		}
86 +
	}
87 +
88 +
	static byte[] encode(byte[] data, boolean useJdk) {
89 +
		if (useJdk) {
90 +
			return java.util.Base64.getEncoder().encode(data);
91 +
		}
92 +
		return encode0(data);
93 +
	}
94 +
95 +
	/**
96 +
	 * Encodes bytes from the specified byte array into a newly-allocated byte array
97 +
	 * using the Base64 encoding scheme.
98 +
	 * <p>
99 +
	 * It uses "The Base 64 Alphabet" as specified in Table 1 of RFC 4648.
100 +
	 * 
101 +
	 * @param data the byte array to encode
102 +
	 * @return A newly-allocated byte array containing the resulting encoded bytes
103 +
	 */
104 +
	public static byte[] encode(byte[] data) {
105 +
		return encode(data, USE_JDK);
106 +
	}
107 +
108 +
	/**
109 +
	 * Encodes the specified byte array into a String using the Base64 encoding
110 +
	 * scheme.
111 +
	 * <p>
112 +
	 * It first encodes input bytes into a base64 encoded byte array by calling the
113 +
	 * {@link #encode(byte[])} method and then constructs a new String by using the
114 +
	 * encoded byte array and the specified charset.
115 +
	 * 
116 +
	 * @param data    the byte array to encode
117 +
	 * @param charset the charset used to encode the resulting String
118 +
	 * @return A String containing the resulting Base64 encoded characters
119 +
	 */
120 +
	public static String encode(byte[] data, Charset charset) {
121 +
		return new String(encode(data, USE_JDK), charset);
122 +
	}
123 +
124 +
	static byte[] encode0(byte[] data) {
125 +
		int len = data.length;
126 +
127 +
		if (len == 0) {
128 +
			return data;
129 +
		}
130 +
131 +
		byte[] encoded = new byte[(len / 3 + (len % 3 == 0 ? 0 : 1)) * 4];
132 +
		int c = 0, i = 0;
133 +
		int i1, i2, i3, i4;
134 +
135 +
		for (; i < len; i += 3) {
136 +
			if (i + 3 > len) {
137 +
				break;
138 +
			}
139 +
140 +
			i1 = data[i] >>> 2 & 0x3f;
141 +
			i2 = (data[i] << 4 | data[i + 1] >>> 4 & 0x0f) & 0x3f;
142 +
			i3 = (data[i + 1] << 2 | data[i + 2] >>> 6 & 0x03) & 0x3f;
143 +
			i4 = data[i + 2] & 0x3f;
144 +
145 +
			encoded[c++] = ALPHABET[i1];
146 +
			encoded[c++] = ALPHABET[i2];
147 +
			encoded[c++] = ALPHABET[i3];
148 +
			encoded[c++] = ALPHABET[i4];
149 +
		}
150 +
151 +
		switch (len - i) {
152 +
		case 1:
153 +
			i1 = data[i] >>> 2 & 0x3f;
154 +
			i2 = data[i] << 4 & 0x3f;
155 +
			i3 = PAD_INDEX;
156 +
			i4 = PAD_INDEX;
157 +
			break;
158 +
159 +
		case 2:
160 +
			i1 = data[i] >>> 2 & 0x3f;
161 +
			i2 = (data[i] << 4 | data[i + 1] >>> 4 & 0x0f) & 0x3f;
162 +
			i3 = data[i + 1] << 2 & 0x3f;
163 +
			i4 = PAD_INDEX;
164 +
			break;
165 +
166 +
		default:
167 +
			return encoded;
168 +
		}
169 +
170 +
		encoded[c++] = ALPHABET[i1];
171 +
		encoded[c++] = ALPHABET[i2];
172 +
		encoded[c++] = ALPHABET[i3];
173 +
		encoded[c++] = ALPHABET[i4];
174 +
		return encoded;
175 +
	}
176 +
177 +
	static String encode0(byte[] data, Charset charset) {
178 +
		return new String(encode0(data), charset);
179 +
	}
180 +
181 +
	static byte[] decode(byte[] data, boolean useJdk) {
182 +
		if (useJdk) {
183 +
			return java.util.Base64.getDecoder().decode(data);
184 +
		}
185 +
186 +
		byte[] encoded = decode0(data);
187 +
188 +
		if (encoded == null) {
189 +
			throw new IllegalArgumentException("data is not in valid Base64 scheme");
190 +
		}
191 +
		return encoded;
192 +
	}
193 +
194 +
	/**
195 +
	 * Decodes bytes from the specified byte array into a newly-allocated byte array
196 +
	 * using the Base64 encoding scheme.
197 +
	 * <p>
198 +
	 * It uses "The Base 64 Alphabet" as specified in Table 1 of RFC 4648.
199 +
	 * 
200 +
	 * @param data the byte array to decode
201 +
	 * @return A newly-allocated byte array containing the resulting decoded bytes
202 +
	 * @throws IllegalArgumentException - if the data is not in valid Base64 scheme
203 +
	 */
204 +
	public static byte[] decode(byte[] data) {
205 +
		return decode(data, USE_JDK);
206 +
	}
207 +
208 +
	/**
209 +
	 * Decodes a Base64 encoded String into a newly-allocated byte array using the
210 +
	 * Base64 encoding scheme.
211 +
	 * <p>
212 +
	 * It first decodes the Base64 encoded String into a sequence of bytes using the
213 +
	 * given charset and then decode the bytes by calling the
214 +
	 * {@link #decode(byte[])} method.
215 +
	 * 
216 +
	 * @param data    the string to decode
217 +
	 * @param charset The charset to be used to encode the String
218 +
	 * @return A newly-allocated byte array containing the resulting decoded bytes
219 +
	 * @throws IllegalArgumentException - if the data is not in valid Base64 scheme
220 +
	 */
221 +
	public static byte[] decode(String data, Charset charset) {
222 +
		return decode(data.getBytes(charset), USE_JDK);
223 +
	}
224 +
225 +
	static byte[] decode0(byte[] data) {
226 +
		int len = data.length;
227 +
228 +
		if (len == 0) {
229 +
			return data;
230 +
		} else if (len < 2) {
231 +
			return null;
232 +
		}
233 +
234 +
		if (data[len - 1] == PAD) {
235 +
			--len;
236 +
			if (data[len - 1] == PAD) {
237 +
				--len;
238 +
			}
239 +
		}
240 +
241 +
		if (len == 0) {
242 +
			return new byte[0];
243 +
		}
244 +
245 +
		int calcLen = (len / 4) * 3;
246 +
247 +
		switch (len & 0x03) {
248 +
		case 1:
249 +
			return null;
250 +
251 +
		case 2:
252 +
			calcLen++;
253 +
			break;
254 +
255 +
		case 3:
256 +
			calcLen += 2;
257 +
258 +
		default:
259 +
		}
260 +
261 +
		byte[] decoded = new byte[calcLen];
262 +
		int d = 0, i = 0;
263 +
		int v, jlen, shift;
264 +
265 +
		for (; i < len; i += 4) {
266 +
			jlen = len - i;
267 +
			if (jlen > 4) {
268 +
				jlen = 4;
269 +
				shift = 0;
270 +
			} else {
271 +
				shift = (4 - jlen) * 6;
272 +
			}
273 +
274 +
			v = 0;
275 +
			for (int j = 0; j < jlen; ++j) {
276 +
				byte c = DECODING[data[i + j] & 0xff];
277 +
278 +
				if (c == -1) {
279 +
					return null;
280 +
				}
281 +
				v <<= 6;
282 +
				v |= c;
283 +
			}
284 +
			if (shift > 0) {
285 +
				decoded[d++] = (byte) (v >> (16 - shift));
286 +
				if (shift == 6) {
287 +
					decoded[d++] = (byte) (v >> (8 - shift));
288 +
				}
289 +
			} else {
290 +
				decoded[d++] = (byte) (v >> 16);
291 +
				decoded[d++] = (byte) (v >> 8);
292 +
				decoded[d++] = (byte) v;
293 +
			}
294 +
		}
295 +
296 +
		return decoded;
297 +
	}
298 +
299 +
	static byte[] decode0(String data, Charset charset) {
300 +
		return decode0(data.getBytes(charset));
301 +
	}
302 +
303 +
}

@@ -47,78 +47,54 @@
Loading
47 47
	
48 48
	private final static Object CONNECTION_TIMER_EVENT = new Object();
49 49
	
50 -
	private final long connectionTimeout;
50 +
	private volatile long connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
51 51
	
52 52
	private final ISessionStructureFactory factory;
53 53
54 54
	private ITimerTask connectionTimer;
55 55
	
56 56
	/**
57 -
	 * Constructs a proxy connection handler with the specified connection timeout,
58 -
	 * configuration and factory.
57 +
	 * Constructs a proxy connection handler with the default (10 seconds)
58 +
	 * connection timeout, configuration and factory.
59 59
	 * <p>
60 60
	 * NOTE: The connection timeout will have no effect if the associated session
61 61
	 * does not support a session timer.
62 62
	 * 
63 -
	 * @param connectionTimeout the proxy connection timeout in milliseconds, or
64 -
	 *                          {@code 0} to wait an infinite amount of time for the
65 -
	 *                          proxy connection.
66 -
	 * @param config            the session configuration object, or {@code null} to
67 -
	 *                          use the default configuration
68 -
	 * @param factory           the factory that will be used to configure the
69 -
	 *                          internal structure of the associated session, or
70 -
	 *                          {@code null} to use the default factory
63 +
	 * @param config  the session configuration object, or {@code null} to use the
64 +
	 *                default configuration
65 +
	 * @param factory the factory that will be used to configure the internal
66 +
	 *                structure of the associated session, or {@code null} to use
67 +
	 *                the default factory
71 68
	 */
72 -
	protected AbstractProxyHandler(long connectionTimeout, ISessionConfig config, ISessionStructureFactory factory) {
69 +
	protected AbstractProxyHandler(ISessionConfig config, ISessionStructureFactory factory) {
73 70
		super(config);
74 71
		this.factory = factory != null ? factory : DefaultSessionStructureFactory.DEFAULT;
75 -
		if (connectionTimeout < 0) {
76 -
			throw new IllegalArgumentException("connectionTimeout is negative");
77 -
		}
78 -
		this.connectionTimeout = connectionTimeout;
79 72
	}
80 -
73 +
	
81 74
	/**
82 -
	 * Constructs a proxy connection handler with the specified connection
83 -
	 * timeout.
75 +
	 * Configures the proxy connection timeout.
84 76
	 * <p>
85 77
	 * NOTE: The connection timeout will have no effect if the associated session
86 78
	 * does not support a session timer.
87 79
	 * 
88 -
	 * @param connectionTimeout the proxy connection timeout in milliseconds, or
89 -
	 *                          {@code 0} to wait an infinite amount of time for the
90 -
	 *                          proxy connection.
91 -
	 */
92 -
	protected AbstractProxyHandler(long connectionTimeout) {
93 -
		this(connectionTimeout, null, null);
94 -
	}
95 -
96 -
	/**
97 -
	 * Constructs a proxy connection handler with the default (10 seconds)
98 -
	 * connection timeout.
99 -
	 * <p>
100 -
	 * NOTE: The connection timeout will have no effect if the associated session
101 -
	 * does not support a session timer.
80 +
	 * @param connectionTimeout the proxy connection timeout in milliseconds, or 0
81 +
	 *                          to wait an infinite amount of time for establishing
82 +
	 *                          the HTTP tunnel
83 +
	 * @return this handler
84 +
	 * @throws IllegalArgumentException if the connection timeout is negative 
102 85
	 */
103 -
	protected AbstractProxyHandler() {
104 -
		this(DEFAULT_CONNECTION_TIMEOUT, null, null);
86 +
	public AbstractProxyHandler connectionTimeout(long connectionTimeout) {
87 +
		if (connectionTimeout < 0) {
88 +
			throw new IllegalArgumentException("connectionTimeout is negative");
89 +
		}
90 +
		this.connectionTimeout = connectionTimeout;
91 +
		return this;
105 92
	}
106 -
107 -
	/**
108 -
	 * Constructs a proxy connection handler with the default (10 seconds)
109 -
	 * connection timeout, configuration and factory.
110 -
	 * <p>
111 -
	 * NOTE: The connection timeout will have no effect if the associated session
112 -
	 * does not support a session timer.
113 -
	 * 
114 -
	 * @param config  the session configuration object, or {@code null} to use the
115 -
	 *                default configuration
116 -
	 * @param factory the factory that will be used to configure the internal
117 -
	 *                structure of the associated session, or {@code null} to use
118 -
	 *                the default factory
119 -
	 */
120 -
	protected AbstractProxyHandler(ISessionConfig config, ISessionStructureFactory factory) {
121 -
		this(DEFAULT_CONNECTION_TIMEOUT, config, factory);
93 +
	
94 +
	final void checkNull(Object value, String name) {
95 +
		if (value == null) {
96 +
			throw new IllegalArgumentException(name + " is null");
97 +
		}
122 98
	}
123 99
	
124 100
	@Override

@@ -51,30 +51,6 @@
Loading
51 51
	private List<ISocksReplyListener> replyListeners;
52 52
	
53 53
	volatile AbstractSocksState state;
54 -
	
55 -
	/**
56 -
	 * Constructs a SOCKS proxy connection handler with the specified destination
57 -
	 * address, connection timeout, configuration and factory.
58 -
	 * <p>
59 -
	 * NOTE: The connection timeout will have no effect if the associated session
60 -
	 * does not support a session timer.
61 -
	 * 
62 -
	 * @param address           the destination address
63 -
	 * @param connectionTimeout the SOCKS proxy connection timeout in milliseconds,
64 -
	 *                          or {@code 0} to wait an infinite amount of time for
65 -
	 *                          establishing of the SOCKS connection.
66 -
	 * @param config            the session configuration object, or {@code null} to
67 -
	 *                          use the default configuration
68 -
	 * @param factory           the factory that will be used to configure the
69 -
	 *                          internal structure of the associated session, or
70 -
	 *                          {@code null} to use the default factory
71 -
	 * @throws IllegalArgumentException if the address is null
72 -
	 */
73 -
	protected AbstractSocksProxyHandler(InetSocketAddress address, long connectionTimeout, ISessionConfig config, ISessionStructureFactory factory) {
74 -
		super(connectionTimeout, config, factory);
75 -
		checkNull(address, "address");
76 -
		this.address = address;
77 -
	}
78 54
79 55
	/**
80 56
	 * Constructs a SOCKS proxy connection handler with the specified destination
@@ -97,12 +73,6 @@
Loading
97 73
		this.address = address;
98 74
	}
99 75
	
100 -
	final void checkNull(Object value, String name) {
101 -
		if (value == null) {
102 -
			throw new IllegalArgumentException(name + " is null");
103 -
		}
104 -
	}
105 -
	
106 76
	/**
107 77
	 * Returns the destination address.
108 78
	 * 

@@ -255,252 +255,6 @@
Loading
255 255
		this(address, command, username, password, config, null);
256 256
	}
257 257
	
258 -
	/**
259 -
	 * Constructs a SOCKS5 proxy connection handler with the specified destination
260 -
	 * address, the default ({@link Socks5Command#CONNECT CONNECT}) command and
261 -
	 * connection timeout.
262 -
	 * <p>
263 -
	 * NOTE: The connection timeout will have no effect if the associated session
264 -
	 * does not support a session timer.
265 -
	 * 
266 -
	 * @param address           the destination address to the host to which the
267 -
	 *                          connection should be proxied
268 -
	 * @param connectionTimeout the SOCKS5 proxy connection timeout in milliseconds,
269 -
	 *                          or {@code 0} to wait an infinite amount of time for
270 -
	 *                          establishing of the SOCKS5 connection.
271 -
	 * @throws IllegalArgumentException if the address is null
272 -
	 */
273 -
	public Socks5ProxyHandler(InetSocketAddress address, long connectionTimeout) {
274 -
		this(address, Socks5Command.CONNECT, null, null, connectionTimeout, null, null);
275 -
	}
276 -
	
277 -
	/**
278 -
	 * Constructs a SOCKS5 proxy connection handler with the specified destination
279 -
	 * address, the default ({@link Socks5Command#CONNECT CONNECT}) command,
280 -
	 * connection timeout and configuration.
281 -
	 * <p>
282 -
	 * NOTE: The connection timeout will have no effect if the associated session
283 -
	 * does not support a session timer.
284 -
	 * 
285 -
	 * @param address           the destination address to the host to which the
286 -
	 *                          connection should be proxied
287 -
	 * @param connectionTimeout the SOCKS5 proxy connection timeout in milliseconds,
288 -
	 *                          or {@code 0} to wait an infinite amount of time for
289 -
	 *                          establishing of the SOCKS5 connection.
290 -
	 * @param config            the session configuration object, or {@code null} to
291 -
	 *                          use the default configuration
292 -
	 * @throws IllegalArgumentException if the address is null
293 -
	 */
294 -
	public Socks5ProxyHandler(InetSocketAddress address, long connectionTimeout, ISessionConfig config) {
295 -
		this(address, Socks5Command.CONNECT, null, null, connectionTimeout, config, null);
296 -
	}
297 -
298 -
	/**
299 -
	 * Constructs a SOCKS5 proxy connection handler with the specified destination
300 -
	 * address, the default ({@link Socks5Command#CONNECT CONNECT}) command,
301 -
	 * connection timeout, configuration and factory.
302 -
	 * <p>
303 -
	 * NOTE: The connection timeout will have no effect if the associated session
304 -
	 * does not support a session timer.
305 -
	 * 
306 -
	 * @param address           the destination address to the host to which the
307 -
	 *                          connection should be proxied
308 -
	 * @param connectionTimeout the SOCKS5 proxy connection timeout in milliseconds,
309 -
	 *                          or {@code 0} to wait an infinite amount of time for
310 -
	 *                          establishing of the SOCKS5 connection.
311 -
	 * @param config            the session configuration object, or {@code null} to
312 -
	 *                          use the default configuration
313 -
	 * @param factory           the factory that will be used to configure the
314 -
	 *                          internal structure of the associated session, or
315 -
	 *                          {@code null} to use the default factory
316 -
	 * @throws IllegalArgumentException if the address is null
317 -
	 */
318 -
	public Socks5ProxyHandler(InetSocketAddress address, long connectionTimeout, ISessionConfig config, ISessionStructureFactory factory) {
319 -
		this(address, Socks5Command.CONNECT, null, null, connectionTimeout, config, factory);
320 -
	}
321 -
322 -
	/**
323 -
	 * Constructs a SOCKS5 proxy connection handler with the specified destination
324 -
	 * address, the default ({@link Socks5Command#CONNECT CONNECT}) command, user's
325 -
	 * name/password and connection timeout.
326 -
	 * <p>
327 -
	 * NOTE: The connection timeout will have no effect if the associated session
328 -
	 * does not support a session timer.
329 -
	 * 
330 -
	 * @param address           the destination address to the host to which the
331 -
	 *                          connection should be proxied
332 -
	 * @param username          the user's name, or {@code null} for an empty name
333 -
	 * @param password          the user's password, or {@code null} for an empty
334 -
	 *                          password
335 -
	 * @param connectionTimeout the SOCKS5 proxy connection timeout in milliseconds,
336 -
	 *                          or {@code 0} to wait an infinite amount of time for
337 -
	 *                          establishing of the SOCKS5 connection.
338 -
	 * @throws IllegalArgumentException if the address is null
339 -
	 */
340 -
	public Socks5ProxyHandler(InetSocketAddress address, String username, String password, long connectionTimeout) {
341 -
		this(address, Socks5Command.CONNECT, username, password, connectionTimeout, null, null);
342 -
	}
343 -
344 -
	/**
345 -
	 * Constructs a SOCKS5 proxy connection handler with the specified destination
346 -
	 * address, the default ({@link Socks5Command#CONNECT CONNECT}) command, user's
347 -
	 * name/password, connection timeout and configuration.
348 -
	 * <p>
349 -
	 * NOTE: The connection timeout will have no effect if the associated session
350 -
	 * does not support a session timer.
351 -
	 * 
352 -
	 * @param address           the destination address to the host to which the
353 -
	 *                          connection should be proxied
354 -
	 * @param username          the user's name, or {@code null} for an empty name
355 -
	 * @param password          the user's password, or {@code null} for an empty
356 -
	 *                          password
357 -
	 * @param connectionTimeout the SOCKS5 proxy connection timeout in milliseconds,
358 -
	 *                          or {@code 0} to wait an infinite amount of time for
359 -
	 *                          establishing of the SOCKS5 connection.
360 -
	 * @param config            the session configuration object, or {@code null} to
361 -
	 *                          use the default configuration
362 -
	 * @throws IllegalArgumentException if the address is null
363 -
	 */
364 -
	public Socks5ProxyHandler(InetSocketAddress address, String username, String password, long connectionTimeout, ISessionConfig config) {
365 -
		this(address, Socks5Command.CONNECT, username, password, connectionTimeout, config, null);
366 -
	}
367 -
368 -
	/**
369 -
	 * Constructs a SOCKS5 proxy connection handler with the specified destination
370 -
	 * address, the default ({@link Socks5Command#CONNECT CONNECT}) command, user's
371 -
	 * name/password, connection timeout, configuration and factory.
372 -
	 * <p>
373 -
	 * NOTE: The connection timeout will have no effect if the associated session
374 -
	 * does not support a session timer.
375 -
	 * 
376 -
	 * @param address           the destination address to the host to which the
377 -
	 *                          connection should be proxied
378 -
	 * @param username          the user's name, or {@code null} for an empty name
379 -
	 * @param password          the user's password, or {@code null} for an empty
380 -
	 *                          password
381 -
	 * @param connectionTimeout the SOCKS5 proxy connection timeout in milliseconds,
382 -
	 *                          or {@code 0} to wait an infinite amount of time for
383 -
	 *                          establishing of the SOCKS5 connection.
384 -
	 * @param config            the session configuration object, or {@code null} to
385 -
	 *                          use the default configuration
386 -
	 * @param factory           the factory that will be used to configure the
387 -
	 *                          internal structure of the associated session, or
388 -
	 *                          {@code null} to use the default factory
389 -
	 * @throws IllegalArgumentException if the address is null
390 -
	 */
391 -
	public Socks5ProxyHandler(InetSocketAddress address, String username, String password, long connectionTimeout, ISessionConfig config, ISessionStructureFactory factory) {
392 -
		this(address, Socks5Command.CONNECT, username, password, connectionTimeout, config, factory);
393 -
	}
394 -
	
395 -
	/**
396 -
	 * Constructs a SOCKS5 proxy connection handler with the specified destination
397 -
	 * address, SOCKS5 command and connection timeout.
398 -
	 * <p>
399 -
	 * NOTE: The connection timeout will have no effect if the associated session
400 -
	 * does not support a session timer.
401 -
	 * 
402 -
	 * @param address           the destination address to the host to which the
403 -
	 *                          connection should be proxied
404 -
	 * @param command           the SCOCS5 command
405 -
	 * @param connectionTimeout the SOCKS5 proxy connection timeout in milliseconds,
406 -
	 *                          or {@code 0} to wait an infinite amount of time for
407 -
	 *                          establishing of the SOCKS5 connection.
408 -
	 * @throws IllegalArgumentException if the address or the command is null
409 -
	 */
410 -
	public Socks5ProxyHandler(InetSocketAddress address, Socks5Command command, long connectionTimeout) {
411 -
		this(address, command, null, null, connectionTimeout, null, null);
412 -
	}
413 -
414 -
	/**
415 -
	 * Constructs a SOCKS5 proxy connection handler with the specified destination
416 -
	 * address, SOCKS5 command, connection timeout and configuration.
417 -
	 * <p>
418 -
	 * NOTE: The connection timeout will have no effect if the associated session
419 -
	 * does not support a session timer.
420 -
	 * 
421 -
	 * @param address           the destination address to the host to which the
422 -
	 *                          connection should be proxied
423 -
	 * @param command           the SCOCS5 command
424 -
	 * @param connectionTimeout the SOCKS5 proxy connection timeout in milliseconds,
425 -
	 *                          or {@code 0} to wait an infinite amount of time for
426 -
	 *                          establishing of the SOCKS5 connection.
427 -
	 * @param config            the session configuration object, or {@code null} to
428 -
	 *                          use the default configuration
429 -
	 * @throws IllegalArgumentException if the address or the command is null
430 -
	 */
431 -
	public Socks5ProxyHandler(InetSocketAddress address, Socks5Command command, long connectionTimeout, ISessionConfig config) {
432 -
		this(address, command, null, null, connectionTimeout, config, null);
433 -
	}
434 -
435 -
	/**
436 -
	 * Constructs a SOCKS5 proxy connection handler with the specified destination
437 -
	 * address, SOCKS5 command, connection timeout, configuration and factory.
438 -
	 * <p>
439 -
	 * NOTE: The connection timeout will have no effect if the associated session
440 -
	 * does not support a session timer.
441 -
	 * 
442 -
	 * @param address           the destination address to the host to which the
443 -
	 *                          connection should be proxied
444 -
	 * @param command           the SCOCS5 command
445 -
	 * @param connectionTimeout the SOCKS5 proxy connection timeout in milliseconds,
446 -
	 *                          or {@code 0} to wait an infinite amount of time for
447 -
	 *                          establishing of the SOCKS5 connection.
448 -
	 * @param config            the session configuration object, or {@code null} to
449 -
	 *                          use the default configuration
450 -
	 * @param factory           the factory that will be used to configure the
451 -
	 *                          internal structure of the associated session, or
452 -
	 *                          {@code null} to use the default factory
453 -
	 * @throws IllegalArgumentException if the address or the command is null
454 -
	 */
455 -
	public Socks5ProxyHandler(InetSocketAddress address, Socks5Command command, long connectionTimeout, ISessionConfig config, ISessionStructureFactory factory) {
456 -
		this(address, command, null, null, connectionTimeout, config, factory);
457 -
	}
458 -
459 -
	/**
460 -
	 * Constructs a SOCKS5 proxy connection handler with the specified destination
461 -
	 * address, SOCKS5 command, user's name/password and connection timeout.
462 -
	 * <p>
463 -
	 * NOTE: The connection timeout will have no effect if the associated session
464 -
	 * does not support a session timer.
465 -
	 * 
466 -
	 * @param address           the destination address to the host to which the
467 -
	 *                          connection should be proxied
468 -
	 * @param command           the SCOCS5 command
469 -
	 * @param username			the user's name, or {@code null} for an empty name
470 -
	 * @param password			the user's password, or {@code null} for an empty password
471 -
	 * @param connectionTimeout the SOCKS5 proxy connection timeout in milliseconds,
472 -
	 *                          or {@code 0} to wait an infinite amount of time for
473 -
	 *                          establishing of the SOCKS5 connection.
474 -
	 * @throws IllegalArgumentException if the address or the command is null
475 -
	 */
476 -
	public Socks5ProxyHandler(InetSocketAddress address, Socks5Command command, String username, String password, long connectionTimeout) {
477 -
		this(address, command, username, password, connectionTimeout, null, null);
478 -
	}
479 -
	
480 -
	/**
481 -
	 * Constructs a SOCKS5 proxy connection handler with the specified destination
482 -
	 * address, SOCKS5 command, user's name/password, connection timeout and 
483 -
	 * configuration.
484 -
	 * <p>
485 -
	 * NOTE: The connection timeout will have no effect if the associated session
486 -
	 * does not support a session timer.
487 -
	 * 
488 -
	 * @param address           the destination address to the host to which the
489 -
	 *                          connection should be proxied
490 -
	 * @param command           the SCOCS5 command
491 -
	 * @param username			the user's name, or {@code null} for an empty name
492 -
	 * @param password			the user's password, or {@code null} for an empty password
493 -
	 * @param connectionTimeout the SOCKS5 proxy connection timeout in milliseconds,
494 -
	 *                          or {@code 0} to wait an infinite amount of time for
495 -
	 *                          establishing of the SOCKS5 connection.
496 -
	 * @param config            the session configuration object, or {@code null} to
497 -
	 *                          use the default configuration
498 -
	 * @throws IllegalArgumentException if the address or the command is null
499 -
	 */
500 -
	public Socks5ProxyHandler(InetSocketAddress address, Socks5Command command, String username, String password, long connectionTimeout, ISessionConfig config) {
501 -
		this(address, command, username, password, connectionTimeout, config, null);
502 -
	}
503 -
504 258
	/**
505 259
	 * Constructs a SOCKS5 proxy connection handler with the specified destination
506 260
	 * address, SOCKS5 command, user's name/password, the default (10 seconds)
@@ -528,37 +282,6 @@
Loading
528 282
		passwordAuthState = new Socks5PasswordAuthState(this, username, password, commandState);
529 283
		state = state();
530 284
	}
531 -
	
532 -
	/**
533 -
	 * Constructs a SOCKS5 proxy connection handler with the specified destination
534 -
	 * address, SOCKS5 command, user's name/password, connection timeout, configuration and
535 -
	 * factory.
536 -
	 * <p>
537 -
	 * NOTE: The connection timeout will have no effect if the associated session
538 -
	 * does not support a session timer.
539 -
	 * 
540 -
	 * @param address           the destination address to the host to which the
541 -
	 *                          connection should be proxied
542 -
	 * @param command           the SCOCS5 command
543 -
	 * @param username			the user's name, or {@code null} for an empty name
544 -
	 * @param password			the user's password, or {@code null} for an empty password
545 -
	 * @param connectionTimeout the SOCKS5 proxy connection timeout in milliseconds,
546 -
	 *                          or {@code 0} to wait an infinite amount of time for
547 -
	 *                          establishing of the SOCKS5 connection.
548 -
	 * @param config            the session configuration object, or {@code null} to
549 -
	 *                          use the default configuration
550 -
	 * @param factory           the factory that will be used to configure the
551 -
	 *                          internal structure of the associated session, or
552 -
	 *                          {@code null} to use the default factory
553 -
	 * @throws IllegalArgumentException if the address or the command is null
554 -
	 */
555 -
	public Socks5ProxyHandler(InetSocketAddress address, Socks5Command command, String username, String password, long connectionTimeout, ISessionConfig config, ISessionStructureFactory factory) {
556 -
		super(address, connectionTimeout, config, factory);
557 -
		checkNull(command, "command");
558 -
		commandState = new Socks5CommandState(this, command);
559 -
		passwordAuthState = new Socks5PasswordAuthState(this, username, password, commandState);
560 -
		state = state();
561 -
	}
562 285
563 286
	private Socks5InitState state() {
564 287
		AbstractSocksState[] nextStates;
@@ -575,6 +298,17 @@
Loading
575 298
		return new Socks5InitState(this, authMethods, nextStates);
576 299
	}
577 300
	
301 +
	/**
302 +
	 * {@inheritDoc}
303 +
	 * 
304 +
	 * @throws IllegalArgumentException if the connection timeout is negative 
305 +
	 */
306 +
	@Override
307 +
	public Socks5ProxyHandler connectionTimeout(long connectionTimeout) {
308 +
		super.connectionTimeout(connectionTimeout);
309 +
		return this;
310 +
	}
311 +
578 312
	@Override
579 313
	String protocol() {
580 314
		return ISocks5.PROTOCOL;

@@ -132,115 +132,6 @@
Loading
132 132
		this(address, command, username, config, null);
133 133
	}
134 134
	
135 -
	/**
136 -
	 * Constructs a SOCKS4 proxy connection handler with the specified destination
137 -
	 * address, the default ({@link Socks4Command#CONNECT CONNECT}) command, user's
138 -
	 * name and connection timeout.
139 -
	 * <p>
140 -
	 * NOTE: The connection timeout will have no effect if the associated session
141 -
	 * does not support a session timer.
142 -
	 * 
143 -
	 * @param address           the destination address to the host to which the
144 -
	 *                          connection should be proxied
145 -
	 * @param username          the user's name, or {@code null} for an empty name
146 -
	 * @param connectionTimeout the SOCKS4 proxy connection timeout in milliseconds,
147 -
	 *                          or {@code 0} to wait an infinite amount of time for
148 -
	 *                          establishing of the SOCKS4 connection.
149 -
	 * @throws IllegalArgumentException if the address is null
150 -
	 */
151 -
	public Socks4ProxyHandler(InetSocketAddress address, String username, long connectionTimeout) {
152 -
		this(address, Socks4Command.CONNECT, username, connectionTimeout, null, null);
153 -
	}
154 -
155 -
	/**
156 -
	 * Constructs a SOCKS4 proxy connection handler with the specified destination
157 -
	 * address, the default ({@link Socks4Command#CONNECT CONNECT}) command, user's
158 -
	 * name, connection timeout and configuration.
159 -
	 * <p>
160 -
	 * NOTE: The connection timeout will have no effect if the associated session
161 -
	 * does not support a session timer.
162 -
	 * 
163 -
	 * @param address           the destination address to the host to which the
164 -
	 *                          connection should be proxied
165 -
	 * @param username          the user's name, or {@code null} for an empty name
166 -
	 * @param connectionTimeout the SOCKS4 proxy connection timeout in milliseconds,
167 -
	 *                          or {@code 0} to wait an infinite amount of time for
168 -
	 *                          establishing of the SOCKS4 connection.
169 -
	 * @param config            the session configuration object, or {@code null} to
170 -
	 *                          use the default configuration
171 -
	 * @throws IllegalArgumentException if the address is null
172 -
	 */
173 -
	public Socks4ProxyHandler(InetSocketAddress address, String username, long connectionTimeout, ISessionConfig config) {
174 -
		this(address, Socks4Command.CONNECT, username, connectionTimeout, config, null);
175 -
	}
176 -
	
177 -
	/**
178 -
	 * Constructs a SOCKS4 proxy connection handler with the specified destination
179 -
	 * address, the default ({@link Socks4Command#CONNECT CONNECT}) command, user's
180 -
	 * name, connection timeout, configuration and factory.
181 -
	 * <p>
182 -
	 * NOTE: The connection timeout will have no effect if the associated session
183 -
	 * does not support a session timer.
184 -
	 * 
185 -
	 * @param address           the destination address to the host to which the
186 -
	 *                          connection should be proxied
187 -
	 * @param username          the user's name, or {@code null} for an empty name
188 -
	 * @param connectionTimeout the SOCKS4 proxy connection timeout in milliseconds,
189 -
	 *                          or {@code 0} to wait an infinite amount of time for
190 -
	 *                          establishing of the SOCKS4 connection.
191 -
	 * @param config            the session configuration object, or {@code null} to
192 -
	 *                          use the default configuration
193 -
	 * @param factory           the factory that will be used to configure the
194 -
	 *                          internal structure of the associated session, or
195 -
	 *                          {@code null} to use the default factory
196 -
	 * @throws IllegalArgumentException if the address is null
197 -
	 */
198 -
	public Socks4ProxyHandler(InetSocketAddress address, String username, long connectionTimeout, ISessionConfig config, ISessionStructureFactory factory) {
199 -
		this(address, Socks4Command.CONNECT, username, connectionTimeout, config, factory);
200 -
	}
201 -
202 -
	/**
203 -
	 * Constructs a SOCKS4 proxy connection handler with the specified destination
204 -
	 * address, SOCKS4 command, user's name and connection timeout.
205 -
	 * <p>
206 -
	 * NOTE: The connection timeout will have no effect if the associated session
207 -
	 * does not support a session timer.
208 -
	 * 
209 -
	 * @param address           the destination address to the host to which the
210 -
	 *                          connection should be proxied
211 -
	 * @param command           the SCOCS4 command
212 -
	 * @param username			the user's name, or {@code null} for an empty name
213 -
	 * @param connectionTimeout the SOCKS4 proxy connection timeout in milliseconds,
214 -
	 *                          or {@code 0} to wait an infinite amount of time for
215 -
	 *                          establishing of the SOCKS4 connection.
216 -
	 * @throws IllegalArgumentException if the address or the command is null
217 -
	 */
218 -
	public Socks4ProxyHandler(InetSocketAddress address, Socks4Command command, String username, long connectionTimeout) {
219 -
		this(address, command, username, connectionTimeout, null, null);
220 -
	}
221 -
222 -
	/**
223 -
	 * Constructs a SOCKS4 proxy connection handler with the specified destination
224 -
	 * address, SOCKS4 command, user's name, connection timeout and configuration.
225 -
	 * <p>
226 -
	 * NOTE: The connection timeout will have no effect if the associated session
227 -
	 * does not support a session timer.
228 -
	 * 
229 -
	 * @param address           the destination address to the host to which the
230 -
	 *                          connection should be proxied
231 -
	 * @param command           the SCOCS4 command
232 -
	 * @param username			the user's name, or {@code null} for an empty name
233 -
	 * @param connectionTimeout the SOCKS4 proxy connection timeout in milliseconds,
234 -
	 *                          or {@code 0} to wait an infinite amount of time for
235 -
	 *                          establishing of the SOCKS4 connection.
236 -
	 * @param config            the session configuration object, or {@code null} to
237 -
	 *                          use the default configuration
238 -
	 * @throws IllegalArgumentException if the address or the command is null
239 -
	 */
240 -
	public Socks4ProxyHandler(InetSocketAddress address, Socks4Command command, String username, long connectionTimeout, ISessionConfig config) {
241 -
		this(address, command, username, connectionTimeout, config, null);
242 -
	}
243 -
	
244 135
	/**
245 136
	 * Constructs a SOCKS4 proxy connection handler with the specified destination
246 137
	 * address, SOCKS4 command, user's name, the default (10 seconds) connection
@@ -267,31 +158,14 @@
Loading
267 158
	}
268 159
	
269 160
	/**
270 -
	 * Constructs a SOCKS4 proxy connection handler with the specified destination
271 -
	 * address, SOCKS4 command, user's name, connection timeout, configuration and
272 -
	 * factory.
273 -
	 * <p>
274 -
	 * NOTE: The connection timeout will have no effect if the associated session
275 -
	 * does not support a session timer.
161 +
	 * {@inheritDoc}
276 162
	 * 
277 -
	 * @param address           the destination address to the host to which the
278 -
	 *                          connection should be proxied
279 -
	 * @param command           the SCOCS4 command
280 -
	 * @param username			the user's name, or {@code null} for an empty name
281 -
	 * @param connectionTimeout the SOCKS4 proxy connection timeout in milliseconds,
282 -
	 *                          or {@code 0} to wait an infinite amount of time for
283 -
	 *                          establishing of the SOCKS4 connection.
284 -
	 * @param config            the session configuration object, or {@code null} to
285 -
	 *                          use the default configuration
286 -
	 * @param factory           the factory that will be used to configure the
287 -
	 *                          internal structure of the associated session, or
288 -
	 *                          {@code null} to use the default factory
289 -
	 * @throws IllegalArgumentException if the address or the command is null
163 +
	 * @throws IllegalArgumentException if the connection timeout is negative 
290 164
	 */
291 -
	public Socks4ProxyHandler(InetSocketAddress address, Socks4Command command, String username, long connectionTimeout, ISessionConfig config, ISessionStructureFactory factory) {
292 -
		super(address, connectionTimeout, config, factory);
293 -
		checkNull(command, "command");
294 -
		state = new Socks4CommandState(this, command, username);
165 +
	@Override
166 +
	public Socks4ProxyHandler connectionTimeout(long connectionTimeout) {
167 +
		super.connectionTimeout(connectionTimeout);
168 +
		return this;
295 169
	}
296 170
297 171
	@Override
Files Coverage
snf4j-core-log4j2/src/main/java/org/snf4j/core/logger/impl 96.66%
snf4j-core-slf4j/src/main/java/org/snf4j/core/logger/impl 96.66%
snf4j-core/src/main/java/org/snf4j/core 97.85%
snf4j-sctp/src/main/java/org/snf4j/core 98.56%
snf4j-websocket/src/main/java/org/snf4j/websocket 99.37%
Project Totals (219 files) 98.16%
codecov-umbrella
Build #1471549757 -
1
coverage:
2
  range: "70...100"
3
  round: down
4
  precision: 2
5
  
6
  status:
7
    project:
8
      default:
9
        enabled: yes
10
        target: 94%
11
        threshold: 5%
12
        
13
    patch:
14
      default:
15
        enabled: yes
16
        target: 85%
17
        threshold: 5%
18
        
19
    changes: no
20
    
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading