Ejemplo n.º 1
0
func handleConnection(frontconn net.Conn) {
	frontaddr := frontconn.RemoteAddr().String()
	log.Println("ACCEPTED frontend", frontconn, frontaddr)
	defer func() {
		if err := recover(); err != nil {
			log.Println("ERROR frontend", frontconn, frontaddr, err)
		}
		frontconn.Close()
		log.Println("DISCONNECTED frontend", frontconn, frontaddr)
	}()

	log.Printf("trying to connect to %s...\n", BACKEND)
	backconn, err := net.Dial("tcp", BACKEND)
	if err != nil {
		log.Printf("failed to connect to %s: %s\n", BACKEND, err)
		return
	}

	backaddr := backconn.RemoteAddr().String()
	log.Println("CONNECTED backend", backconn, backaddr)
	defer func() {
		backconn.Close()
		log.Println("DISCONNECTED backend", backconn, backaddr)
	}()

	if len(CIPHER) > 0 {
		performConnect(frontconn, common.NewXReadWriter(backconn, CIPHER))
	} else {
		performConnect(frontconn, backconn)
	}
}
Ejemplo n.º 2
0
func handleConnection(frontconn net.Conn) {
	frontaddr := frontconn.RemoteAddr().String()
	log.Println("ACCEPTED frontend", frontconn, frontaddr)
	defer func() {
		if err := recover(); err != nil {
			log.Println("ERROR frontend", frontconn, frontaddr, err)
		}
		frontconn.Close()
		log.Println("DISCONNECTED frontend", frontconn, frontaddr)
	}()

	err := frontconn.SetDeadline(common.AfterSeconds(60))
	if err != nil {
		panic(err)
	}

	if len(CIPHER) > 0 {
		handleSocks5(common.NewXReadWriter(frontconn, CIPHER))
	} else {
		handleSocks5(frontconn)
	}
}