mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-02-12 03:05:45 -05:00
step 1 to remove reference to net package
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"bufio"
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strconv"
|
||||
@@ -17,7 +16,7 @@ import (
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/errors"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/signal"
|
||||
"v2ray.com/core/transport/internet"
|
||||
)
|
||||
@@ -39,33 +38,30 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (*Server) Network() v2net.NetworkList {
|
||||
return v2net.NetworkList{
|
||||
Network: []v2net.Network{v2net.Network_TCP},
|
||||
func (*Server) Network() net.NetworkList {
|
||||
return net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
}
|
||||
}
|
||||
|
||||
func parseHost(rawHost string, defaultPort v2net.Port) (v2net.Destination, error) {
|
||||
func parseHost(rawHost string, defaultPort net.Port) (net.Destination, error) {
|
||||
port := defaultPort
|
||||
host, rawPort, err := net.SplitHostPort(rawHost)
|
||||
if err != nil {
|
||||
if addrError, ok := err.(*net.AddrError); ok && strings.Contains(addrError.Err, "missing port") {
|
||||
host = rawHost
|
||||
} else {
|
||||
return v2net.Destination{}, err
|
||||
return net.Destination{}, err
|
||||
}
|
||||
} else {
|
||||
intPort, err := strconv.Atoi(rawPort)
|
||||
if err != nil {
|
||||
return v2net.Destination{}, err
|
||||
return net.Destination{}, err
|
||||
}
|
||||
port = v2net.Port(intPort)
|
||||
port = net.Port(intPort)
|
||||
}
|
||||
|
||||
if ip := net.ParseIP(host); ip != nil {
|
||||
return v2net.TCPDestination(v2net.IPAddress(ip), port), nil
|
||||
}
|
||||
return v2net.TCPDestination(v2net.DomainAddress(host), port), nil
|
||||
return net.TCPDestination(net.ParseAddress(host), port), nil
|
||||
}
|
||||
|
||||
func isTimeout(err error) bool {
|
||||
@@ -73,7 +69,7 @@ func isTimeout(err error) bool {
|
||||
return ok && nerr.Timeout()
|
||||
}
|
||||
|
||||
func (s *Server) Process(ctx context.Context, network v2net.Network, conn internet.Connection, dispatcher dispatcher.Interface) error {
|
||||
func (s *Server) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher dispatcher.Interface) error {
|
||||
reader := bufio.NewReaderSize(conn, 2048)
|
||||
|
||||
Start:
|
||||
@@ -90,9 +86,9 @@ Start:
|
||||
log.Trace(newError("request to Method [", request.Method, "] Host [", request.Host, "] with URL [", request.URL, "]"))
|
||||
conn.SetReadDeadline(time.Time{})
|
||||
|
||||
defaultPort := v2net.Port(80)
|
||||
defaultPort := net.Port(80)
|
||||
if strings.ToLower(request.URL.Scheme) == "https" {
|
||||
defaultPort = v2net.Port(443)
|
||||
defaultPort = net.Port(443)
|
||||
}
|
||||
host := request.Host
|
||||
if len(host) == 0 {
|
||||
@@ -121,7 +117,7 @@ Start:
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Server) handleConnect(ctx context.Context, request *http.Request, reader io.Reader, writer io.Writer, dest v2net.Destination, dispatcher dispatcher.Interface) error {
|
||||
func (s *Server) handleConnect(ctx context.Context, request *http.Request, reader io.Reader, writer io.Writer, dest net.Destination, dispatcher dispatcher.Interface) error {
|
||||
_, err := writer.Write([]byte("HTTP/1.1 200 Connection established\r\n\r\n"))
|
||||
if err != nil {
|
||||
return newError("failed to write back OK response").Base(err)
|
||||
@@ -192,7 +188,7 @@ func StripHopByHopHeaders(header http.Header) {
|
||||
|
||||
var errWaitAnother = newError("keep alive")
|
||||
|
||||
func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, reader io.Reader, writer io.Writer, dest v2net.Destination, dispatcher dispatcher.Interface) error {
|
||||
func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, reader io.Reader, writer io.Writer, dest net.Destination, dispatcher dispatcher.Interface) error {
|
||||
if len(request.URL.Host) <= 0 {
|
||||
response := &http.Response{
|
||||
Status: "Bad Request",
|
||||
|
||||
Reference in New Issue
Block a user