mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-09 18:43:14 +00:00
Fix copy early conn
This commit is contained in:
parent
6d78cf6b58
commit
4067e0f25c
|
@ -79,6 +79,10 @@ func (tt *tcpTracker) Leave() {
|
|||
tt.manager.Leave(tt)
|
||||
}
|
||||
|
||||
func (tt *tcpTracker) Upstream() any {
|
||||
return tt.Conn
|
||||
}
|
||||
|
||||
func NewTCPTracker(conn net.Conn, manager *Manager, metadata Metadata, router adapter.Router, rule adapter.Rule) *tcpTracker {
|
||||
uuid, _ := uuid.NewV4()
|
||||
|
||||
|
@ -166,6 +170,10 @@ func (ut *udpTracker) Leave() {
|
|||
ut.manager.Leave(ut)
|
||||
}
|
||||
|
||||
func (ut *udpTracker) Upstream() any {
|
||||
return ut.PacketConn
|
||||
}
|
||||
|
||||
func NewUDPTracker(conn N.PacketConn, manager *Manager, metadata Metadata, router adapter.Router, rule adapter.Rule) *udpTracker {
|
||||
uuid, _ := uuid.NewV4()
|
||||
|
||||
|
|
|
@ -49,6 +49,15 @@ func NewConnection(ctx context.Context, this N.Dialer, conn net.Conn, metadata a
|
|||
if err != nil {
|
||||
return N.HandshakeFailure(conn, err)
|
||||
}
|
||||
if cachedReader, isCached := conn.(N.CachedReader); isCached {
|
||||
payload := cachedReader.ReadCached()
|
||||
if payload != nil && !payload.IsEmpty() {
|
||||
_, err = outConn.Write(payload.Bytes())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return bufio.CopyConn(ctx, conn, outConn)
|
||||
}
|
||||
|
||||
|
@ -122,7 +131,7 @@ func connectPacketConnection(ctx context.Context, this N.Dialer, conn N.PacketCo
|
|||
}
|
||||
|
||||
func CopyEarlyConn(ctx context.Context, conn net.Conn, serverConn net.Conn) error {
|
||||
if cachedReader, isCached := serverConn.(N.CachedReader); isCached {
|
||||
if cachedReader, isCached := conn.(N.CachedReader); isCached {
|
||||
payload := cachedReader.ReadCached()
|
||||
if payload != nil && !payload.IsEmpty() {
|
||||
_, err := serverConn.Write(payload.Bytes())
|
||||
|
|
Loading…
Reference in a new issue