Skip to content

Commit d5437e0

Browse files
author
Kanhaiya Lal Singh
committed
Logging + Updated readme for new flags
- egressOnly: Uses proxy settings only for outbound requests. - ingressOnly: Uses proxy settings only for inbound requests. - dns: Comma separated list of dns servers - sshConnType: Specify type of ssh connection (over_22, over_443, over_ws) - mode: Specifies in which mode tunnel should run [ssh,ws] - nows: Force tunnel to run in non websocket mode
1 parent 370bf1d commit d5437e0

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ tunnelArguments = {
322322
logFile: '/lambdatest/logs.txt'
323323
};
324324
```
325+
- egressOnly: Uses proxy settings only for outbound requests.
326+
- ingressOnly: Uses proxy settings only for inbound requests.
327+
- dns: Comma separated list of dns servers
328+
- sshConnType: Specify type of ssh connection (over_22, over_443, over_ws)
329+
- mode: Specifies in which mode tunnel should run [ssh,ws]
330+
- nows: Force tunnel to run in non websocket mode
325331

326332
## Contribute
327333

lib/config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ function setupLogger_(options, jsonResponse) {
8181
reqOptions.agent = new HttpsProxyAgent(proxyOpts);
8282
}
8383
var req = https.request(reqOptions, res => {
84-
res.on('data', d => {
85-
process.stdout.write(d);
86-
});
84+
res.on('data', _ => {});
8785
});
8886

8987
req.on('error', _ => {});

lib/tunnel.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ function runBinary_(self, retries, fnCallback) {
317317
self.isProcessRunning = true;
318318
isCallback = true;
319319
self.getTunnelName(function(tunnelName) {
320+
if (tunnelName === null) {
321+
return fnCallback(true, false);
322+
}
320323
console.log(`Tunnel successfully initiated. You can start testing now`);
321324
return fnCallback(null, true);
322325
});
@@ -841,7 +844,6 @@ function getBinaryPath_(that, options, fnCallback) {
841844
*/
842845
function retryTunnelName_(self, infoAPIPort, retries, fnCallback) {
843846
try {
844-
var timeoutId = null;
845847
// Check whether max retries is reached ?.
846848
if (retries >= 0) {
847849
// local Server path for getting tunnelName
@@ -856,14 +858,11 @@ function retryTunnelName_(self, infoAPIPort, retries, fnCallback) {
856858
response.on('end', () => {
857859
// After successfully getting name clear the timeout and return name
858860
if (response.statusCode === 200) {
859-
clearTimeout_(timeoutId);
860861
if (typeof json === 'string') json = JSON.parse(json);
861862
return fnCallback((json.data && json.data.tunnelName) || null);
862863
} else {
863-
clearTimeout_(timeoutId);
864-
timeoutId = setTimeout(function() {
865-
retryTunnelName_(self, infoAPIPort, retries - 1, fnCallback);
866-
}, 500);
864+
sleep(500);
865+
retryTunnelName_(self, infoAPIPort, retries - 1, fnCallback);
867866
}
868867
});
869868
})
@@ -876,21 +875,20 @@ function retryTunnelName_(self, infoAPIPort, retries, fnCallback) {
876875
'Getting error while trying to get the tunnel name from running local server. Error : ' +
877876
e
878877
);
879-
clearTimeout_(timeoutId);
880878
// wait .5s for next retries
881-
timeoutId = setTimeout(function() {
882-
retryTunnelName_(self, infoAPIPort, retries - 1, fnCallback);
883-
}, 500);
879+
sleep(500);
880+
retryTunnelName_(self, infoAPIPort, retries - 1, fnCallback);
884881
});
885882
} else {
886-
clearTimeout_(timeoutId);
883+
sleep(500);
887884
logger.log(
888885
self.options['user'],
889886
self.options['key'],
890887
{ filename: __filename },
891888
self.options,
892889
'Number of retries to to get tunnel name exceeded.'
893890
);
891+
console.log('Number of retries to to get tunnel name exceeded.');
894892
return fnCallback(null);
895893
}
896894
} catch (e) {
@@ -924,12 +922,11 @@ function clearTimeout_(timeoutId) {
924922
function killProcess_(that, fnCallback) {
925923
that.proc.on('exit', function() {
926924
if (that.proc.pid) {
927-
setTimeout(function() {
928-
try {
929-
process.kill(that.proc.pid);
930-
} catch (err) {}
931-
return fnCallback();
932-
}, 500);
925+
sleep(500);
926+
try {
927+
process.kill(that.proc.pid);
928+
} catch (err) {}
929+
return fnCallback();
933930
}
934931
return fnCallback();
935932
});
@@ -940,5 +937,9 @@ function killProcess_(that, fnCallback) {
940937
that.proc.kill('SIGINT');
941938
}
942939
}
940+
function sleep( sleepDuration ){
941+
var now = new Date().getTime();
942+
while(new Date().getTime() < now + sleepDuration){ /* do nothing */ }
943+
}
943944
module.exports = Tunnel;
944945
module.exports.Tunnel = Tunnel;

0 commit comments

Comments
 (0)