• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang shadowsocks.SetDebug函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/shadowsocks/shadowsocks-go/shadowsocks.SetDebug函数的典型用法代码示例。如果您正苦于以下问题:Golang SetDebug函数的具体用法?Golang SetDebug怎么用?Golang SetDebug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了SetDebug函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	log.SetOutput(os.Stdout)

	var cmdConfig ss.Config
	var printVer bool
	var core int

	flag.BoolVar(&printVer, "version", false, "print version")
	flag.StringVar(&configFile, "c", "config.json", "specify config file")
	flag.StringVar(&cmdConfig.Password, "k", "", "password")
	flag.IntVar(&cmdConfig.ServerPort, "p", 0, "server port")
	flag.IntVar(&cmdConfig.Timeout, "t", 300, "timeout in seconds")
	flag.StringVar(&cmdConfig.Method, "m", "", "encryption method, default: aes-256-cfb")
	flag.IntVar(&core, "core", 0, "maximum number of CPU cores to use, default is determinied by Go runtime")
	flag.BoolVar((*bool)(&debug), "d", false, "print debug message")

	flag.Parse()

	if printVer {
		ss.PrintVersion()
		os.Exit(0)
	}

	ss.SetDebug(debug)

	if strings.HasSuffix(cmdConfig.Method, "-auth") {
		cmdConfig.Method = cmdConfig.Method[:len(cmdConfig.Method)-5]
		cmdConfig.Auth = true
	}

	var err error
	config, err = ss.ParseConfig(configFile)
	if err != nil {
		if !os.IsNotExist(err) {
			fmt.Fprintf(os.Stderr, "error reading %s: %v\n", configFile, err)
			os.Exit(1)
		}
		config = &cmdConfig
	} else {
		ss.UpdateConfig(config, &cmdConfig)
	}
	if config.Method == "" {
		config.Method = "aes-256-cfb"
	}
	if err = ss.CheckCipherMethod(config.Method); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	if err = unifyPortPassword(config); err != nil {
		os.Exit(1)
	}
	if core > 0 {
		runtime.GOMAXPROCS(core)
	}
	for port, password := range config.PortPassword {
		go run(port, password, config.Auth)
	}

	waitSignal()
}
开发者ID:CowLeo,项目名称:shadowsocks-go,代码行数:60,代码来源:server.go


示例2: main

func main() {
	log.SetOutput(os.Stdout)

	var cmdConfig ss.Config
	var printVer bool
	var core int

	flag.BoolVar(&printVer, "version", false, "print version")
	flag.StringVar(&configFile, "c", "config.json", "specify config file")
	flag.StringVar(&cmdConfig.Password, "k", "", "password")
	flag.IntVar(&cmdConfig.ServerPort, "p", 0, "server port")
	flag.IntVar(&cmdConfig.Timeout, "t", 60, "connection timeout (in seconds)")
	flag.StringVar(&cmdConfig.Method, "m", "", "encryption method, use empty string or rc4")
	flag.IntVar(&core, "core", 0, "maximum number of CPU cores to use, default is determinied by Go runtime")
	flag.BoolVar((*bool)(&debug), "d", false, "print debug message")

	flag.Parse()

	if printVer {
		ss.PrintVersion()
		os.Exit(0)
	}

	ss.SetDebug(debug)

	var err error
	config, err = ss.ParseConfig(configFile)
	if err != nil {
		if !os.IsNotExist(err) {
			fmt.Fprintf(os.Stderr, "error reading %s: %v\n", configFile, err)
			os.Exit(1)
		}
		config = &cmdConfig
	} else {
		ss.UpdateConfig(config, &cmdConfig)
	}
	if err = unifyPortPassword(config); err != nil {
		os.Exit(1)
	}
	if err = ss.SetDefaultCipher(config.Method); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	if core > 0 {
		runtime.GOMAXPROCS(core)
	}
	for port, password := range config.PortPassword {
		go run(port, password)
	}

	waitSignal()
}
开发者ID:code2u,项目名称:shadowsocks-go,代码行数:52,代码来源:server.go


示例3: main

