mirror of
https://github.com/XTLS/REALITY.git
synced 2025-08-23 06:58:39 +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"
|
"golang.org/x/crypto/hkdf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type CloseWriteConn interface {
|
||||||
|
net.Conn
|
||||||
|
CloseWrite() error
|
||||||
|
}
|
||||||
|
|
||||||
type MirrorConn struct {
|
type MirrorConn struct {
|
||||||
*sync.Mutex
|
*sync.Mutex
|
||||||
net.Conn
|
net.Conn
|
||||||
@ -125,10 +130,11 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
underlying := conn
|
raw := conn
|
||||||
if pc, ok := underlying.(*proxyproto.Conn); ok {
|
if pc, ok := conn.(*proxyproto.Conn); ok {
|
||||||
underlying = pc.Raw() // for TCP splicing in io.Copy()
|
raw = pc.Raw() // for TCP splicing in io.Copy()
|
||||||
}
|
}
|
||||||
|
underlying := raw.(CloseWriteConn) // *net.TCPConn or *net.UnixConn
|
||||||
|
|
||||||
mutex := new(sync.Mutex)
|
mutex := new(sync.Mutex)
|
||||||
|
|
||||||
@ -334,6 +340,10 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
|
|||||||
}
|
}
|
||||||
conn.Write(s2cSaved)
|
conn.Write(s2cSaved)
|
||||||
io.Copy(underlying, target)
|
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()
|
waitGroup.Done()
|
||||||
}()
|
}()
|
||||||
|
Loading…
Reference in New Issue
Block a user