mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-11 14:11:11 +00:00
Figure out node ip
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
declare module 'iplocation' {
|
||||
namespace iplocation {
|
||||
export interface LocationData {
|
||||
as?: string;
|
||||
city?: string;
|
||||
country?: string;
|
||||
countryCode?: string;
|
||||
isp?: string;
|
||||
lat: number;
|
||||
lon: number;
|
||||
org?: string;
|
||||
query?: string;
|
||||
region?: string;
|
||||
regionName?: string;
|
||||
status: string;
|
||||
timezone?: string;
|
||||
zip?: string;
|
||||
}
|
||||
}
|
||||
|
||||
function iplocation(ip: string, callback: (err: Error, result: iplocation.LocationData) => void): void;
|
||||
|
||||
export = iplocation;
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
"@types/node": "^10.3.3",
|
||||
"@types/ws": "^5.1.2",
|
||||
"express": "^4.16.3",
|
||||
"iplocation": "^5.0.1",
|
||||
"typescript": "^2.9.2",
|
||||
"ws": "5.2.0"
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"outDir": "build"
|
||||
},
|
||||
"include": [
|
||||
"./src/**/*.ts"
|
||||
"./src/**/*.ts",
|
||||
"./declarations/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -9,11 +9,6 @@
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.App-logo {
|
||||
animation: App-logo-spin infinite 20s linear;
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.App-list {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
|
||||
@@ -1950,7 +1950,7 @@ date-now@^0.1.4:
|
||||
version "0.1.4"
|
||||
resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b"
|
||||
|
||||
debug@2.6.9, debug@^2.1.2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.6, debug@^2.6.8, debug@^2.6.9:
|
||||
debug@2.6.9, debug@^2.1.2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.3, debug@^2.6.6, debug@^2.6.8, debug@^2.6.9:
|
||||
version "2.6.9"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
|
||||
dependencies:
|
||||
@@ -3382,6 +3382,10 @@ invert-kv@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6"
|
||||
|
||||
ip-regex@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-2.1.0.tgz#fa78bf5d2e6913c911ce9f819ee5146bb6d844e9"
|
||||
|
||||
ip@^1.1.0, ip@^1.1.5:
|
||||
version "1.1.5"
|
||||
resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.5.tgz#bdded70114290828c0a039e72ef25f5aaec4354a"
|
||||
@@ -3390,6 +3394,14 @@ ipaddr.js@1.6.0:
|
||||
version "1.6.0"
|
||||
resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.6.0.tgz#e3fa357b773da619f26e95f049d055c72796f86b"
|
||||
|
||||
iplocation@^5.0.1:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/iplocation/-/iplocation-5.0.1.tgz#558bba3fbd77fff1784f5fa41fa5c07cc04dbabd"
|
||||
dependencies:
|
||||
debug "^2.6.3"
|
||||
ip-regex "^2.1.0"
|
||||
request "^2.81.0"
|
||||
|
||||
is-absolute-url@^2.0.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/is-absolute-url/-/is-absolute-url-2.1.0.tgz#50530dfb84fcc9aa7dbe7852e83a37b93b9f2aa6"
|
||||
@@ -5953,7 +5965,7 @@ request-promise-native@^1.0.5:
|
||||
stealthy-require "^1.1.0"
|
||||
tough-cookie ">=2.3.3"
|
||||
|
||||
request@^2.83.0:
|
||||
request@^2.81.0, request@^2.83.0:
|
||||
version "2.87.0"
|
||||
resolved "https://registry.yarnpkg.com/request/-/request-2.87.0.tgz#32f00235cd08d482b4d0d68db93a829c0ed5756e"
|
||||
dependencies:
|
||||
|
||||
Reference in New Issue
Block a user