This commit is contained in:
@@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
package com.wentch.redkale.net.socks;
|
|
||||||
|
|
||||||
import com.wentch.redkale.net.*;
|
|
||||||
import com.wentch.redkale.util.*;
|
|
||||||
import com.wentch.redkale.watch.*;
|
|
||||||
import java.net.*;
|
|
||||||
import java.nio.*;
|
|
||||||
import java.nio.charset.*;
|
|
||||||
import java.util.concurrent.*;
|
|
||||||
import java.util.logging.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author zhangjx
|
|
||||||
*/
|
|
||||||
public class SocksContext extends Context {
|
|
||||||
|
|
||||||
public SocksContext(long serverStartTime, Logger logger, ExecutorService executor, ObjectPool<ByteBuffer> bufferPool,
|
|
||||||
ObjectPool<Response> responsePool, int maxbody, Charset charset, InetSocketAddress address, PrepareServlet prepare,
|
|
||||||
WatchFactory watch, int readTimeoutSecond, int writeTimeoutSecond) {
|
|
||||||
super(serverStartTime, logger, executor, bufferPool, responsePool, maxbody, charset,
|
|
||||||
address, prepare, watch, readTimeoutSecond, writeTimeoutSecond);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -13,10 +13,11 @@ import java.nio.*;
|
|||||||
import java.nio.channels.*;
|
import java.nio.channels.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在appliation.xml中的HTTP类型的server节点加上forwardproxy="true"表示该HttpServer支持正向代理
|
* 正向代理
|
||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
|
@AutoLoad(false)
|
||||||
public final class SocksProxyServlet extends SocksServlet {
|
public final class SocksProxyServlet extends SocksServlet {
|
||||||
|
|
||||||
protected static final byte[] LINE = new byte[]{'\r', '\n'};
|
protected static final byte[] LINE = new byte[]{'\r', '\n'};
|
||||||
|
|||||||
@@ -21,13 +21,13 @@ public class SocksRequest extends HttpRequest {
|
|||||||
|
|
||||||
private short requestid;
|
private short requestid;
|
||||||
|
|
||||||
protected SocksRequest(SocksContext context) {
|
protected SocksRequest(HttpContext context) {
|
||||||
super(context, JsonFactory.root(), null);
|
super(context, JsonFactory.root(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int readHeader(ByteBuffer buffer) {
|
protected int readHeader(ByteBuffer buffer) {
|
||||||
if (buffer.remaining() > 3) {
|
if (buffer.get(0) > 0x05 && buffer.remaining() > 3) {
|
||||||
this.http = true;
|
this.http = true;
|
||||||
return super.readHeader(buffer);
|
return super.readHeader(buffer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
package com.wentch.redkale.net.socks;
|
package com.wentch.redkale.net.socks;
|
||||||
|
|
||||||
import com.wentch.redkale.net.*;
|
import com.wentch.redkale.net.*;
|
||||||
|
import com.wentch.redkale.net.http.*;
|
||||||
import com.wentch.redkale.util.*;
|
import com.wentch.redkale.util.*;
|
||||||
import com.wentch.redkale.watch.*;
|
import com.wentch.redkale.watch.*;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
@@ -50,8 +51,8 @@ public final class SocksServer extends Server {
|
|||||||
AtomicLong createResponseCounter = watch == null ? new AtomicLong() : watch.createWatchNumber("SOCKS_" + port + ".Response.creatCounter");
|
AtomicLong createResponseCounter = watch == null ? new AtomicLong() : watch.createWatchNumber("SOCKS_" + port + ".Response.creatCounter");
|
||||||
AtomicLong cycleResponseCounter = watch == null ? new AtomicLong() : watch.createWatchNumber("SOCKS_" + port + ".Response.cycleCounter");
|
AtomicLong cycleResponseCounter = watch == null ? new AtomicLong() : watch.createWatchNumber("SOCKS_" + port + ".Response.cycleCounter");
|
||||||
ObjectPool<Response> responsePool = SocksResponse.createPool(createResponseCounter, cycleResponseCounter, this.responsePoolSize, null);
|
ObjectPool<Response> responsePool = SocksResponse.createPool(createResponseCounter, cycleResponseCounter, this.responsePoolSize, null);
|
||||||
SocksContext localcontext = new SocksContext(this.serverStartTime, this.logger, executor, bufferPool, responsePool,
|
HttpContext localcontext = new HttpContext(this.serverStartTime, this.logger, executor, bufferPool, responsePool,
|
||||||
this.maxbody, this.charset, this.address, this.prepare, this.watch, this.readTimeoutSecond, this.writeTimeoutSecond);
|
this.maxbody, this.charset, this.address, this.prepare, this.watch, this.readTimeoutSecond, this.writeTimeoutSecond, "");
|
||||||
responsePool.setCreator((Object... params) -> new SocksResponse(localcontext, new SocksRequest(localcontext)));
|
responsePool.setCreator((Object... params) -> new SocksResponse(localcontext, new SocksRequest(localcontext)));
|
||||||
return localcontext;
|
return localcontext;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user