Upgrade dependencies and add socks proxy support

This commit is contained in:
Djuri Baars 2022-04-17 22:59:36 +02:00
parent 57734b2aab
commit bf3cf70a63
6 changed files with 1026 additions and 921 deletions

View File

@ -4,5 +4,8 @@ LND_REST_API_WS=wss://localhost:8080
LND_REST_API=https://localhost:8080
REJECT_UNAUTHORIZED=0
TLS_CERT_BASE64=ABCD=
USE_SOCKS_PROXY=0
SOCKS_PROXY_HOST=""
SOCKS_PROXY_PORT=1080
#MACAROON_FILE=readonly.macaroon
#TLS_CERT_FILE=tls.cert

View File

@ -29,7 +29,8 @@
"project": "./tsconfig.json"
},
"rules": {
"@typescript-eslint/no-unnecessary-condition": "off"
"@typescript-eslint/no-unnecessary-condition": "off",
"@typescript-eslint/naming-convention": "off"
}
}
],

View File

@ -7,27 +7,28 @@
"test": "test"
},
"dependencies": {
"@types/ws": "^8.2.2",
"axios": "^0.24.0",
"dotenv": "12",
"fastify": "^3.25.3",
"fastify-cors": "^6.0.2",
"fastify-decorators": "^3.10.0",
"fastify-helmet": "7.0",
"fastify-plugin": "^3.0.0",
"@types/ws": "^8.5.3",
"axios": "^0.26.1",
"dotenv": "16.0.0",
"fastify": "^3.28.0",
"fastify-cors": "^6.0.3",
"fastify-decorators": "^3.11.0",
"fastify-helmet": "7.0.1",
"fastify-plugin": "^3.0.1",
"fastify-sensible": "^3.1.2",
"fastify-socket.io": "^3.0.0",
"fastify-static": "^4.5.0",
"fastify-static": "^4.6.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.5.2",
"rxjs": "^7.5.5",
"socket.io": "^4.4.1",
"typescript": "^4.5.4",
"ws": "^8.4.0"
"socks-proxy-agent": "^6.2.0-beta.0",
"typescript": "^4.6.3",
"ws": "^8.5.0"
},
"devDependencies": {
"@shopify/eslint-plugin": "^41.0.1",
"@types/jest": "^27.4.0",
"@types/node": "^17.0.8",
"@types/node": "^17.0.24",
"@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/parser": "^5.8.1",
"axios-mock-adapter": "^1.20.0",

View File

@ -53,8 +53,7 @@ export default class ChannelController {
try {
return await this.lndService.getChannel(request.params.channelId);
}
catch {
} catch {
return reply.notFound();
}
}

View File

@ -1,6 +1,7 @@
import * as https from 'https';
import {existsSync, readFileSync} from 'fs';
import {SocksProxyAgent} from 'socks-proxy-agent';
import axios from 'axios';
import {Subject} from 'rxjs';
import WebSocket from 'ws';
@ -23,7 +24,7 @@ if (existsSync(process.env.MACAROON_FILE)) {
if (existsSync(process.env.TLS_CERT_FILE)) {
tlsCertData = readFileSync(process.env.TLS_CERT_FILE).toString('ascii');
} else {
const tlsCertData = Buffer.from(
tlsCertData = Buffer.from(
process.env.TLS_CERT_BASE64 || '',
'base64',
).toString('ascii');
@ -39,20 +40,37 @@ if (process.env.REJECT_UNAUTHORIZED) {
rejectUnauthorized = Boolean(Number(process.env.REJECT_UNAUTHORIZED));
}
const httpsAgent = new https.Agent({
let httpsAgent;
if (process.env.USE_SOCKS_PROXY === '1') {
httpsAgent = new SocksProxyAgent({
host: process.env.SOCKS_PROXY_HOST || undefined,
hostname: process.env.SOCKS_PROXY_HOST || undefined,
port: process.env.SOCKS_PROXY_PORT || undefined,
tls: {
rejectUnauthorized: false,
checkServerIdentity: () => undefined,
},
});
} else {
httpsAgent = new https.Agent({
rejectUnauthorized,
ca: tlsCertData,
});
});
}
axios.defaults.httpAgent = httpsAgent;
axios.defaults.httpsAgent = httpsAgent;
interface GraphUpdateResult {
result: {
// eslint-disable-next-line @typescript-eslint/naming-convention
error?: {
code: number;
message?: string;
details: any;
};
result?: {
node_updates: [];
// eslint-disable-next-line @typescript-eslint/naming-convention
channel_updates: [];
// eslint-disable-next-line @typescript-eslint/naming-convention
closed_chans: [];
};
}
@ -82,6 +100,7 @@ export class LndService {
this.ws = new WebSocket(
`${this.lndRestApiWsUrl}/v1/graph/subscribe?method=GET`,
{
agent: httpsAgent,
rejectUnauthorized,
ca: tlsCertData,
headers: {
@ -100,9 +119,13 @@ export class LndService {
this.ws.on('error', (err: Error) => {
console.log(`Error: ${err}`);
});
this.ws.on('ping', (event: Buffer) => {});
this.ws.on('ping', (_event: Buffer) => {});
this.ws.on('message', (event: WebSocket.RawData) => {
const data: GraphUpdateResult = JSON.parse(event.toString());
if (data.error) {
console.log(data.error);
return;
}
if (data.result.node_updates.length) {
this.nodeUpdateSubject.next(data.result.node_updates);

1868
yarn.lock

File diff suppressed because it is too large Load Diff