@@ -19,9 +19,10 @@ import (
1919)
2020
2121const (
22- clientStartTimeout = 30 * time .Second
23- clientStopTimeout = 10 * time .Second
24- defaultLogLevel = "warn"
22+ clientStartTimeout = 30 * time .Second
23+ clientStopTimeout = 10 * time .Second
24+ defaultLogLevel = "warn"
25+ defaultSSHDetectionTimeout = 20 * time .Second
2526)
2627
2728func main () {
@@ -207,11 +208,19 @@ func createDetectSSHServerMethod(client *netbird.Client) js.Func {
207208 host := args [0 ].String ()
208209 port := args [1 ].Int ()
209210
211+ timeoutMs := int (defaultSSHDetectionTimeout .Milliseconds ())
212+ if len (args ) >= 3 && ! args [2 ].IsNull () && ! args [2 ].IsUndefined () {
213+ timeoutMs = args [2 ].Int ()
214+ if timeoutMs <= 0 {
215+ return js .ValueOf ("error: timeout must be positive" )
216+ }
217+ }
218+
210219 return createPromise (func (resolve , reject js.Value ) {
211- ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
220+ ctx , cancel := context .WithTimeout (context .Background (), time . Duration ( timeoutMs ) * time .Millisecond )
212221 defer cancel ()
213222
214- serverType , err := detectSSHServerType (ctx , client , host , port )
223+ serverType , err := sshdetection . DetectSSHServerType (ctx , client , host , port )
215224 if err != nil {
216225 reject .Invoke (err .Error ())
217226 return
@@ -222,11 +231,6 @@ func createDetectSSHServerMethod(client *netbird.Client) js.Func {
222231 })
223232}
224233
225- // detectSSHServerType detects SSH server type using NetBird network connection
226- func detectSSHServerType (ctx context.Context , client * netbird.Client , host string , port int ) (sshdetection.ServerType , error ) {
227- return sshdetection .DetectSSHServerType (ctx , client , host , port )
228- }
229-
230234// createClientObject wraps the NetBird client in a JavaScript object
231235func createClientObject (client * netbird.Client ) js.Value {
232236 obj := make (map [string ]interface {})
0 commit comments