This repository was archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 382
/
Copy pathconfigLoader.js
90 lines (77 loc) · 3.69 KB
/
configLoader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (C) <2019> Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
'use strict';
var fs = require('fs');
var toml = require('toml');
var networkHelper = require('./networkHelper');
module.exports.load = () => {
var config;
try {
config = toml.parse(fs.readFileSync('./agent.toml')) || {};
config.agent = config.agent || {};
config.agent.maxProcesses = config.agent.maxProcesses || 16;
config.agent.prerunProcesses = config.agent.prerunProcesses || 2;
config.cluster = config.cluster || {};
config.cluster.name = config.cluster.name || 'owt-cluster';
config.cluster.worker = config.cluster.worker || {};
config.cluster.worker.ip = config.cluster.worker.ip || (networkHelper.getAddress("firstEnumerated") || {}).ip || 'unkown';
config.cluster.worker.join_retry = config.cluster.worker.join_retry || 60;
config.cluster.worker.load = config.cluster.worker.load || {};
config.cluster.worker.load.max = config.cluster.max_load || 0.85;
config.cluster.worker.load.period = config.cluster.report_load_interval || 1000;
config.cluster.worker.load.item = {
name: 'network',
interf: 'lo',
max_scale: config.cluster.network_max_scale || 1000
};
config.capacity = config.capacity || {};
config.capacity.isps = config.capacity.isps || [];
config.capacity.regions = config.capacity.regions || [];
config.internal.ip_address = config.internal.ip_address || '';
config.internal.network_interface = config.internal.network_interface || undefined;
config.internal.minport = config.internal.minport || 0;
config.internal.maxport = config.internal.maxport || 0;
if (!config.internal.ip_address) {
let addr = networkHelper.getAddress(config.internal.network_interface || "firstEnumerated");
if (!addr) {
console.error("Can't get internal IP address");
process.exit(1);
}
config.internal.ip_address = addr.ip;
}
config.webrtc = config.webrtc || {};
config.webrtc.stunserver = config.webrtc.stunserver || '';
config.webrtc.stunport = config.webrtc.stunport || 0;
config.webrtc.minport = config.webrtc.minport || 0;
config.webrtc.maxport = config.webrtc.maxport || 0;
config.webrtc.keystorePath = config.webrtc.keystorePath || '';
config.webrtc.num_workers = config.webrtc.num_workers || 24;
config.webrtc.use_nicer = config.webrtc.use_nicer || false;
config.webrtc.io_workers = config.webrtc.io_workers || 8;
config.webrtc.network_interfaces = config.webrtc.network_interfaces || [];
config.webrtc.audio_minport = config.webrtc.audio_minport || 0;
config.webrtc.audio_maxport = config.webrtc.audio_maxport || 0;
config.webrtc.video_minport = config.webrtc.video_minport || 0;
config.webrtc.video_maxport = config.webrtc.video_maxport || 0;
config.webrtc.screen_minport = config.webrtc.screen_minport || 0;
config.webrtc.screen_maxport = config.webrtc.screen_maxport || 0;
config.webrtc.network_interfaces.forEach(item => {
let addr = networkHelper.getAddress(item.name);
if (!addr) {
console.error("Can't get webrtc IP address");
process.exit(1);
}
item.ip_address = addr.ip;
// Parse webrtc ip_address variables from ENV.
if (item.replaced_ip_address && item.replaced_ip_address.indexOf('$') == 0) {
item.replaced_ip_address = process.env[item.replaced_ip_address.substr(1)];
console.log('ENV: config.webrtc.network_interfaces[' + item.name + '].replaced_ip_address=' + item.replaced_ip_address);
}
});
return config;
} catch (e) {
console.error('Parsing config error on line ' + e.line + ', column ' + e.column + ': ' + e.message);
process.exit(1);
}
};