无多路复用版本
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
package shadow
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@ -22,8 +24,6 @@ func NewClient(listenAddress string, serverAddress string, fakeAddressSNI string
|
||||
}
|
||||
|
||||
func (c *Client) Start() {
|
||||
bridge := NewTLSBridge(c.ServerAddress, c.FakeAddressSNI)
|
||||
|
||||
listen, err := net.Listen("tcp", c.ListenAddress)
|
||||
if err != nil {
|
||||
fmt.Printf("[Client] Start client error: %v\n", err)
|
||||
@ -37,15 +37,28 @@ func (c *Client) Start() {
|
||||
fmt.Printf("[Client] accept error: %v\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
stream := bridge.GetStream()
|
||||
if stream == nil {
|
||||
conn.Close()
|
||||
fmt.Println("[Client] connect to server error")
|
||||
continue
|
||||
}
|
||||
fmt.Printf("[Client] New TCP connection: %v <-> %v \n", conn.LocalAddr().String(), conn.RemoteAddr().String())
|
||||
go io.Copy(conn, stream)
|
||||
go io.Copy(stream, conn)
|
||||
go handlerClient(conn, c.ServerAddress, c.FakeAddressSNI)
|
||||
}
|
||||
}
|
||||
|
||||
func handlerClient(conn net.Conn, serverAddress string, fakeAddressSNI string) {
|
||||
dial, err := tls.DialWithDialer(&net.Dialer{
|
||||
Timeout: time.Second * 5,
|
||||
}, "tcp", serverAddress, &tls.Config{
|
||||
ServerName: fakeAddressSNI,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("[Client] Dial server error: %v\n", err)
|
||||
return
|
||||
}
|
||||
err = dial.Handshake()
|
||||
if err != nil {
|
||||
fmt.Printf("[Client] Handshake error: %v\n", err)
|
||||
return
|
||||
}
|
||||
dial.NetConn().SetDeadline(time.Now())
|
||||
dial.NetConn().SetDeadline(time.Time{})
|
||||
|
||||
go io.Copy(conn, dial.NetConn())
|
||||
go io.Copy(dial.NetConn(), conn)
|
||||
}
|
||||
|
Reference in New Issue
Block a user