Unverified Commit b88d3909 authored by fishyds's avatar fishyds Committed by GitHub
Browse files

Add ip address cached to resolve network issue (#220)

* Add ip address cached to resolve network issue
parent 9bb479bb
......@@ -245,18 +245,27 @@ function cleanupUnitTest(): void {
Container.restore(ExperimentStartupInfo);
}
let cachedipv4Address : string = '';
/**
* Get IPv4 address of current machine
*/
function getIPV4Address(): string {
let ipv4Address : string = '';
if (cachedipv4Address && cachedipv4Address.length > 0) {
return cachedipv4Address;
}
for(const item of os.networkInterfaces().eth0) {
if(item.family === 'IPv4') {
ipv4Address = item.address;
if(os.networkInterfaces().eth0) {
for(const item of os.networkInterfaces().eth0) {
if(item.family === 'IPv4') {
cachedipv4Address = item.address;
return cachedipv4Address;
}
}
} else {
throw Error('getIPV4Address() failed because os.networkInterfaces().eth0 is undefined.');
}
return ipv4Address;
throw Error('getIPV4Address() failed because no valid IPv4 address found.')
}
export { generateParamFileName, getMsgDispatcherCommand, getLogDir, getExperimentRootDir,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment