Feature: add inbounds for flexible binding inbound (#2818)

This commit is contained in:
fuyun
2023-08-03 22:30:08 +08:00
committed by GitHub
parent 10f4d5375a
commit 9e78137768
25 changed files with 552 additions and 361 deletions

View File

@@ -209,23 +209,27 @@ func newLargeDataPair() (chan hashPair, chan hashPair, func(t *testing.T) error)
return pingCh, pongCh, test
}
func testPingPongWithSocksPort(t *testing.T, port int) {
func testPingPongWithSocksPort(t *testing.T, port int) error {
l, err := Listen("tcp", ":10001")
require.NoError(t, err)
defer l.Close()
pingCh, pongCh, test := newPingPongPair()
go func() {
l, err := Listen("tcp", ":10001")
require.NoError(t, err)
defer l.Close()
c, err := l.Accept()
require.NoError(t, err)
if err != nil {
return
}
buf := make([]byte, 4)
_, err = io.ReadFull(c, buf)
require.NoError(t, err)
if _, err = io.ReadFull(c, buf); err != nil {
return
}
pingCh <- buf
_, err = c.Write([]byte("pong"))
require.NoError(t, err)
if _, err = c.Write([]byte("pong")); err != nil {
return
}
}()
go func() {
@@ -233,20 +237,23 @@ func testPingPongWithSocksPort(t *testing.T, port int) {
require.NoError(t, err)
defer c.Close()
_, err = socks5.ClientHandshake(c, socks5.ParseAddr("127.0.0.1:10001"), socks5.CmdConnect, nil)
require.NoError(t, err)
if _, err = socks5.ClientHandshake(c, socks5.ParseAddr("127.0.0.1:10001"), socks5.CmdConnect, nil); err != nil {
return
}
_, err = c.Write([]byte("ping"))
require.NoError(t, err)
if _, err = c.Write([]byte("ping")); err != nil {
return
}
buf := make([]byte, 4)
_, err = io.ReadFull(c, buf)
require.NoError(t, err)
if _, err = io.ReadFull(c, buf); err != nil {
return
}
pongCh <- buf
}()
test(t)
return test(t)
}
func testPingPongWithConn(t *testing.T, c net.Conn) error {
@@ -655,7 +662,7 @@ log-level: silent
defer cleanup()
require.True(t, TCPing(net.JoinHostPort("127.0.0.1", "10000")))
testPingPongWithSocksPort(t, 10000)
require.NoError(t, testPingPongWithSocksPort(t, 10000))
}
func Benchmark_Direct(b *testing.B) {