mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-29 12:01:29 +00:00
Fix hysteria inbound
This commit is contained in:
parent
62859e0c6b
commit
a5163e3e3c
|
@ -250,12 +250,6 @@ func (h *Hysteria) acceptStream(ctx context.Context, conn quic.Connection, strea
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = hysteria.WriteServerResponse(stream, hysteria.ServerResponse{
|
|
||||||
OK: true,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var metadata adapter.InboundContext
|
var metadata adapter.InboundContext
|
||||||
metadata.Inbound = h.tag
|
metadata.Inbound = h.tag
|
||||||
metadata.InboundType = C.TypeHysteria
|
metadata.InboundType = C.TypeHysteria
|
||||||
|
@ -265,7 +259,14 @@ func (h *Hysteria) acceptStream(ctx context.Context, conn quic.Connection, strea
|
||||||
metadata.Source = M.SocksaddrFromNet(conn.RemoteAddr())
|
metadata.Source = M.SocksaddrFromNet(conn.RemoteAddr())
|
||||||
metadata.OriginDestination = M.SocksaddrFromNet(conn.LocalAddr())
|
metadata.OriginDestination = M.SocksaddrFromNet(conn.LocalAddr())
|
||||||
metadata.Destination = M.ParseSocksaddrHostPort(request.Host, request.Port)
|
metadata.Destination = M.ParseSocksaddrHostPort(request.Host, request.Port)
|
||||||
|
|
||||||
if !request.UDP {
|
if !request.UDP {
|
||||||
|
err = hysteria.WriteServerResponse(stream, hysteria.ServerResponse{
|
||||||
|
OK: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
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), metadata)
|
||||||
} else {
|
} else {
|
||||||
|
@ -277,6 +278,13 @@ func (h *Hysteria) acceptStream(ctx context.Context, conn quic.Connection, strea
|
||||||
h.udpSessions[id] = nCh
|
h.udpSessions[id] = nCh
|
||||||
h.udpSessionId += 1
|
h.udpSessionId += 1
|
||||||
h.udpAccess.Unlock()
|
h.udpAccess.Unlock()
|
||||||
|
err = hysteria.WriteServerResponse(stream, hysteria.ServerResponse{
|
||||||
|
OK: true,
|
||||||
|
UDPSessionID: id,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
packetConn := hysteria.NewPacketConn(conn, stream, id, metadata.Destination, nCh, common.Closer(func() error {
|
packetConn := hysteria.NewPacketConn(conn, stream, id, metadata.Destination, nCh, common.Closer(func() error {
|
||||||
h.udpAccess.Lock()
|
h.udpAccess.Lock()
|
||||||
if ch, ok := h.udpSessions[id]; ok {
|
if ch, ok := h.udpSessions[id]; ok {
|
||||||
|
|
Loading…
Reference in a new issue