proxy: optimize NewConn, avoid loop

This commit is contained in:
nadoo committed 2020-10-11 18:46:15 +08:00
1 parent 40ddd1be3a
commit 6fff126e4b
6 files changed
+14 -13

No files matched your search

+3
View File
@@ -28,6 +28,9 @@ type Conn struct {
// NewConn returns a new conn.
func NewConn(c net.Conn) *Conn {
if conn, ok := c.(*Conn); ok {
return conn
}
return &Conn{bufio.NewReader(c), c}
}
+3 -9
View File
@@ -45,17 +45,11 @@ func (s *HTTP) ListenAndServe() {
func (s *HTTP) Serve(cc net.Conn) {
defer cc.Close()
var c *proxy.Conn
switch cc := cc.(type) {
case *proxy.Conn:
c = cc
case *net.TCPConn:
cc.SetKeepAlive(true)
c = proxy.NewConn(cc)
default:
c = proxy.NewConn(cc)
if c, ok := cc.(*net.TCPConn); ok {
c.SetKeepAlive(true)
}
c := proxy.NewConn(cc)
req, err := parseRequest(c.Reader())
if err != nil {
log.F("[http] can not parse request from %s", c.RemoteAddr())
+4
View File
@@ -96,6 +96,10 @@ func NewTLSServer(s string, p proxy.Proxy) (proxy.Server, error) {
return nil, err
}
if t.certFile == "" || t.keyFile == "" {
return nil, errors.New("[tls] cert and key file path must be spcified")
}
cert, err := stdtls.LoadX509KeyPair(t.certFile, t.keyFile)
if err != nil {
log.F("[tls] unable to load cert: %s, key %s", t.certFile, t.keyFile)
+1 -1
View File
@@ -54,9 +54,9 @@ func NewVLess(s string, d proxy.Dialer, p proxy.Proxy) (*VLess, error) {
proxy: p,
addr: addr,
uuid: uuid,
// fallback: "127.0.0.1:80",
}
// v.fallback = "127.0.0.1:80"
if custom := u.Query().Get("fallback"); custom != "" {
v.fallback = custom
}