(ctx context.Context, networkAddr string, clientConfig *ssh.ClientConfig, currentClient *ssh.Client)
| 839 | } |
| 840 | |
| 841 | func connectInternal(ctx context.Context, networkAddr string, clientConfig *ssh.ClientConfig, currentClient *ssh.Client) (*ssh.Client, error) { |
| 842 | var clientConn net.Conn |
| 843 | var err error |
| 844 | if currentClient == nil { |
| 845 | d := net.Dialer{Timeout: clientConfig.Timeout} |
| 846 | blocklogger.Infof(ctx, "[conndebug] ssh dial %s\n", networkAddr) |
| 847 | clientConn, err = d.DialContext(ctx, "tcp", networkAddr) |
| 848 | if err != nil { |
| 849 | subCode := ClassifyDialErrorSubCode(err) |
| 850 | blocklogger.Infof(ctx, "[conndebug] ERROR dial error [%s]: %v\n", subCode, err) |
| 851 | return nil, utilds.MakeSubCodedError(ConnErrCode_Dial, subCode, err) |
| 852 | } |
| 853 | } else { |
| 854 | blocklogger.Infof(ctx, "[conndebug] ssh dial (from client) %s\n", networkAddr) |
| 855 | clientConn, err = currentClient.DialContext(ctx, "tcp", networkAddr) |
| 856 | if err != nil { |
| 857 | subCode := ClassifyDialErrorSubCode(err) |
| 858 | blocklogger.Infof(ctx, "[conndebug] ERROR dial error [%s]: %v\n", subCode, err) |
| 859 | return nil, utilds.MakeSubCodedError(ConnErrCode_ProxyJumpDial, subCode, err) |
| 860 | } |
| 861 | } |
| 862 | c, chans, reqs, err := ssh.NewClientConn(clientConn, networkAddr, clientConfig) |
| 863 | if err != nil { |
| 864 | blocklogger.Infof(ctx, "[conndebug] ERROR ssh auth/negotiation: %s\n", SimpleMessageFromPossibleConnectionError(err)) |
| 865 | return nil, err |
| 866 | } |
| 867 | blocklogger.Infof(ctx, "[conndebug] successful ssh connection to %s\n", networkAddr) |
| 868 | return ssh.NewClient(c, chans, reqs), nil |
| 869 | } |
| 870 | |
| 871 | func ConnectToClient(connCtx context.Context, opts *SSHOpts, currentClient *ssh.Client, jumpNum int32, connFlags *wconfig.ConnKeywords) (*ssh.Client, int32, error) { |
| 872 | blocklogger.Infof(connCtx, "[conndebug] ConnectToClient %s (jump:%d)...\n", opts.String(), jumpNum) |
no test coverage detected