From 08328d23fa2628994b249663d839bc13a0f1e6c1 Mon Sep 17 00:00:00 2001 From: V2Ray Date: Wed, 28 Oct 2015 12:13:27 +0100 Subject: [PATCH] beginning of http proxy --- proxy/http/config/json/json.go | 15 ++++++++++++++ proxy/http/http.go | 36 ++++++++++++++++++++++++++++++++++ proxy/vmess/vmessin.go | 2 +- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 proxy/http/config/json/json.go create mode 100644 proxy/http/http.go diff --git a/proxy/http/config/json/json.go b/proxy/http/config/json/json.go new file mode 100644 index 000000000..7049a56e7 --- /dev/null +++ b/proxy/http/config/json/json.go @@ -0,0 +1,15 @@ +package json + +import ( + "github.com/v2ray/v2ray-core/config" + "github.com/v2ray/v2ray-core/config/json" +) + +type HttpProxyConfig struct { +} + +func init() { + json.RegisterConfigType("http", config.TypeInbound, func() interface{} { + return new(HttpProxyConfig) + }) +} diff --git a/proxy/http/http.go b/proxy/http/http.go new file mode 100644 index 000000000..881c5d27a --- /dev/null +++ b/proxy/http/http.go @@ -0,0 +1,36 @@ +package http + +import ( + "net" + // "net/http" + + "github.com/v2ray/v2ray-core/app" + "github.com/v2ray/v2ray-core/common/log" + jsonconfig "github.com/v2ray/v2ray-core/proxy/http/config/json" +) + +type HttpProxyServer struct { + accepting bool + dispatcher app.PacketDispatcher + config *jsonconfig.HttpProxyConfig +} + +func NewHttpProxyServer(dispatcher app.PacketDispatcher, config *jsonconfig.HttpProxyConfig) *HttpProxyServer { + return &HttpProxyServer{ + dispatcher: dispatcher, + config: config, + } +} + +func (server *HttpProxyServer) Listen(port uint16) error { + _, err := net.ListenTCP("tcp", &net.TCPAddr{ + IP: []byte{0, 0, 0, 0}, + Port: int(port), + Zone: "", + }) + if err != nil { + log.Error("HTTP Proxy failed to listen on port %d: %v", port, err) + return err + } + return nil +} diff --git a/proxy/vmess/vmessin.go b/proxy/vmess/vmessin.go index 76a344a14..8a14e0fe6 100644 --- a/proxy/vmess/vmessin.go +++ b/proxy/vmess/vmessin.go @@ -91,7 +91,7 @@ func (handler *VMessInboundHandler) HandleConnection(connection *net.TCPConn) er readFinish.Lock() writeFinish.Lock() - connReader.SetTimeOut(120) + connReader.SetTimeOut(120) go handleInput(request, connReader, input, &readFinish) responseKey := md5.Sum(request.RequestKey)