Пример #1
0
// Generic connection handler
//
// This redelegates to more specific proxy handlers that contain the
// main proxy loop logic.
func handleConnection(proxy proxyBehavior,
	clientConn net.Conn, serverAddr string) {
	var err error

	// Log disconnections
	defer func() {
		if err != nil && err != io.EOF {
			fmt.Printf("Session exits with error: %v\n", err)
		} else {
			fmt.Printf("Session exits cleanly\n")
		}
	}()

	defer clientConn.Close()

	c := femebe.NewMessageStream("Client", clientConn, clientConn)

	serverConn, err := autoDial(serverAddr)
	if err != nil {
		fmt.Printf("Could not connect to server: %v\n", err)
	}

	b := femebe.NewMessageStream("Server", serverConn, serverConn)

	done := proxy.start(c, b)
	err = <-done
}
Пример #2
0
Файл: dogs.go Проект: pvh/femebe
func findServer(client femebe.MessageStream) (server femebe.MessageStream, err error) {
	msg, err := client.Next()
	if err != nil {
		return nil, err
	}

	var dbname string

	if femebe.IsStartupMessage(msg) {
		startupMsg := femebe.ReadStartupMessage(msg)
		fmt.Println("Got startup message:")
		for key, value := range startupMsg.Params {
			fmt.Printf("\t%v: %v\n", key, value)
		}
		dbname = startupMsg.Params["database"]
		fmt.Printf("dbname: %v\n", dbname)
	}

	serverAddr, _ := lookupServer(dbname)

	fmt.Printf("serverAddr: %v\n", serverAddr)

	serverConn, err := autoDial(serverAddr)
	if err != nil {
		fmt.Printf("Could not connect to server: %v\n", err)
	}

	server = femebe.NewMessageStream("Server", serverConn, serverConn)
	server.Send(msg)

	return server, nil
}
Пример #3
0
Файл: dogs.go Проект: pvh/femebe
// Generic connection handler
//
// This redelegates to more specific proxy handlers that contain the
// main proxy loop logic.
func handleConnection(proxy proxyBehavior, clientConn net.Conn) {
	var err error

	// Log disconnections
	defer func() {
		if err != nil && err != io.EOF {
			fmt.Printf("Session exits with error: %v\n", err)
		} else {
			fmt.Printf("Session exits cleanly\n")
		}
	}()

	defer clientConn.Close()

	c := femebe.NewMessageStream("Client", clientConn, clientConn)

	s, err := findServer(c)
	if err != nil {
		return
	}

	done := proxy.start(c, s)
	err = <-done
}