From d04a786a85a37432e5913d804a12ea65df92fef0 Mon Sep 17 00:00:00 2001 From: kslr Date: Sun, 3 Jan 2021 07:11:59 +0800 Subject: [PATCH] Fix: http2: listen port failed use error level log ref https://github.com/v2fly/v2ray-core/issues/576 --- transport/internet/http/http_test.go | 4 ++-- transport/internet/http/hub.go | 19 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/transport/internet/http/http_test.go b/transport/internet/http/http_test.go index b1c3ef8a4..c7eeb622d 100644 --- a/transport/internet/http/http_test.go +++ b/transport/internet/http/http_test.go @@ -26,7 +26,7 @@ func TestHTTPConnection(t *testing.T) { ProtocolSettings: &Config{}, SecurityType: "tls", SecuritySettings: &tls.Config{ - Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil, cert.CommonName("www.v2ray.com")))}, + Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil, cert.CommonName("www.v2fly.org")))}, }, }, func(conn internet.Connection) { go func() { @@ -56,7 +56,7 @@ func TestHTTPConnection(t *testing.T) { ProtocolSettings: &Config{}, SecurityType: "tls", SecuritySettings: &tls.Config{ - ServerName: "www.v2ray.com", + ServerName: "www.v2fly.org", AllowInsecure: true, }, }) diff --git a/transport/internet/http/hub.go b/transport/internet/http/hub.go index 645b9101b..0e8600b75 100644 --- a/transport/internet/http/hub.go +++ b/transport/internet/http/hub.go @@ -4,10 +4,8 @@ package http import ( "context" - "fmt" "io" "net/http" - "os" "strings" "time" @@ -38,7 +36,6 @@ func (l *Listener) Addr() net.Addr { func (l *Listener) Close() error { if l.locker != nil { - fmt.Fprintln(os.Stderr, "RELEASE LOCK") l.locker.Release() } return l.server.Close() @@ -90,11 +87,11 @@ func (l *Listener) ServeHTTP(writer http.ResponseWriter, request *http.Request) } } - forwardedAddrs := http_proto.ParseXForwardedFor(request.Header) - if len(forwardedAddrs) > 0 && forwardedAddrs[0].Family().IsIP() { + forwardedAddress := http_proto.ParseXForwardedFor(request.Header) + if len(forwardedAddress) > 0 && forwardedAddress[0].Family().IsIP() { remoteAddr = &net.TCPAddr{ - IP: forwardedAddrs[0].IP(), - Port: int(0), + IP: forwardedAddress[0].IP(), + Port: 0, } } @@ -166,7 +163,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti Net: "unix", }, streamSettings.SocketSettings) if err != nil { - newError("failed to listen on ", address).Base(err).WriteToLog(session.ExportIDToError(ctx)) + newError("failed to listen on ", address).Base(err).AtError().WriteToLog(session.ExportIDToError(ctx)) return } locker := ctx.Value(address.Domain()) @@ -179,7 +176,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti Port: int(port), }, streamSettings.SocketSettings) if err != nil { - newError("failed to listen on ", address, ":", port).Base(err).WriteToLog(session.ExportIDToError(ctx)) + newError("failed to listen on ", address, ":", port).Base(err).AtError().WriteToLog(session.ExportIDToError(ctx)) return } } @@ -187,12 +184,12 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti if config == nil { err = server.Serve(streamListener) if err != nil { - newError("stoping serving H2C").Base(err).WriteToLog(session.ExportIDToError(ctx)) + newError("stopping serving H2C").Base(err).WriteToLog(session.ExportIDToError(ctx)) } } else { err = server.ServeTLS(streamListener, "", "") if err != nil { - newError("stoping serving TLS").Base(err).WriteToLog(session.ExportIDToError(ctx)) + newError("stopping serving TLS").Base(err).WriteToLog(session.ExportIDToError(ctx)) } } }()