@@ -97,13 +97,7 @@ type Dialer struct {
97
97
config * ssh.ClientConfig
98
98
}
99
99
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 {
107
101
d .mut .Lock ()
108
102
defer d .mut .Unlock ()
109
103
if d .sshCli == nil {
@@ -114,10 +108,6 @@ func (d *Dialer) reset() error {
114
108
return err
115
109
}
116
110
117
- func (d * Dialer ) Close () error {
118
- return d .reset ()
119
- }
120
-
121
111
func (d * Dialer ) proxyDial (ctx context.Context , network , address string ) (net.Conn , error ) {
122
112
proxyDial := d .ProxyDial
123
113
if proxyDial == nil {
@@ -127,7 +117,7 @@ func (d *Dialer) proxyDial(ctx context.Context, network, address string) (net.Co
127
117
return proxyDial (ctx , network , address )
128
118
}
129
119
130
- func (d * Dialer ) getCli (ctx context.Context ) (* ssh.Client , error ) {
120
+ func (d * Dialer ) SSHClient (ctx context.Context ) (* ssh.Client , error ) {
131
121
d .mut .Lock ()
132
122
defer d .mut .Unlock ()
133
123
cli := d .sshCli
@@ -158,7 +148,7 @@ func (d *Dialer) CommandDialContext(ctx context.Context, name string, args ...st
158
148
}
159
149
160
150
func (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 )
162
152
if err != nil {
163
153
return nil , err
164
154
}
@@ -173,7 +163,7 @@ func (d *Dialer) commandDialContext(ctx context.Context, cmd string, retry int)
173
163
err = sess .Start (cmd )
174
164
if err != nil {
175
165
if retry != 0 {
176
- d .reset ()
166
+ d .Close ()
177
167
return d .commandDialContext (ctx , cmd , retry - 1 )
178
168
}
179
169
return nil , err
@@ -207,14 +197,14 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.
207
197
}
208
198
209
199
func (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 )
211
201
if err != nil {
212
202
return nil , err
213
203
}
214
204
conn , err := cli .Dial (network , address )
215
205
if err != nil {
216
206
if retry != 0 {
217
- d .reset ()
207
+ d .Close ()
218
208
return d .dialContext (ctx , network , address , retry - 1 )
219
209
}
220
210
return nil , err
@@ -233,14 +223,14 @@ func (d *Dialer) Listen(ctx context.Context, network, address string) (net.Liste
233
223
}
234
224
235
225
func (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 )
237
227
if err != nil {
238
228
return nil , err
239
229
}
240
230
listener , err := cli .Listen (network , address )
241
231
if err != nil {
242
232
if retry != 0 {
243
- d .reset ()
233
+ d .Close ()
244
234
return d .listen (ctx , network , address , retry - 1 )
245
235
}
246
236
return nil , err
0 commit comments