init
This commit is contained in:
51
shadow/client.go
Normal file
51
shadow/client.go
Normal file
@ -0,0 +1,51 @@
|
||||
package shadow
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
ListenAddress string
|
||||
ServerAddress string
|
||||
FakeAddressSNI string
|
||||
}
|
||||
|
||||
func NewClient(listenAddress string, serverAddress string, fakeAddressSNI string) *Client {
|
||||
client := &Client{
|
||||
ListenAddress: listenAddress,
|
||||
ServerAddress: serverAddress,
|
||||
FakeAddressSNI: fakeAddressSNI,
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
||||
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)
|
||||
return
|
||||
}
|
||||
defer listen.Close()
|
||||
fmt.Printf("[Client] Listening at:%v\n", c.ListenAddress)
|
||||
for {
|
||||
conn, err := listen.Accept()
|
||||
if err != nil {
|
||||
fmt.Printf("[Client] accept error: %v\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
stream := bridge.GetStream()
|
||||
if stream == nil {
|
||||
conn.Close()
|
||||
fmt.Printf("[Client] connect to server error: %v\n", err)
|
||||
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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user