Merge branch 'master' into unfurler-optional-puppeteer
This commit is contained in:
commit
2debea28c8
@ -228,34 +228,75 @@ export class Common {
|
|||||||
return d.toISOString().split('T')[0] + ' ' + d.toTimeString().split(' ')[0];
|
return d.toISOString().split('T')[0] + ' ' + d.toTimeString().split(' ')[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static formatSocket(publicKey: string, socket: {network: string, addr: string}): NodeSocket {
|
static findSocketNetwork(addr: string): {network: string | null, url: string} {
|
||||||
let network: string | null = null;
|
let network: string | null = null;
|
||||||
|
let url = addr.split('://')[1];
|
||||||
|
|
||||||
if (config.LIGHTNING.BACKEND === 'cln') {
|
if (!url) {
|
||||||
network = socket.network;
|
return {
|
||||||
} else if (config.LIGHTNING.BACKEND === 'lnd') {
|
network: null,
|
||||||
if (socket.addr.indexOf('onion') !== -1) {
|
url: addr,
|
||||||
if (socket.addr.split('.')[0].length >= 56) {
|
};
|
||||||
network = 'torv3';
|
}
|
||||||
} else {
|
|
||||||
network = 'torv2';
|
if (addr.indexOf('onion') !== -1) {
|
||||||
}
|
if (url.split('.')[0].length >= 56) {
|
||||||
} else if (socket.addr.indexOf('i2p') !== -1) {
|
network = 'torv3';
|
||||||
network = 'i2p';
|
|
||||||
} else {
|
} else {
|
||||||
const ipv = isIP(socket.addr.split(':')[0]);
|
network = 'torv2';
|
||||||
if (ipv === 4) {
|
|
||||||
network = 'ipv4';
|
|
||||||
} else if (ipv === 6) {
|
|
||||||
network = 'ipv6';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else if (addr.indexOf('i2p') !== -1) {
|
||||||
|
network = 'i2p';
|
||||||
|
} else if (addr.indexOf('ipv4') !== -1) {
|
||||||
|
const ipv = isIP(url.split(':')[0]);
|
||||||
|
if (ipv === 4) {
|
||||||
|
network = 'ipv4';
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
network: null,
|
||||||
|
url: addr,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else if (addr.indexOf('ipv6') !== -1) {
|
||||||
|
url = url.split('[')[1].split(']')[0];
|
||||||
|
const ipv = isIP(url);
|
||||||
|
if (ipv === 6) {
|
||||||
|
const parts = addr.split(':');
|
||||||
|
network = 'ipv6';
|
||||||
|
url = `[${url}]:${parts[parts.length - 1]}`;
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
network: null,
|
||||||
|
url: addr,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
network: null,
|
||||||
|
url: addr,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
publicKey: publicKey,
|
|
||||||
network: network,
|
network: network,
|
||||||
addr: socket.addr,
|
url: url,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static formatSocket(publicKey: string, socket: {network: string, addr: string}): NodeSocket {
|
||||||
|
if (config.LIGHTNING.BACKEND === 'cln') {
|
||||||
|
return {
|
||||||
|
publicKey: publicKey,
|
||||||
|
network: socket.network,
|
||||||
|
addr: socket.addr,
|
||||||
|
};
|
||||||
|
} else /* if (config.LIGHTNING.BACKEND === 'lnd') */ {
|
||||||
|
const formatted = this.findSocketNetwork(socket.addr);
|
||||||
|
return {
|
||||||
|
publicKey: publicKey,
|
||||||
|
network: formatted.network,
|
||||||
|
addr: formatted.url,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -503,6 +503,18 @@ class NodesApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update node sockets
|
||||||
|
*/
|
||||||
|
public async $updateNodeSockets(publicKey: string, sockets: {network: string; addr: string}[]): Promise<void> {
|
||||||
|
const formattedSockets = (sockets.map(a => a.addr).join(',')) ?? '';
|
||||||
|
try {
|
||||||
|
await DB.query(`UPDATE nodes SET sockets = ? WHERE public_key = ?`, [formattedSockets, publicKey]);
|
||||||
|
} catch (e) {
|
||||||
|
logger.err(`Cannot update node sockets for ${publicKey}. Reason: ${e instanceof Error ? e.message : e}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set all nodes not in `nodesPubkeys` as inactive (status = 0)
|
* Set all nodes not in `nodesPubkeys` as inactive (status = 0)
|
||||||
*/
|
*/
|
||||||
|
@ -57,6 +57,8 @@ class LightningStatsImporter {
|
|||||||
features: node.features,
|
features: node.features,
|
||||||
});
|
});
|
||||||
nodesInDb[node.pub_key] = node;
|
nodesInDb[node.pub_key] = node;
|
||||||
|
} else {
|
||||||
|
await nodesApi.$updateNodeSockets(node.pub_key, node.addresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
let hasOnion = false;
|
let hasOnion = false;
|
||||||
@ -369,7 +371,7 @@ class LightningStatsImporter {
|
|||||||
graph = JSON.parse(fileContent);
|
graph = JSON.parse(fileContent);
|
||||||
graph = await this.cleanupTopology(graph);
|
graph = await this.cleanupTopology(graph);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.debug(`Invalid topology file ${this.topologiesFolder}/${filename}, cannot parse the content`);
|
logger.debug(`Invalid topology file ${this.topologiesFolder}/${filename}, cannot parse the content. Reason: ${e instanceof Error ? e.message : e}`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,9 +421,10 @@ class LightningStatsImporter {
|
|||||||
const addressesParts = (node.addresses ?? '').split(',');
|
const addressesParts = (node.addresses ?? '').split(',');
|
||||||
const addresses: any[] = [];
|
const addresses: any[] = [];
|
||||||
for (const address of addressesParts) {
|
for (const address of addressesParts) {
|
||||||
|
const formatted = Common.findSocketNetwork(address);
|
||||||
addresses.push({
|
addresses.push({
|
||||||
network: '',
|
network: formatted.network,
|
||||||
addr: address
|
addr: formatted.url
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user