This commit is contained in:
地平线
2015-09-30 17:53:35 +08:00
parent 4d2020f856
commit 36da33756f
4 changed files with 7 additions and 34 deletions

View File

@@ -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);
}
}

View File

@@ -13,10 +13,11 @@ import java.nio.*;
import java.nio.channels.*;
/**
* 在appliation.xml中的HTTP类型的server节点加上forwardproxy="true"表示该HttpServer支持正向代理
* 正向代理
*
* @author zhangjx
*/
@AutoLoad(false)
public final class SocksProxyServlet extends SocksServlet {
protected static final byte[] LINE = new byte[]{'\r', '\n'};

View File

@@ -21,13 +21,13 @@ public class SocksRequest extends HttpRequest {
private short requestid;
protected SocksRequest(SocksContext context) {
protected SocksRequest(HttpContext context) {
super(context, JsonFactory.root(), null);
}
@Override
protected int readHeader(ByteBuffer buffer) {
if (buffer.remaining() > 3) {
if (buffer.get(0) > 0x05 && buffer.remaining() > 3) {
this.http = true;
return super.readHeader(buffer);
}

View File

@@ -6,6 +6,7 @@
package com.wentch.redkale.net.socks;
import com.wentch.redkale.net.*;
import com.wentch.redkale.net.http.*;
import com.wentch.redkale.util.*;
import com.wentch.redkale.watch.*;
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 cycleResponseCounter = watch == null ? new AtomicLong() : watch.createWatchNumber("SOCKS_" + port + ".Response.cycleCounter");
ObjectPool<Response> responsePool = SocksResponse.createPool(createResponseCounter, cycleResponseCounter, this.responsePoolSize, null);
SocksContext localcontext = new SocksContext(this.serverStartTime, this.logger, executor, bufferPool, responsePool,
this.maxbody, this.charset, this.address, this.prepare, this.watch, this.readTimeoutSecond, this.writeTimeoutSecond);
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, "");
responsePool.setCreator((Object... params) -> new SocksResponse(localcontext, new SocksRequest(localcontext)));
return localcontext;
}