func clientSetup() (launched bool, listeners []net.Listener) { ptClientInfo, err := pt.ClientSetup(transports.Transports()) if err != nil { golog.Fatal(err) } ptClientProxy, err := ptGetProxy() if err != nil { golog.Fatal(err) } else if ptClientProxy != nil { ptProxyDone() } // Launch each of the client listeners. for _, name := range ptClientInfo.MethodNames { t := transports.Get(name) if t == nil { pt.CmethodError(name, "no such transport is supported") continue } f, err := t.ClientFactory(stateDir) if err != nil { pt.CmethodError(name, "failed to get ClientFactory") continue } ln, err := net.Listen("tcp", socksAddr) if err != nil { pt.CmethodError(name, err.Error()) continue } go clientAcceptLoop(f, ln, ptClientProxy) pt.Cmethod(name, socks5.Version(), ln.Addr()) log.Infof("%s - registered listener: %s", name, ln.Addr()) listeners = append(listeners, ln) launched = true } pt.CmethodsDone() return }
func serverSetup() (launched bool, listeners []net.Listener) { ptServerInfo, err := pt.ServerSetup(transports.Transports()) if err != nil { golog.Fatal(err) } for _, bindaddr := range ptServerInfo.Bindaddrs { name := bindaddr.MethodName t := transports.Get(name) if t == nil { pt.SmethodError(name, "no such transport is supported") continue } f, err := t.ServerFactory(stateDir, &bindaddr.Options) if err != nil { pt.SmethodError(name, err.Error()) continue } ln, err := net.ListenTCP("tcp", bindaddr.Addr) if err != nil { pt.SmethodError(name, err.Error()) continue } go serverAcceptLoop(f, ln, &ptServerInfo) if args := f.Args(); args != nil { pt.SmethodArgs(name, ln.Addr(), *args) } else { pt.SmethodArgs(name, ln.Addr(), nil) } log.Infof("%s - registered listener: %s", name, log.ElideAddr(ln.Addr().String())) listeners = append(listeners, ln) launched = true } pt.SmethodsDone() return }
func clientSetup() (launched bool, listeners []net.Listener) { ptClientInfo, err := pt.ClientSetup(transports.Transports()) if err != nil { golog.Fatal(err) } ptClientProxy, err := ptGetProxy() if err != nil { golog.Fatal(err) } else if ptClientProxy != nil { ptProxyDone() } configFile := os.Getenv("TCP_PROXY_CONFIG_FILE") bytes, er := ioutil.ReadFile(configFile) if er != nil { fmt.Println("unable to read config file ", configFile) golog.Fatal(err) } fmt.Println("parse config file ", configFile) config := parseConfig(bytes) // Launch each of the client listeners. for _, name := range ptClientInfo.MethodNames { t := transports.Get(name) if t == nil { pt.CmethodError(name, "no such transport is supported") continue } links, has := config[name] if !has { continue } f, err := t.ClientFactory(stateDir) if err != nil { pt.CmethodError(name, "failed to get ClientFactory") continue } for _, link := range links { fmt.Println("create tcp proxy ", name, link.ListenAddr, link.ServerAddr, link.PtArgs) ln, er := net.Listen("tcp", link.ListenAddr) if er != nil { pt.CmethodError(name, er.Error()) continue } go clientAcceptLoop(f, ln, ptClientProxy, link) pt.Cmethod(name, "tcp", ln.Addr()) log.Infof("%s - registered listener: %s", name, ln.Addr()) listeners = append(listeners, ln) launched = true } } pt.CmethodsDone() return }