func (s *tunnelSite) Dial(network string, addr string) (net.Conn, error) {
	s.log.Infof("[TUNNEL] dialing %v@%v through the tunnel", addr, s.domainName)

	try := func() (net.Conn, error) {
		remoteConn, err := s.nextConn()
		if err != nil {
			return nil, trace.Wrap(err)
		}
		var ch ssh.Channel
		ch, _, err = remoteConn.sshConn.OpenChannel(chanTransport, nil)
		if err != nil {
			remoteConn.markInvalid(err)
			return nil, trace.Wrap(err)
		}
		// we're creating a new SSH connection inside reverse SSH connection
		// as a new SSH channel:
		var dialed bool
		dialed, err = ch.SendRequest(chanTransportDialReq, true, []byte(addr))
		if err != nil {
			remoteConn.markInvalid(err)
			return nil, trace.Wrap(err)
		}
		if !dialed {
			remoteConn.markInvalid(err)
			return nil, trace.ConnectionProblem(
				nil, "remote server %v is not available", addr)
		}
		return utils.NewChConn(remoteConn.sshConn, ch), nil
	}

	for {
		conn, err := try()
		if err != nil {
			s.log.Errorf("[TUNNEL] Dial(addr=%v) failed: %v", addr, err)
			// we interpret it as a "out of connections and will try again"
			if trace.IsNotFound(err) {
				return nil, trace.Wrap(err)
			}
			continue
		}
		return conn, nil
	}
}
// Dial is used to connect a requesting client (say, tsh) to an SSH server
// located in a remote connected site, the connection goes through the
// reverse proxy tunnel.
Dial is used to connect a requesting client (say, tsh) to an SSH server
located in a remote connected site, the connection goes through the
reverse proxy tunnel.
// Dial is used to connect a requesting client ( say tsh ) to an SSH server // located in a remote connected site the connection goes through the // reverse proxy tunnel .
func (s *tunnelSite) Dial(network string, addr string) (net.Conn, error) {
	s.log.Infof("[TUNNEL] dialing %v@%v through the tunnel", addr, s.domainName)
	try := func() (net.Conn, error) {
		remoteConn, err := s.nextConn()
		if err != nil {
			return nil, trace.Wrap(err)
		}
		var ch ssh.Channel
		ch, _, err = remoteConn.sshConn.OpenChannel(chanTransport, nil)
		if err != nil {
			remoteConn.markInvalid(err)
			return nil, trace.Wrap(err)
		}
		var dialed bool
		dialed, err = ch.SendRequest(chanTransportDialReq, true, []byte(addr))
		if err != nil {
			remoteConn.markInvalid(err)
			return nil, trace.Wrap(err)
		}
		if !dialed {
			remoteConn.markInvalid(err)
			return nil, trace.ConnectionProblem(
				nil, "remote server %v is not available", addr)
		}
		return utils.NewChConn(remoteConn.sshConn, ch), nil
	}
	for {
		conn, err := try()
		if err != nil {
			s.log.Errorf("[TUNNEL] Dial(addr=%v) failed: %v", addr, err)
			if trace.IsNotFound(err) {
				return nil, trace.Wrap(err)
			}
			continue
		}
		return conn, nil
	}
}
func ( s * tunnelSite ) Dial ( network string , addr string ) ( net . Conn , error ) { s . log . Infof ( " " , addr , s . domainName ) try := func ( ) ( net . Conn , error ) { remoteConn , err := s . nextConn ( ) if err != nil { return nil , trace . Wrap ( err ) } var ch ssh . Channel ch , _ , err = remoteConn . sshConn . OpenChannel ( chanTransport , nil ) if err != nil { remoteConn . markInvalid ( err ) return nil , trace . Wrap ( err ) } var dialed bool dialed , err = ch . SendRequest ( chanTransportDialReq , true , [ ] byte ( addr ) ) if err != nil { remoteConn . markInvalid ( err ) return nil , trace . Wrap ( err ) } if ! dialed { remoteConn . markInvalid ( err ) return nil , trace . ConnectionProblem ( nil , " " , addr ) } return utils . NewChConn ( remoteConn . sshConn , ch ) , nil } for { conn , err := try ( ) if err != nil { s . log . Errorf ( " " , addr , err ) if trace . IsNotFound ( err ) { return nil , trace . Wrap ( err ) } continue } return conn , nil } }
Dial is used to connect a requesting client (say, tsh) to an SSH server
located in a remote connected site, the connection goes through the
reverse proxy tunnel.
Dial is used to connect a requesting client ( say tsh ) to an SSH server located in a remote connected site the connection goes through the reverse proxy tunnel .
// we're creating a new SSH connection inside reverse SSH connection // as a new SSH channel: // we interpret it as a "out of connections and will try again"