mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-10 02:53:12 +00:00
Improve mux server
This commit is contained in:
parent
b1c2440371
commit
9a8918cb9e
|
@ -28,23 +28,26 @@ func NewConnection(ctx context.Context, router adapter.Router, errorHandler E.Ha
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
go newConnection(ctx, router, errorHandler, logger, stream, metadata)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newConnection(ctx context.Context, router adapter.Router, errorHandler E.Handler, logger log.ContextLogger, stream net.Conn, metadata adapter.InboundContext) {
|
||||||
stream = &wrapStream{stream}
|
stream = &wrapStream{stream}
|
||||||
request, err := ReadRequest(stream)
|
request, err := ReadRequest(stream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
logger.ErrorContext(ctx, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
metadata.Destination = request.Destination
|
metadata.Destination = request.Destination
|
||||||
if request.Network == N.NetworkTCP {
|
if request.Network == N.NetworkTCP {
|
||||||
go func() {
|
|
||||||
logger.InfoContext(ctx, "inbound multiplex connection to ", metadata.Destination)
|
logger.InfoContext(ctx, "inbound multiplex connection to ", metadata.Destination)
|
||||||
hErr := router.RouteConnection(ctx, &ServerConn{ExtendedConn: bufio.NewExtendedConn(stream)}, metadata)
|
hErr := router.RouteConnection(ctx, &ServerConn{ExtendedConn: bufio.NewExtendedConn(stream)}, metadata)
|
||||||
stream.Close()
|
stream.Close()
|
||||||
if hErr != nil {
|
if hErr != nil {
|
||||||
errorHandler.NewError(ctx, hErr)
|
errorHandler.NewError(ctx, hErr)
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
} else {
|
} else {
|
||||||
go func() {
|
|
||||||
var packetConn N.PacketConn
|
var packetConn N.PacketConn
|
||||||
if !request.PacketAddr {
|
if !request.PacketAddr {
|
||||||
logger.InfoContext(ctx, "inbound multiplex packet connection to ", metadata.Destination)
|
logger.InfoContext(ctx, "inbound multiplex packet connection to ", metadata.Destination)
|
||||||
|
@ -58,8 +61,6 @@ func NewConnection(ctx context.Context, router adapter.Router, errorHandler E.Ha
|
||||||
if hErr != nil {
|
if hErr != nil {
|
||||||
errorHandler.NewError(ctx, hErr)
|
errorHandler.NewError(ctx, hErr)
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue