Esempio n. 1
0
func argsCheck() *tunnel.Options {
	var options tunnel.Options

	var tgw string
	var rc4Key string
	flag.BoolVar(&options.TunnelServer, "tunnel_server", false, "work as tunnel server or client")
	flag.BoolVar(&options.Front, "front", false, "work as front door or back door")
	flag.StringVar(&tgw, "tgw", "", "tgw header")
	flag.StringVar(&rc4Key, "rc4", "the answer to life, the universe and everything", "rc4 key, disable if no key")
	flag.StringVar(&options.FrontAddr, "front_addr", "0.0.0.0:8001", "front door address(0.0.0.0:8001)")
	flag.StringVar(&options.TunnelAddr, "tunnel_addr", "0.0.0.0:8002", "tunnel door address(0.0.0.0:8002)")
	flag.IntVar(&options.LogLevel, "log", 1, "larger value for detail log")
	flag.Usage = usage
	flag.Parse()

	options.Capacity = 65535
	options.Tgw = bytes.ToLower([]byte(tgw))
	options.Rc4Key = []byte(rc4Key)

	if len(options.Rc4Key) > 256 {
		fmt.Println("rc4 key at most 256 bytes")
		os.Exit(1)
	}

	if !options.Front {
		args := flag.Args()
		if len(args) < 1 {
			usage()
		} else {
			options.ConfigFile = args[0]
		}
	}
	return &options
}
Esempio n. 2
0
func argsCheck() *tunnel.Options {
	var options tunnel.Options

	var rc4Key string
	flag.StringVar(&options.Listen, "listen", ":8001", "host:port gotunnel listen on")
	flag.StringVar(&options.Server, "server", "", "server address, empty if work as server")
	flag.IntVar(&options.LogLevel, "log", 1, "larger value for detail log")
	flag.IntVar(&options.TunnelCount, "tunnel_count", 1, "low level tunnel count")
	flag.StringVar(&rc4Key, "rc4", "the answer to life, the universe and everything", "rc4 key, disable if no key")
	//flag.IntVar(&options.Count, "count", 1, "underlayer tunnel count")
	flag.Usage = usage
	flag.Parse()

	options.Capacity = 10240
	options.RbufHw = 12
	options.RbufLw = 2
	options.PacketSize = 4096
	options.RC4Key = []byte(rc4Key)

	if len(options.RC4Key) > 256 {
		fmt.Println("rc4 key at most 256 bytes")
		os.Exit(1)
	}

	// will support multiple tunnel in future
	options.Count = 1
	if options.Count <= 0 || options.Count > 1024 {
		fmt.Println("tunnel count must be in range [1, 1024]")
		os.Exit(1)
	}

	if options.Server == "" {
		args := flag.Args()
		if len(args) < 1 {
			usage()
		} else {
			options.ConfigFile = args[0]
		}
	}
	return &options
}