2019-07-03 01:41:05 +02:00
|
|
|
import { config, logger } from "./env";
|
2019-06-28 03:46:48 +02:00
|
|
|
import cluster from "cluster";
|
|
|
|
import WebSocket from "ws";
|
|
|
|
import sleep from "sleep";
|
|
|
|
import Consumer from "./consumer";
|
2019-07-03 17:56:07 +02:00
|
|
|
import Connector from "./connector";
|
2019-06-28 03:46:48 +02:00
|
|
|
|
|
|
|
if (cluster.isMaster) {
|
|
|
|
|
|
|
|
const worker = cluster.fork();
|
|
|
|
|
|
|
|
|
|
|
|
if (config.testMode){
|
|
|
|
// const update = {
|
|
|
|
// data: {
|
|
|
|
// withdrawals: ["124.40.52.0/22"],
|
|
|
|
// peer: "124.0.0.2"
|
|
|
|
// },
|
|
|
|
// type: "ris_message"
|
|
|
|
// };
|
|
|
|
|
|
|
|
const update = {
|
|
|
|
data: {
|
|
|
|
announcements: [{
|
|
|
|
prefixes: ["124.40.52.0/22"],
|
|
|
|
next_hop: "124.0.0.2"
|
|
|
|
}],
|
|
|
|
peer: "124.0.0.2",
|
|
|
|
path: "1,2,3,2914".split(",")
|
|
|
|
},
|
|
|
|
type: "ris_message"
|
|
|
|
};
|
|
|
|
|
|
|
|
const message = JSON.stringify(update);
|
|
|
|
|
|
|
|
while (true){
|
|
|
|
worker.send(message);
|
|
|
|
sleep.sleep(1);
|
|
|
|
}
|
2019-06-29 03:35:53 +02:00
|
|
|
|
2019-06-28 03:46:48 +02:00
|
|
|
} else {
|
|
|
|
|
2019-06-29 03:35:53 +02:00
|
|
|
const ws = new WebSocket(config.websocketDataService);
|
2019-06-28 03:46:48 +02:00
|
|
|
|
|
|
|
ws.on('message', (message) => {
|
|
|
|
worker.send(message);
|
|
|
|
});
|
|
|
|
|
|
|
|
ws.on('open', () => {
|
|
|
|
ws.send(JSON.stringify({
|
|
|
|
type: "ris_subscribe",
|
|
|
|
data: config.wsParams
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
ws.on('close', function close() {
|
2019-06-30 01:42:58 +02:00
|
|
|
logger.log({
|
|
|
|
level: 'info',
|
|
|
|
message: 'Web socket disconnected'
|
|
|
|
});
|
2019-06-28 03:46:48 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2019-07-03 01:41:05 +02:00
|
|
|
new Consumer();
|
2019-06-28 03:46:48 +02:00
|
|
|
}
|