mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-08 11:44:13 +08:00
Refine naming
This commit is contained in:
parent
803febd01b
commit
9a90d34b18
@ -37,7 +37,7 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, options option.V2RayGRPCOptions, tlsConfig *tls.Config) adapter.V2RayClientTransport {
|
func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, options option.V2RayGRPCOptions, tlsConfig *tls.Config) adapter.V2RayClientTransport {
|
||||||
client := &Client{
|
return &Client{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
dialer: dialer,
|
dialer: dialer,
|
||||||
serverAddr: serverAddr,
|
serverAddr: serverAddr,
|
||||||
@ -61,36 +61,35 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt
|
|||||||
PingTimeout: 0,
|
PingTimeout: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
url: &url.URL{
|
||||||
client.url = &url.URL{
|
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
Host: serverAddr.String(),
|
Host: serverAddr.String(),
|
||||||
Path: fmt.Sprintf("/%s/Tun", options.ServiceName),
|
Path: fmt.Sprintf("/%s/Tun", options.ServiceName),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
return client
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) DialContext(ctx context.Context) (net.Conn, error) {
|
func (c *Client) DialContext(ctx context.Context) (net.Conn, error) {
|
||||||
reader, writer := io.Pipe()
|
requestPipeReader, requestPipeWriter := io.Pipe()
|
||||||
request := (&http.Request{
|
request := (&http.Request{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Body: reader,
|
Body: requestPipeReader,
|
||||||
URL: c.url,
|
URL: c.url,
|
||||||
Proto: "HTTP/2",
|
Proto: "HTTP/2",
|
||||||
ProtoMajor: 2,
|
ProtoMajor: 2,
|
||||||
ProtoMinor: 0,
|
ProtoMinor: 0,
|
||||||
Header: defaultClientHeader,
|
Header: defaultClientHeader,
|
||||||
}).WithContext(c.ctx)
|
}).WithContext(ctx)
|
||||||
anotherReader, anotherWriter := io.Pipe()
|
responsePipeReader, responsePipeWriter := io.Pipe()
|
||||||
go func() {
|
go func() {
|
||||||
defer anotherWriter.Close()
|
defer responsePipeWriter.Close()
|
||||||
response, err := c.client.Do(request)
|
response, err := c.client.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, _ = bufio.Copy(anotherWriter, response.Body)
|
_, _ = bufio.Copy(responsePipeWriter, response.Body)
|
||||||
}()
|
}()
|
||||||
return newGunConn(anotherReader, writer, ChainedClosable{reader, writer, anotherReader}), nil
|
return newGunConn(responsePipeReader, requestPipeWriter, ChainedClosable{requestPipeReader, requestPipeWriter, responsePipeReader}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChainedClosable []io.Closer
|
type ChainedClosable []io.Closer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user