feat(wip): test reworks

This commit is contained in:
Toby 2023-07-26 13:48:08 -07:00
parent 55fb903192
commit dd836b4496
22 changed files with 934 additions and 185 deletions

View file

@ -41,7 +41,7 @@ func (t *TCPTunnel) handle(conn net.Conn) {
}
}()
rc, err := t.HyClient.DialTCP(t.Remote)
rc, err := t.HyClient.TCP(t.Remote)
if err != nil {
closeErr = err
return

View file

@ -118,7 +118,7 @@ func (t *UDPTunnel) handle(l net.PacketConn, sm *sessionManager, addr net.Addr,
if t.EventLogger != nil {
t.EventLogger.Connect(addr)
}
hyConn, err := t.HyClient.ListenUDP()
hyConn, err := t.HyClient.UDP()
if err != nil {
if t.EventLogger != nil {
t.EventLogger.Error(addr, err)

View file

@ -156,7 +156,7 @@ func (s *Server) handleConnect(conn net.Conn, req *http.Request) {
}()
// Dial
rConn, err := s.HyClient.DialTCP(reqAddr)
rConn, err := s.HyClient.TCP(reqAddr)
if err != nil {
_ = sendSimpleResponse(conn, req, http.StatusBadGateway)
closeErr = err
@ -233,7 +233,7 @@ func (s *Server) initHTTPClient() {
Transport: &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
// HyClient doesn't support context for now
return s.HyClient.DialTCP(addr)
return s.HyClient.TCP(addr)
},
},
CheckRedirect: func(req *http.Request, via []*http.Request) error {

View file

@ -17,11 +17,11 @@ const (
type mockHyClient struct{}
func (c *mockHyClient) DialTCP(addr string) (net.Conn, error) {
func (c *mockHyClient) TCP(addr string) (net.Conn, error) {
return net.Dial("tcp", addr)
}
func (c *mockHyClient) ListenUDP() (client.HyUDPConn, error) {
func (c *mockHyClient) UDP() (client.HyUDPConn, error) {
// Not implemented
return nil, errors.New("not implemented")
}

View file

@ -135,7 +135,7 @@ func (s *Server) handleTCP(conn net.Conn, req *socks5.Request) {
}()
// Dial
rConn, err := s.HyClient.DialTCP(addr)
rConn, err := s.HyClient.TCP(addr)
if err != nil {
_ = sendSimpleReply(conn, socks5.RepHostUnreachable)
closeErr = err
@ -196,7 +196,7 @@ func (s *Server) handleUDP(conn net.Conn, req *socks5.Request) {
defer udpConn.Close()
// HyClient UDP session
hyUDP, err := s.HyClient.ListenUDP()
hyUDP, err := s.HyClient.UDP()
if err != nil {
_ = sendSimpleReply(conn, socks5.RepServerFailure)
closeErr = err

View file

@ -10,13 +10,13 @@ import (
type MockEchoHyClient struct{}
func (c *MockEchoHyClient) DialTCP(addr string) (net.Conn, error) {
func (c *MockEchoHyClient) TCP(addr string) (net.Conn, error) {
return &mockEchoTCPConn{
BufChan: make(chan []byte, 10),
}, nil
}
func (c *MockEchoHyClient) ListenUDP() (client.HyUDPConn, error) {
func (c *MockEchoHyClient) UDP() (client.HyUDPConn, error) {
return &mockEchoUDPConn{
BufChan: make(chan mockEchoUDPPacket, 10),
}, nil