func (context *bootContext) startClient() { defer func() { ex.CatchException(recover()) sigChan <- t.Bye }() var conf = t.Parse_d5cFile(context.config) context.setLogVerbose(conf.Verbose) log.Info(versionString()) log.Infoln("Socks5/Http is working at", conf.ListenAddr) mgr := NewClientMgr(conf) context.statser = mgr ln, err := net.ListenTCP("tcp", conf.ListenAddr) if err != nil { log.Fatalln(err) } defer ln.Close() for { conn, err := ln.Accept() if err == nil { go mgr.selectClientServ(conn) } else { t.SafeClose(conn) } } }
func (context *bootContext) startServer() { defer func() { ex.CatchException(recover()) sigChan <- t.Bye }() var conf = t.Parse_d5sFile(context.config) context.setLogVerbose(conf.Verbose) log.Info(versionString()) log.Infoln("Server is listening on", conf.ListenAddr) ln, err := net.ListenTCP("tcp", conf.ListenAddr) if err != nil { log.Fatalln(err) } defer ln.Close() dhKeys := t.GenerateDHKeyPairs() server := t.NewServer(conf, dhKeys) context.statser = server for { conn, err := ln.AcceptTCP() if err == nil { go server.TunnelServe(conn) } else { t.SafeClose(conn) } } }
func (m *clientMgr) selectClientServ(conn net.Conn) { if client := m.selectClient(); client != nil { client.ClientServe(conn) } else { t.SafeClose(conn) } }