mirror of
https://github.com/XTLS/REALITY.git
synced 2025-08-22 14:38:35 +00:00
Call underlying.CloseWrite()
once io.Copy()
returned (#7)
Co-authored-by: Fangliding <Fangliding.fshxy@outlook.com>
This commit is contained in:
parent
ecc4401070
commit
48f0b2d5ed
16
tls.go
16
tls.go
@ -40,6 +40,11 @@ import (
|
||||
"golang.org/x/crypto/hkdf"
|
||||
)
|
||||
|
||||
type CloseWriteConn interface {
|
||||
net.Conn
|
||||
CloseWrite() error
|
||||
}
|
||||
|
||||
type MirrorConn struct {
|
||||
*sync.Mutex
|
||||
net.Conn
|
||||
@ -125,10 +130,11 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
|
||||
}
|
||||
}
|
||||
|
||||
underlying := conn
|
||||
if pc, ok := underlying.(*proxyproto.Conn); ok {
|
||||
underlying = pc.Raw() // for TCP splicing in io.Copy()
|
||||
raw := conn
|
||||
if pc, ok := conn.(*proxyproto.Conn); ok {
|
||||
raw = pc.Raw() // for TCP splicing in io.Copy()
|
||||
}
|
||||
underlying := raw.(CloseWriteConn) // *net.TCPConn or *net.UnixConn
|
||||
|
||||
mutex := new(sync.Mutex)
|
||||
|
||||
@ -334,6 +340,10 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
|
||||
}
|
||||
conn.Write(s2cSaved)
|
||||
io.Copy(underlying, target)
|
||||
// Here is bidirectional direct forwarding:
|
||||
// client ---underlying--- server ---target--- dest
|
||||
// Call `underlying.CloseWrite()` once `io.Copy()` returned
|
||||
underlying.CloseWrite()
|
||||
}
|
||||
waitGroup.Done()
|
||||
}()
|
||||
|
Loading…
Reference in New Issue
Block a user