mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 00:21:30 +00:00
Skip wait for hysteria tcp handshake response
Co-authored-by: arm64v8a <48624112+arm64v8a@users.noreply.github.com>
This commit is contained in:
parent
38088f28b0
commit
79b6bdfda1
|
@ -273,7 +273,7 @@ func (h *Hysteria) acceptStream(ctx context.Context, conn quic.Connection, strea
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
h.logger.InfoContext(ctx, "inbound connection to ", metadata.Destination)
|
h.logger.InfoContext(ctx, "inbound connection to ", metadata.Destination)
|
||||||
return h.router.RouteConnection(ctx, hysteria.NewConn(stream, metadata.Destination), metadata)
|
return h.router.RouteConnection(ctx, hysteria.NewConn(stream, metadata.Destination, false), metadata)
|
||||||
} else {
|
} else {
|
||||||
h.logger.InfoContext(ctx, "inbound packet connection to ", metadata.Destination)
|
h.logger.InfoContext(ctx, "inbound packet connection to ", metadata.Destination)
|
||||||
var id uint32
|
var id uint32
|
||||||
|
|
|
@ -276,16 +276,7 @@ func (h *Hysteria) DialContext(ctx context.Context, network string, destination
|
||||||
stream.Close()
|
stream.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
response, err := hysteria.ReadServerResponse(stream)
|
return hysteria.NewConn(stream, destination, true), nil
|
||||||
if err != nil {
|
|
||||||
stream.Close()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if !response.OK {
|
|
||||||
stream.Close()
|
|
||||||
return nil, E.New("remote error: ", response.Message)
|
|
||||||
}
|
|
||||||
return hysteria.NewConn(stream, destination), nil
|
|
||||||
case N.NetworkUDP:
|
case N.NetworkUDP:
|
||||||
conn, err := h.ListenPacket(ctx, destination)
|
conn, err := h.ListenPacket(ctx, destination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -374,17 +374,35 @@ var _ net.Conn = (*Conn)(nil)
|
||||||
|
|
||||||
type Conn struct {
|
type Conn struct {
|
||||||
quic.Stream
|
quic.Stream
|
||||||
destination M.Socksaddr
|
destination M.Socksaddr
|
||||||
responseWritten bool
|
needReadResponse bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConn(stream quic.Stream, destination M.Socksaddr) *Conn {
|
func NewConn(stream quic.Stream, destination M.Socksaddr, isClient bool) *Conn {
|
||||||
return &Conn{
|
return &Conn{
|
||||||
Stream: stream,
|
Stream: stream,
|
||||||
destination: destination,
|
destination: destination,
|
||||||
|
needReadResponse: isClient,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Conn) Read(p []byte) (n int, err error) {
|
||||||
|
if c.needReadResponse {
|
||||||
|
var response *ServerResponse
|
||||||
|
response, err = ReadServerResponse(c.Stream)
|
||||||
|
if err != nil {
|
||||||
|
c.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !response.OK {
|
||||||
|
c.Close()
|
||||||
|
return 0, E.New("remote error: ", response.Message)
|
||||||
|
}
|
||||||
|
c.needReadResponse = false
|
||||||
|
}
|
||||||
|
return c.Stream.Read(p)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Conn) LocalAddr() net.Addr {
|
func (c *Conn) LocalAddr() net.Addr {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -394,7 +412,7 @@ func (c *Conn) RemoteAddr() net.Addr {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) ReaderReplaceable() bool {
|
func (c *Conn) ReaderReplaceable() bool {
|
||||||
return true
|
return !c.needReadResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) WriterReplaceable() bool {
|
func (c *Conn) WriterReplaceable() bool {
|
||||||
|
|
Loading…
Reference in a new issue