Beispiel #1
0
func tcpServe(localConf *utils.LocalConf) {
	nl, err := net.Listen("tcp", fmt.Sprintf("%s:%d", localConf.Address, localConf.Port))
	if err != nil {
		utils.Fatalf("Create server error %s", err)
	}
	defer nl.Close()

	utils.Infof("Client listen on %s://%s:%d", localConf.Protocol, localConf.Address, localConf.Port)

	var handleFunc func(c protocols.Protocol)
	switch localConf.Protocol {
	case "http":
		handleFunc = handleHTTP
	case "socks5":
		handleFunc = handleSocks5
	}

	for {
		c, err := nl.Accept()
		if err != nil {
			utils.Errorf("Local connection accept error %s", err)
			continue
		}
		utils.Infof("Get local connection from %s", c.RemoteAddr())
		go handleFunc(c)
	}

}
Beispiel #2
0
func _HTTPHandler(conn protocols.Protocol, req *http.Request) {
	utils.Infof("Sending request %v %v \n", req.Method, req.URL.Host)

	rmProxyHeaders(req)
	dump, err := httputil.DumpRequest(req, true)
	if err != nil {
		utils.Fatalf("%s", err)
	}

	conn.Write(dump)
}
Beispiel #3
0
func main() {

	conf := utils.ParseSeverConf()
	for _, s := range conf.Server {
		se := &server{
			address: fmt.Sprintf("%s:%d", s.Address, s.Port),
			cg:      mika.NewCryptoGenerator(s.Method, s.Password),
		}
		servers = append(servers, se)
	}

	if len(servers) <= 0 {
		utils.Fatalf("Please configure server")
	}

	for _, localConf := range conf.Local {
		tcpServe(localConf)
	}
}
Beispiel #4
0
func listen(serverInfo *utils.ServerConf) {
	nl, err := net.Listen("tcp", fmt.Sprintf("%s:%d", serverInfo.Address, serverInfo.Port))
	if err != nil {
		utils.Fatalf("Create server error %s", err)
	}

	utils.Infof("Listen on %d\n", serverInfo.Port)
	cg := mika.NewCryptoGenerator(serverInfo.Method, serverInfo.Password)

	for {
		c, err := nl.Accept()
		if err != nil {
			utils.Errorf("Accept connection error %s", err)
			continue
		}

		go func() {
			tcpConn := &tcp.Conn{c, time.Duration(serverInfo.Timeout) * time.Second}
			handle(tcpConn, cg)
		}()
	}
}