-
Notifications
You must be signed in to change notification settings - Fork 4
/
itransport.js
100 lines (82 loc) · 2.35 KB
/
itransport.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
91
92
93
94
95
96
97
98
99
100
/**
* Node Trinity source code
* See LICENCE file at the top of the source tree
*
* ******************************************
*
* itransport.js
* Launcher for transport module
*
* ******************************************
*
* Authors: K. Zhidanov, A. Prudanov, M. Vasil'ev
*/
const argv = require('yargs').argv;
const fs = require('fs');
const DB = require('./DB').DB;
const Transport = require('./Transport').Hub;
const CONFIG_FILENAME = 'config.json';
let config = {
dbhost : 'localhost',
dbname : 'trinity',
dbuser : 'root',
dbpass : '',
loglevel : 'silly',
transport_on : 1
};
console.trace = function (...msg) {
console.log(...msg);
};
console.debug = function (...msg) {
console.log(...msg);
};
console.silly = function (...msg) {
console.log(...msg);
};
console.fatal = function (...msg) {
console.log(...msg);
process.exit(1);
};
console.info("Application started");
let config_filename = argv.config || CONFIG_FILENAME;
console.info('Loading config from', config_filename, '...');
let cfg = {};
try {
cfg = JSON.parse(fs.readFileSync(config_filename, 'utf8'));
config = Object.assign(config, cfg);
} catch (e) {
console.info('No configuration file found.')
}
config = Object.assign(config, argv);
console.info(`config = ${JSON.stringify(config)}`);
require('console-stamp')(console, {datePrefix: '[', pattern:'yyyy.mm.dd HH:MM:ss', level: config.loglevel, extend:{fatal:0, debug:4, trace:5, silly:6}, include:['silly', 'trace','debug','info','warn','error','fatal']});
let db = new DB({
host: config.dbhost,
port: config.dbport,
user: config.dbuser,
database: config.dbname,
password: config.dbpass.toString(),
dateStrings: true,
multipleStatements: true
},config);
BigInt.prototype.toJSON = function() { return this.toString() }
let start_transport = function(config, db) {
if (config.transport_on) {
console.info(`Starting Transport Hub process`);
let transport = new Transport(config, db);
transport.connect(config.peer);
} else {
console.info(`Transport Hub is OFF`);
}
};
/*
let starter = async function(config, db, callback) {
if(!db.isConnected){
setTimeout(starter, 1000, config, db, callback);
return;
}
callback(config, db);
};
starter(config, db, start_transport);
*/
start_transport(config, db);