@@ -97,13 +97,7 @@ type Dialer struct {
9797 config * ssh.ClientConfig
9898}
9999
100- func (d * Dialer ) SSHClient () * ssh.Client {
101- d .mut .Lock ()
102- defer d .mut .Unlock ()
103- return d .sshCli
104- }
105-
106- func (d * Dialer ) reset () error {
100+ func (d * Dialer ) Close () error {
107101 d .mut .Lock ()
108102 defer d .mut .Unlock ()
109103 if d .sshCli == nil {
@@ -114,10 +108,6 @@ func (d *Dialer) reset() error {
114108 return err
115109}
116110
117- func (d * Dialer ) Close () error {
118- return d .reset ()
119- }
120-
121111func (d * Dialer ) proxyDial (ctx context.Context , network , address string ) (net.Conn , error ) {
122112 proxyDial := d .ProxyDial
123113 if proxyDial == nil {
@@ -127,7 +117,7 @@ func (d *Dialer) proxyDial(ctx context.Context, network, address string) (net.Co
127117 return proxyDial (ctx , network , address )
128118}
129119
130- func (d * Dialer ) getCli (ctx context.Context ) (* ssh.Client , error ) {
120+ func (d * Dialer ) SSHClient (ctx context.Context ) (* ssh.Client , error ) {
131121 d .mut .Lock ()
132122 defer d .mut .Unlock ()
133123 cli := d .sshCli
@@ -158,7 +148,7 @@ func (d *Dialer) CommandDialContext(ctx context.Context, name string, args ...st
158148}
159149
160150func (d * Dialer ) commandDialContext (ctx context.Context , cmd string , retry int ) (net.Conn , error ) {
161- cli , err := d .getCli (ctx )
151+ cli , err := d .SSHClient (ctx )
162152 if err != nil {
163153 return nil , err
164154 }
@@ -173,7 +163,7 @@ func (d *Dialer) commandDialContext(ctx context.Context, cmd string, retry int)
173163 err = sess .Start (cmd )
174164 if err != nil {
175165 if retry != 0 {
176- d .reset ()
166+ d .Close ()
177167 return d .commandDialContext (ctx , cmd , retry - 1 )
178168 }
179169 return nil , err
@@ -207,14 +197,14 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.
207197}
208198
209199func (d * Dialer ) dialContext (ctx context.Context , network , address string , retry int ) (net.Conn , error ) {
210- cli , err := d .getCli (ctx )
200+ cli , err := d .SSHClient (ctx )
211201 if err != nil {
212202 return nil , err
213203 }
214204 conn , err := cli .Dial (network , address )
215205 if err != nil {
216206 if retry != 0 {
217- d .reset ()
207+ d .Close ()
218208 return d .dialContext (ctx , network , address , retry - 1 )
219209 }
220210 return nil , err
@@ -233,14 +223,14 @@ func (d *Dialer) Listen(ctx context.Context, network, address string) (net.Liste
233223}
234224
235225func (d * Dialer ) listen (ctx context.Context , network , address string , retry int ) (net.Listener , error ) {
236- cli , err := d .getCli (ctx )
226+ cli , err := d .SSHClient (ctx )
237227 if err != nil {
238228 return nil , err
239229 }
240230 listener , err := cli .Listen (network , address )
241231 if err != nil {
242232 if retry != 0 {
243- d .reset ()
233+ d .Close ()
244234 return d .listen (ctx , network , address , retry - 1 )
245235 }
246236 return nil , err
0 commit comments