MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / DialWithTimeout

Function DialWithTimeout

core/utils/ssh/ssh.go:248–269  ·  view source on GitHub ↗
(network, addr string, useProxy bool, config *gossh.ClientConfig)

Source from the content-addressed store, hash-verified

246}
247
248func DialWithTimeout(network, addr string, useProxy bool, config *gossh.ClientConfig) (*gossh.Client, error) {
249 var conn net.Conn
250 var err error
251 if useProxy {
252 conn, err = loadSSHConnByProxy(network, addr, config.Timeout)
253 } else {
254 conn, err = net.DialTimeout(network, addr, config.Timeout)
255 }
256 if err != nil {
257 return nil, err
258 }
259 _ = conn.SetDeadline(time.Now().Add(config.Timeout))
260 c, chans, reqs, err := gossh.NewClientConn(conn, addr, config)
261 if err != nil {
262 return nil, err
263 }
264 if err := conn.SetDeadline(time.Time{}); err != nil {
265 conn.Close()
266 return nil, fmt.Errorf("clear deadline failed: %v", err)
267 }
268 return gossh.NewClient(c, chans, reqs), nil
269}
270
271func loadSSHConnByProxy(network, addr string, timeout time.Duration) (net.Conn, error) {
272 settingRepo := repo.NewISettingRepo()

Callers 1

NewClientFunction · 0.85

Calls 2

loadSSHConnByProxyFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected