mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-12-12 20:49:48 +04:00
app/reverse/bridge.go: Fix DispatchLink() returns immediately
Fixes https://github.com/XTLS/Xray-core/issues/5088
This commit is contained in:
@@ -149,25 +149,23 @@ func (w *BridgeWorker) Connections() uint32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *BridgeWorker) handleInternalConn(link *transport.Link) {
|
func (w *BridgeWorker) handleInternalConn(link *transport.Link) {
|
||||||
go func() {
|
reader := link.Reader
|
||||||
reader := link.Reader
|
for {
|
||||||
for {
|
mb, err := reader.ReadMultiBuffer()
|
||||||
mb, err := reader.ReadMultiBuffer()
|
if err != nil {
|
||||||
if err != nil {
|
break
|
||||||
|
}
|
||||||
|
for _, b := range mb {
|
||||||
|
var ctl Control
|
||||||
|
if err := proto.Unmarshal(b.Bytes(), &ctl); err != nil {
|
||||||
|
errors.LogInfoInner(context.Background(), err, "failed to parse proto message")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for _, b := range mb {
|
if ctl.State != w.state {
|
||||||
var ctl Control
|
w.state = ctl.State
|
||||||
if err := proto.Unmarshal(b.Bytes(), &ctl); err != nil {
|
|
||||||
errors.LogInfoInner(context.Background(), err, "failed to parse proto message")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if ctl.State != w.state {
|
|
||||||
w.state = ctl.State
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *BridgeWorker) Dispatch(ctx context.Context, dest net.Destination) (*transport.Link, error) {
|
func (w *BridgeWorker) Dispatch(ctx context.Context, dest net.Destination) (*transport.Link, error) {
|
||||||
@@ -182,7 +180,7 @@ func (w *BridgeWorker) Dispatch(ctx context.Context, dest net.Destination) (*tra
|
|||||||
uplinkReader, uplinkWriter := pipe.New(opt...)
|
uplinkReader, uplinkWriter := pipe.New(opt...)
|
||||||
downlinkReader, downlinkWriter := pipe.New(opt...)
|
downlinkReader, downlinkWriter := pipe.New(opt...)
|
||||||
|
|
||||||
w.handleInternalConn(&transport.Link{
|
go w.handleInternalConn(&transport.Link{
|
||||||
Reader: downlinkReader,
|
Reader: downlinkReader,
|
||||||
Writer: uplinkWriter,
|
Writer: uplinkWriter,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user