Example #1
0
func tlsServerConfig() *tls.Config {
	cert, err := tls.LoadX509KeyPair("cert.pem", "key.pem")
	if err != nil {
		out.Fatalf("Could not read server certificate (cert.pem, key.pem): %v", err)
	}
	return &tls.Config{Certificates: []tls.Certificate{cert}}
}
Example #2
0
func handleConnection(src net.Conn) {
	cid := <-nextConnId

	var dst net.Conn
	var err error
	if Ssl {
		dst, err = tls.Dial("tcp", To, tlsClientConfig())
	} else {
		dst, err = net.Dial("tcp", To)
	}

	if err != nil {
		src.Close()
		out.Fatalf("Error connecting to dest: %v", err)
	}

	handler := handler.NewHandler(dst, src, cid)
	handler.Handle()
}
Example #3
0
func Listen() {
	event.PostGlobalf("Listening to [%v], forwarding to [%v]", From, To)

	var ln net.Listener
	var err error
	if Ssl {
		ln, err = tls.Listen("tcp", From, tlsServerConfig())
	} else {
		ln, err = net.Listen("tcp", From)
	}

	if err != nil {
		out.Fatalf("Could not open port: %v", err)
	}

	for {
		conn, err := ln.Accept()
		if err != nil {
			panic(err)
		}
		go handleConnection(conn)
	}
}