func main() {
	var cmdConfig ss.Config
	var printVer bool

	flag.BoolVar(&printVer, "version", false, "print version")
	flag.StringVar(&configFile, "c", "config.json", "specify config file")
	flag.StringVar(&cmdConfig.Password, "k", "", "password")
	flag.IntVar(&cmdConfig.ServerPort, "p", 0, "server port")
	flag.IntVar(&cmdConfig.Timeout, "t", 60, "connection timeout (in seconds)")
	flag.BoolVar((*bool)(&debug), "d", false, "print debug message")

	flag.Parse()

	if printVer {
		ss.PrintVersion()
		os.Exit(0)
	}

	ss.SetDebug(debug)

	var err error
	config, err = ss.ParseConfig(configFile)
	if err != nil {
		if os.IsNotExist(err) {
			log.Println("config file not found, using all options from command line")
		} else {
			log.Printf("error reading %s: %v\n", configFile, err)
			os.Exit(1)
		}
		config = &cmdConfig
	} else {
		ss.UpdateConfig(config, &cmdConfig)
	}

	if err = unifyPortPassword(config); err != nil {
		os.Exit(1)
	}

	initTableCache(config)
	for port, password := range config.PortPassword {
		go run(port, password)
	}
	// Wait all ports have get it's encryption table
	for int(table.getCnt) != len(config.PortPassword) {
		time.Sleep(1 * time.Second)
	}
	storeTableCache(config)
	log.Println("all ports ready")

	table.cache = nil // release memory
	waitSignal()
}
开发者ID:vicenteforever,项目名称:shadowsocks-go,代码行数:52,代码来源:server.go


示例4: main

func main() {
	log.SetOutput(os.Stdout)

	var printVer bool
	var core int
	var serverPort string
	var redisServer string
	var timeout int

	flag.BoolVar(&printVer, "version", false, "print version")
	flag.StringVar(&serverPort, "p", "8388", "server port")
	flag.StringVar(&redisServer, "redis", ":6379", "redis server")
	flag.IntVar(&core, "core", 0, "maximum number of CPU cores to use, default is determinied by Go runtime")
	flag.IntVar(&timeout, "timeout", 10, "Socket read timeout")
	flag.BoolVar((*bool)(&debug), "d", false, "print debug message")

	flag.Parse()

	if printVer {
		ss.PrintVersion()
		os.Exit(0)
	}

	ss.SetDebug(debug)

	storage = NewStorage(redisServer)
	if core > 0 {
		runtime.GOMAXPROCS(core)
	}

	readTimeout = time.Duration(timeout) * time.Second

	go run(serverPort)

	waitSignal()
}
开发者ID:tallriham,项目名称:shadowsocks-auth,代码行数:36,代码来源:server.go


示例5: initLog

func initLog() {
	logFile = os.Stdout
	if config.LogFile != "" {
		if f, err := os.OpenFile(expandTilde(config.LogFile),
			os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600); err != nil {
			fmt.Printf("Can't open log file, logging to stdout: %v\n", err)
		} else {
			logFile = f
		}
	}
	log.SetOutput(logFile)
	if colorize {
		color.SetDefaultColor(color.ANSI)
	} else {
		color.SetDefaultColor(color.NoColor)
	}
	errorLog = log.New(logFile, color.Red("[ERROR] "), log.LstdFlags)
	debugLog = log.New(logFile, color.Blue("[DEBUG] "), log.LstdFlags)
	if debug {
		ss.SetDebug(ss.DebugLog(true))
	}
	requestLog = log.New(logFile, color.Green("[>>>>>] "), log.LstdFlags)
	responseLog = log.New(logFile, color.Yellow("[<<<<<] "), log.LstdFlags)
}
开发者ID:ayanamist,项目名称:MEOW,代码行数:24,代码来源:log.go


示例6: main

