41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/spf13/cobra"
|
|
"shadowTLS/shadow"
|
|
)
|
|
|
|
type ClientParam struct {
|
|
ListenAddr string
|
|
ServerAddr string
|
|
SNI string
|
|
}
|
|
|
|
var (
|
|
clientParams *ClientParam
|
|
clientCmd = &cobra.Command{
|
|
Use: "client",
|
|
Short: "Client mode",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
if !verifyAndParseEncryptionKey() {
|
|
fmt.Println("[Client] Invalid encryption key length")
|
|
return
|
|
}
|
|
client := shadow.NewClient(clientParams.ListenAddr, clientParams.ServerAddr, clientParams.SNI)
|
|
client.Start()
|
|
},
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
clientParams = &ClientParam{}
|
|
clientCmd.Flags().StringVarP(&clientParams.ListenAddr, "listen", "l", "0.0.0.0:18080", "Listen address and port")
|
|
clientCmd.Flags().StringVarP(&clientParams.ServerAddr, "saddr", "s", "", "Server address and port")
|
|
clientCmd.Flags().StringVarP(&clientParams.SNI, "domain", "d", "", "Domain name used for TLS Handshake")
|
|
clientCmd.MarkFlagRequired("listen")
|
|
clientCmd.MarkFlagRequired("saddr")
|
|
clientCmd.MarkFlagRequired("sni")
|
|
rootCmd.AddCommand(clientCmd)
|
|
}
|