mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-13 04:31:01 +00:00
Figure out node ip
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import * as WebSocket from 'ws';
|
||||
import * as EventEmitter from 'events';
|
||||
import * as iplocation from 'iplocation';
|
||||
import { timestamp, Maybe, Types, idGenerator } from '@dotstats/common';
|
||||
import { parseMessage, getBestBlock, Message, BestBlock, SystemInterval } from './message';
|
||||
|
||||
@@ -83,7 +84,9 @@ export default class Node {
|
||||
});
|
||||
}
|
||||
|
||||
public static fromSocket(socket: WebSocket): Promise<Node> {
|
||||
public static fromSocket(socket: WebSocket, ip: string): Promise<Node> {
|
||||
console.log('node ip', ip);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
function cleanup() {
|
||||
clearTimeout(timeout);
|
||||
|
||||
@@ -14,9 +14,15 @@ const telemetryFeed = new WebSocket.Server({ port: 8080 });
|
||||
console.log('Telemetry server listening on port 1024');
|
||||
console.log('Feed server listening on port 8080');
|
||||
|
||||
incomingTelemetry.on('connection', async (socket: WebSocket) => {
|
||||
const ipv4 = /[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/;
|
||||
|
||||
incomingTelemetry.on('connection', async (socket, req) => {
|
||||
try {
|
||||
const node = await Node.fromSocket(socket);
|
||||
const [ ip ] = (req.headers['x-forwarded-for'] || req.connection.remoteAddress || '0.0.0.0')
|
||||
.toString()
|
||||
.match(ipv4) || ['0.0.0.0'];
|
||||
|
||||
const node = await Node.fromSocket(socket, ip);
|
||||
|
||||
aggregator.addNode(node);
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user