// proxyToSite starts proxying all traffic received from Postgres client
// between this proxy and Teleport database service over reverse tunnel.
proxyToSite starts proxying all traffic received from Postgres client
between this proxy and Teleport database service over reverse tunnel.
// proxyToSite starts proxying all traffic received from Postgres client // between this proxy and Teleport database service over reverse tunnel .
func (p *Proxy) proxyToSite(ctx context.Context, clientConn, siteConn net.Conn, startupMessage *pgproto3.StartupMessage) (retErr error) {
	frontend := pgproto3.NewFrontend(pgproto3.NewChunkReader(siteConn), siteConn)
	err := frontend.Send(startupMessage)
	if err != nil {
		return trace.Wrap(err)
	}
	errCh := make(chan error, 2)
	go func() {
		defer p.Log.Debug("Stop proxying from client to site.")
		defer siteConn.Close()
		defer clientConn.Close()
		_, err := io.Copy(siteConn, clientConn)
		errCh <- err
	}()
	go func() {
		defer p.Log.Debug("Stop proxying from site to client.")
		defer siteConn.Close()
		defer clientConn.Close()
		_, err := io.Copy(clientConn, siteConn)
		errCh <- err
	}()
	var errs []error
	for i := 0; i < 2; i++ {
		select {
		case err := <-errCh:
			if err != nil && err != io.EOF && !strings.Contains(err.Error(), "use of closed network connection") {
				p.Log.WithError(err).Warn("Connection problem.")
				errs = append(errs, err)
			}
		case <-ctx.Done():
			return trace.ConnectionProblem(nil, "context is closing")
		}
	}
	return trace.NewAggregate(errs...)
}
func ( p * Proxy ) proxyToSite ( ctx context . Context , clientConn , siteConn net . Conn , startupMessage * pgproto3 . StartupMessage ) ( retErr error ) { frontend := pgproto3 . NewFrontend ( pgproto3 . NewChunkReader ( siteConn ) , siteConn ) err := frontend . Send ( startupMessage ) if err != nil { return trace . Wrap ( err ) } errCh := make ( chan error , 2 ) go func ( ) { defer p . Log . Debug ( " " ) defer siteConn . Close ( ) defer clientConn . Close ( ) _ , err := io . Copy ( siteConn , clientConn ) errCh <- err } ( ) go func ( ) { defer p . Log . Debug ( " " ) defer siteConn . Close ( ) defer clientConn . Close ( ) _ , err := io . Copy ( clientConn , siteConn ) errCh <- err } ( ) var errs [ ] error for i := 0 ; i < 2 ; i ++ { select { case err := <- errCh : if err != nil && err != io . EOF && ! strings . Contains ( err . Error ( ) , " " ) { p . Log . WithError ( err ) . Warn ( " " ) errs = append ( errs , err ) } case <- ctx . Done ( ) : return trace . ConnectionProblem ( nil , " " ) } } return trace . NewAggregate ( errs ... ) }
proxyToSite starts proxying all traffic received from Postgres client
between this proxy and Teleport database service over reverse tunnel.
proxyToSite starts proxying all traffic received from Postgres client between this proxy and Teleport database service over reverse tunnel .
// Frontend acts as a client for the Postgres wire protocol. // Pass the startup message along to the Teleport database server.