Exemple #1
0
func (t *Tunnel) handlePublic(publicConn conn.Conn) {
	defer publicConn.Close()
	defer t.recoverPanic("Tunnel.handlePublic")

	//	publicConn.Info("New connection from %v", publicConn.RemoteAddr())
	log.Printf("[INFO] New connection from %v\n", publicConn.RemoteAddr())
	// connection hook
	if err := t.hooks.OnConnectionOpen(t, publicConn); err != nil {
		//		t.Error("OnConnectionOpen hook failed: %v", err)
		log.Printf("[ERROR] OnConnectionOpen hook failed: %v\n", err)
		return
	}

	startTime := time.Now()

	// open a proxy stream
	proxyConn, err := t.sess.openProxy(publicConn.RemoteAddr().String(), t.url)
	if err != nil {
		//		t.Error("Failed to open proxy connection: %v", err)
		log.Printf("[ERROR] Failed to open proxy connection: %v\n", err)
		return
	}
	defer proxyConn.Close()

	// join the public and proxy connections
	bytesIn, bytesOut := conn.Join(publicConn, proxyConn)

	if err = t.hooks.OnConnectionClose(t, publicConn, time.Now().Sub(startTime), bytesIn, bytesOut); err != nil {
		//		t.Error("OnConnectionClose hook failed: %v", err)
		log.Printf("[ERROR] OnConnectionClose hook failed: %v\n", err)
		return
	}
}