Fix copy early conn

This commit is contained in:
世界 2022-08-08 20:56:53 +08:00
parent 6d78cf6b58
commit 4067e0f25c
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 18 additions and 1 deletions

View file

@ -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()

View file

@ -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())