func main() {
	log.SetOutput(os.Stdout)

	var configFile, cmdServer string
	var cmdConfig ss.Config
	var printVer bool

	flag.BoolVar(&printVer, "version", false, "print version")
	flag.StringVar(&configFile, "c", "config.json", "specify config file")
	flag.StringVar(&cmdServer, "s", "", "server address")
	flag.StringVar(&cmdConfig.Password, "k", "", "password")
	flag.IntVar(&cmdConfig.ServerPort, "p", 0, "server port")
	flag.IntVar(&cmdConfig.LocalPort, "l", 0, "local socks5 proxy port")
	flag.StringVar(&cmdConfig.Method, "m", "", "encryption method, use empty string or rc4")
	flag.BoolVar((*bool)(&debug), "d", false, "print debug message")

	flag.Parse()

	if printVer {
		ss.PrintVersion()
		os.Exit(0)
	}

	cmdConfig.Server = cmdServer
	ss.SetDebug(debug)

	exists, err := ss.IsFileExists(configFile)
	// If no config file in current directory, try search it in the binary directory
	// Note there's no portable way to detect the binary directory.
	binDir := path.Dir(os.Args[0])
	if (!exists || err != nil) && binDir != "" && binDir != "." {
		oldConfig := configFile
		configFile = path.Join(binDir, "config.json")
		log.Printf("%s not found, try config file %s\n", oldConfig, configFile)
	}

	config, err := ss.ParseConfig(configFile)
	if err != nil {
		config = &cmdConfig
		if !os.IsNotExist(err) {
			fmt.Fprintf(os.Stderr, "error reading %s: %v\n", configFile, err)
			os.Exit(1)
		}
	} else {
		ss.UpdateConfig(config, &cmdConfig)
	}

	if len(config.ServerPassword) == 0 {
		if !enoughOptions(config) {
			fmt.Fprintln(os.Stderr, "must specify server address, password and both server/local port")
			os.Exit(1)
		}
	} else {
		if config.Password != "" || config.ServerPort != 0 || config.GetServerArray() != nil {
			fmt.Fprintln(os.Stderr, "given server_password, ignore server, server_port and password option:", config)
		}
		if config.LocalPort == 0 {
			fmt.Fprintln(os.Stderr, "must specify local port")
			os.Exit(1)
		}
	}

	parseServerConfig(config)

	run(strconv.Itoa(config.LocalPort))
}
开发者ID:stefanie924,项目名称:shadowsocks-go-1,代码行数:66,代码来源:local.go


示例7: Start

func (s ShadowsocksTransport) Start() error {
	handler := server.NewHandler(s.Name)

	listener, err := net.Listen("tcp", s.BindAddr)
	if err != nil {
		listener, err = net.Listen("tcp", "127.0.0.1:0")
	}
	if err != nil {
		handler.PrintError("CANNOT BIND TO ANY PORT")
		return errors.New("Cannot bind to any port")
	}

	listener = handler.MonitorListener(listener)
	handler.PrintExpose("socks5", listener.Addr().String())

	config := &ss.Config{
		Server:     s.RemoteHost,
		ServerPort: s.RemotePort,
		Password:   s.Secret,
		LocalPort:  s.BindPort,
		Method:     "aes-256-cfb",
	}

	parseServerConfig(config)

	handler.PrintDone()

	verbose := server.NewOption("verbose")

	if verbose.Has() {
		s.Verbose = true
		ss.SetDebug(true)
		debug = true
	}

	go func() {
		for {
			defer listener.Close()
			conn, err := listener.Accept()
			if err != nil {
				debug.Println("accept:", err)
				continue
			}
			go func(conn net.Conn) {
				conn = handler.MonitorConn(conn)
				if debug {
					debug.Printf("socks connect from %s\n", conn.RemoteAddr().String())
				}
				closed := false
				defer func() {
					if !closed {
						conn.Close()
					}
				}()

				var err error = nil
				if err = handShake(conn); err != nil {
					debug.Printf("socks handshake: %s", err)
					return
				}
				rawaddr, addr, err := getRequest(conn)
				if err != nil {
					debug.Println("error getting request:", err)
					return
				}
				// Sending connection established message immediately to client.
				// This some round trip time for creating socks connection with the client.
				// But if connection failed, the client will get connection reset error.
				_, err = conn.Write([]byte{0x05, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x43})
				if err != nil {
					debug.Println("send connection confirmation:", err)
					return
				}

				remote, err := createServerConn(rawaddr, addr)
				if err != nil {
					if len(servers.srvCipher) > 1 {
						debug.Println("Failed connect to all avaiable shadowsocks server")
					}
					return
				}
				handler.TrackOpenConn(addr)
				defer func() {
					if !closed {
						remote.Close()
					}
				}()

				go ss.PipeThenClose(conn, remote)
				ss.PipeThenClose(remote, conn)
				closed = true
				handler.TrackCloseConn(addr)

			}(conn)
		}
	}()
	handler.Wait()
	return nil
}
开发者ID:thomasf,项目名称:alkasir,代码行数:99,代码来源:service.go


示例8: main

func main() {
	log.SetOutput(os.Stdout)

	var cmdConfig ss.Config
	var printVer, debug bool
	var core int

	flag.BoolVar(&printVer, "version", false, "print version")
	flag.StringVar(&configFile, "c", "config.json", "specify config file")
	flag.StringVar(&cmdConfig.Password, "k", "", "password")
	flag.IntVar(&cmdConfig.ServerPort, "p", 0, "server port")
	flag.IntVar(&cmdConfig.Timeout, "t", 60, "connection timeout (in seconds)")
	flag.StringVar(&cmdConfig.Method, "m", "", "encryption method, default: aes-256-cfb")
	flag.IntVar(&cmdConfig.Net, "n", 0, "ipv4(4) or ipv6(6) or both(0), default is both")
	flag.IntVar(&core, "core", 0, "maximum number of CPU cores to use, default is determinied by logical CPUs on server")
	flag.BoolVar(&udp, "u", false, "UDP Relay")
	flag.BoolVar(&debug, "d", false, "print debug message")
	flag.Parse()

	if printVer {
		ss.PrintVersion()
		os.Exit(0)
	}

	ss.SetDebug(debug)

	var err error
	config, err = ss.ParseConfig(configFile)
	if err != nil {
		if !os.IsNotExist(err) {
			fmt.Fprintf(os.Stderr, "error reading %s: %v\n", configFile, err)
			os.Exit(1)
		}
		config = &cmdConfig
	} else {
		ss.UpdateConfig(config, &cmdConfig)
	}
	switch config.Net {
	case 4:
		netTcp = "tcp4"
		netUdp = "udp4"
	case 6:
		netTcp = "tcp6"
		netUdp = "udp6"
	default:
		netTcp = "tcp"
		netUdp = "udp"
	}
	if config.Method == "" {
		config.Method = "aes-256-cfb"
	}
	if err = ss.CheckCipherMethod(config.Method); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	if err = unifyPortPassword(config); err != nil {
		os.Exit(1)
	}
	if core > 0 {
		runtime.GOMAXPROCS(runtime.NumCPU())
	}
	ss.NewTraffic()
	for port, password := range config.PortPassword {
		go run(port, password)
		if udp && password[2] == "ok" {
			go runUDP(port, password)
		}
	}

	waitSignal()
}
开发者ID:better0332,项目名称:my-shadowsocks-go,代码行数:71,代码来源:server.go


示例9: main

func main() {
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
	log.SetOutput(os.Stdout)

	var cmdConfig ss.Config
	var printVer bool
	var core int

	flag.BoolVar(&printVer, "version", false, "print version")
	flag.StringVar(&configFile, "c", "config.json", "specify config file")
	flag.StringVar(&cmdConfig.Password, "k", "", "password")
	flag.IntVar(&cmdConfig.ServerPort, "p", 0, "server port")
	flag.IntVar(&cmdConfig.Timeout, "t", 60, "connection timeout (in seconds)")
	flag.StringVar(&cmdConfig.Method, "m", "", "encryption method, default: aes-256-cfb")
	flag.IntVar(&core, "core", 0, "maximum number of CPU cores to use, default is determinied by Go runtime")
	flag.BoolVar((*bool)(&debug), "d", false, "print debug message")

	flag.Parse()

	if printVer {
		ss.PrintVersion()
		os.Exit(0)
	}

	ss.SetDebug(debug)

	var err error
	config, err = ss.ParseConfig(configFile)
	if err != nil {
		if !os.IsNotExist(err) {
			fmt.Fprintf(os.Stderr, "error reading %s: %v\n", configFile, err)
			os.Exit(1)
		}
		config = &cmdConfig
	} else {
		ss.UpdateConfig(config, &cmdConfig)
	}
	if config.Method == "" {
		config.Method = "aes-256-cfb"
	}
	if err = ss.CheckCipherMethod(config.Method); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	if err = unifyPortPassword(config); err != nil {
		os.Exit(1)
	}
	if core > 0 {
		runtime.GOMAXPROCS(core)
	}

	initPortMap()
	if runtime.GOOS == "linux" {
		limitConfig.Init("/etc/limit.json")
	} else {
		limitConfig.Init("limit.json")
	}

	for port, password := range config.PortPassword {
		go run(port, password)
	}

	go runWeb()
	go DaysLimitLoop()

	waitSignal()
}
开发者ID:neil-zeng,项目名称:shadowsocks-go,代码行数:67,代码来源:server.go



注:本文中的github.com/shadowsocks/shadowsocks-go/shadowsocks.SetDebug函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang shadowsocks.SetReadTimeout函数代码示例发布时间:2022-05-28
下一篇:
Golang shadowsocks.PrintVersion函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap