@bsv/overlay-express 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/package.json +14 -11
- package/dist/cjs/src/BanService.js +2 -2
- package/dist/cjs/src/BanService.js.map +1 -1
- package/dist/cjs/src/OverlayExpress.js +165 -189
- package/dist/cjs/src/OverlayExpress.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/BanService.js +2 -2
- package/dist/esm/src/BanService.js.map +1 -1
- package/dist/esm/src/OverlayExpress.js +160 -186
- package/dist/esm/src/OverlayExpress.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/OverlayExpress.d.ts +23 -1
- package/dist/types/src/OverlayExpress.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +27 -24
- package/src/BanService.ts +2 -2
- package/src/OverlayExpress.ts +170 -196
|
@@ -18,7 +18,7 @@ export class BanService {
|
|
|
18
18
|
*/
|
|
19
19
|
sanitize(value) {
|
|
20
20
|
if (typeof value !== 'string') {
|
|
21
|
-
throw new
|
|
21
|
+
throw new TypeError('Invalid input: expected a string value');
|
|
22
22
|
}
|
|
23
23
|
return value;
|
|
24
24
|
}
|
|
@@ -66,7 +66,7 @@ export class BanService {
|
|
|
66
66
|
$set: {
|
|
67
67
|
type: 'outpoint',
|
|
68
68
|
value,
|
|
69
|
-
domain: domain
|
|
69
|
+
domain: domain != null ? this.sanitize(domain) : undefined,
|
|
70
70
|
reason: reason ?? 'Manually banned',
|
|
71
71
|
bannedAt: new Date(),
|
|
72
72
|
bannedBy
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BanService.js","sourceRoot":"","sources":["../../../src/BanService.ts"],"names":[],"mappings":"AAoBA;;;;;;;GAOG;AACH,MAAM,OAAO,UAAU;IACJ,IAAI,CAA0B;IAE/C,YAAa,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C,CAAA;IAChH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACnD,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;YAC5C,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;SAC/C,CAAC,CAAA;QACF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,GAAG,YAAY,EAAE,CAAA;IAC3E,CAAC;CACF"}
|
|
@@ -7,7 +7,7 @@ import { MongoClient } from 'mongodb';
|
|
|
7
7
|
import makeUserInterface from './makeUserInterface.js';
|
|
8
8
|
import * as DiscoveryServices from '@bsv/overlay-discovery-services';
|
|
9
9
|
import chalk from 'chalk';
|
|
10
|
-
import util from 'util';
|
|
10
|
+
import util from 'node:util';
|
|
11
11
|
import { v4 as uuidv4 } from 'uuid';
|
|
12
12
|
import { JanitorService } from './JanitorService.js';
|
|
13
13
|
import { BanService } from './BanService.js';
|
|
@@ -259,7 +259,7 @@ export default class OverlayExpress {
|
|
|
259
259
|
}
|
|
260
260
|
/**
|
|
261
261
|
* Configure Knex (SQL) database connection.
|
|
262
|
-
* @param config - Knex configuration object, or MySQL connection string
|
|
262
|
+
* @param config - Knex configuration object, or a MySQL connection string loaded from configuration.
|
|
263
263
|
*/
|
|
264
264
|
async configureKnex(config) {
|
|
265
265
|
if (typeof config === 'string') {
|
|
@@ -362,126 +362,96 @@ export default class OverlayExpress {
|
|
|
362
362
|
async configureEngine(autoConfigureShipSlap = true) {
|
|
363
363
|
const knex = this.ensureKnex();
|
|
364
364
|
if (autoConfigureShipSlap) {
|
|
365
|
-
// Auto-configure SHIP and SLAP services
|
|
366
365
|
this.configureTopicManager('tm_ship', new DiscoveryServices.SHIPTopicManager());
|
|
367
366
|
this.configureTopicManager('tm_slap', new DiscoveryServices.SLAPTopicManager());
|
|
368
367
|
this.configureLookupServiceWithMongo('ls_ship', (db) => new DiscoveryServices.SHIPLookupService(new DiscoveryServices.SHIPStorage(db)));
|
|
369
368
|
this.configureLookupServiceWithMongo('ls_slap', (db) => new DiscoveryServices.SLAPLookupService(new DiscoveryServices.SLAPStorage(db)));
|
|
370
369
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
370
|
+
this.wrapBanAwareServices();
|
|
371
|
+
const syncConfig = this.buildSyncConfig();
|
|
372
|
+
const storage = new KnexStorage(knex);
|
|
373
|
+
this.migrationsToRun = [...KnexStorageMigrations.default, ...this.migrationsToRun];
|
|
374
|
+
const broadcaster = this.buildBroadcaster();
|
|
375
|
+
const advertiser = await this.buildAdvertiser();
|
|
376
|
+
this.engine = new Engine(this.managers, this.services, storage, this.engineConfig.chainTracker ?? this.chainTracker, `https://${this.advertisableFQDN}`, this.network === 'test'
|
|
377
|
+
? (this.engineConfig.shipTrackers ?? DEFAULT_TESTNET_SLAP_TRACKERS)
|
|
378
|
+
: this.engineConfig.shipTrackers, this.resolveSlapTrackers(), broadcaster ?? this.engineConfig.broadcaster, advertiser, syncConfig, this.engineConfig.logTime ?? false, this.engineConfig.logPrefix ?? '[OVERLAY_ENGINE] ', this.engineConfig.throwOnBroadcastFailure ?? false, this.engineConfig.overlayBroadcastFacilitator ?? new HTTPSOverlayBroadcastFacilitator(), this.logger, this.engineConfig.suppressDefaultSyncAdvertisements ?? true);
|
|
379
|
+
this.initServerWallet();
|
|
380
|
+
this.logger.log(chalk.green('Engine has been configured.'));
|
|
381
|
+
}
|
|
382
|
+
/** Wrap SHIP/SLAP with ban-aware filter if BanService is configured. */
|
|
383
|
+
wrapBanAwareServices() {
|
|
384
|
+
if (this.banService === undefined)
|
|
385
|
+
return;
|
|
386
|
+
for (const key of ['ls_ship', 'ls_slap']) {
|
|
387
|
+
if (this.services[key] !== undefined) {
|
|
388
|
+
const label = key === 'ls_ship' ? 'SHIP' : 'SLAP';
|
|
389
|
+
this.services[key] = new BanAwareLookupWrapper(this.services[key], this.banService, label, this.logger);
|
|
390
|
+
this.logger.log(chalk.blue(`${label} lookup service wrapped with ban-aware filter.`));
|
|
381
391
|
}
|
|
382
392
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
syncConfig[managerName] = false;
|
|
389
|
-
}
|
|
393
|
+
}
|
|
394
|
+
/** Build the sync config based on enableGASPSync and engineConfig. */
|
|
395
|
+
buildSyncConfig() {
|
|
396
|
+
if (this.enableGASPSync) {
|
|
397
|
+
return this.engineConfig.syncConfiguration ?? {};
|
|
390
398
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
syncConfig =
|
|
399
|
+
const syncConfig = {};
|
|
400
|
+
for (const name of Object.keys(this.managers)) {
|
|
401
|
+
syncConfig[name] = false;
|
|
394
402
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
403
|
+
return syncConfig;
|
|
404
|
+
}
|
|
405
|
+
/** Build the ARC broadcaster if an API key is configured. */
|
|
406
|
+
buildBroadcaster() {
|
|
407
|
+
if (typeof this.arcApiKey !== 'string')
|
|
408
|
+
return undefined;
|
|
409
|
+
const arcUrl = this.network === 'test' ? 'https://arc-test.taal.com' : 'https://arc.taal.com';
|
|
410
|
+
return new ARC(arcUrl, { apiKey: this.arcApiKey });
|
|
411
|
+
}
|
|
412
|
+
/** Resolve the SLAP trackers from config or network defaults. */
|
|
413
|
+
resolveSlapTrackers() {
|
|
414
|
+
if (Array.isArray(this.engineConfig.slapTrackers))
|
|
415
|
+
return this.engineConfig.slapTrackers;
|
|
416
|
+
return this.network === 'test' ? DEFAULT_TESTNET_SLAP_TRACKERS : DEFAULT_SLAP_TRACKERS;
|
|
417
|
+
}
|
|
418
|
+
/** Build the WalletAdvertiser (or use user-provided one). */
|
|
419
|
+
async buildAdvertiser() {
|
|
420
|
+
if (this.engineConfig.advertiser !== undefined)
|
|
421
|
+
return this.engineConfig.advertiser;
|
|
422
|
+
const storageBase = this.network === 'test'
|
|
423
|
+
? 'https://staging-storage.babbage.systems'
|
|
424
|
+
: 'https://storage.babbage.systems';
|
|
425
|
+
try {
|
|
426
|
+
return new DiscoveryServices.WalletAdvertiser(this.network, this.privateKey, storageBase, `https://${this.advertisableFQDN}`);
|
|
407
427
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
try {
|
|
412
|
-
advertiser = new DiscoveryServices.WalletAdvertiser(this.network, this.privateKey, this.network === 'test' // For now, we hard-code some storage servers. In the future, this needs to be configurable.
|
|
413
|
-
? 'https://staging-storage.babbage.systems'
|
|
414
|
-
: 'https://storage.babbage.systems',
|
|
415
|
-
// Until multiple protocols (like https+bsvauth+smf) are fully supported, HTTPS is the one to always use.
|
|
416
|
-
`https://${this.advertisableFQDN}`);
|
|
417
|
-
}
|
|
418
|
-
catch (e) {
|
|
419
|
-
this.logger.log(`Advertiser not initialized for FQDN ${this.advertisableFQDN} - SHIP and SLAP will be disabled.`);
|
|
420
|
-
}
|
|
428
|
+
catch (e) {
|
|
429
|
+
this.logger.log(`Advertiser not initialized for FQDN ${this.advertisableFQDN} - SHIP and SLAP will be disabled. Reason: ${e}`);
|
|
430
|
+
return undefined;
|
|
421
431
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
typeof this.engineConfig.chainTracker !== 'undefined'
|
|
426
|
-
? this.engineConfig.chainTracker
|
|
427
|
-
: this.chainTracker,
|
|
428
|
-
// hostingURL
|
|
429
|
-
`https://${this.advertisableFQDN}`,
|
|
430
|
-
// shipTrackers
|
|
431
|
-
this.network === 'test'
|
|
432
|
-
? (this.engineConfig.shipTrackers ?? DEFAULT_TESTNET_SLAP_TRACKERS)
|
|
433
|
-
: this.engineConfig.shipTrackers,
|
|
434
|
-
// slapTrackers
|
|
435
|
-
Array.isArray(this.engineConfig.slapTrackers)
|
|
436
|
-
? this.engineConfig.slapTrackers
|
|
437
|
-
: this.network === 'test'
|
|
438
|
-
? DEFAULT_TESTNET_SLAP_TRACKERS
|
|
439
|
-
: DEFAULT_SLAP_TRACKERS,
|
|
440
|
-
// broadcaster
|
|
441
|
-
broadcaster ?? this.engineConfig.broadcaster,
|
|
442
|
-
// advertiser
|
|
443
|
-
advertiser,
|
|
444
|
-
// syncConfiguration
|
|
445
|
-
syncConfig,
|
|
446
|
-
// logTime
|
|
447
|
-
this.engineConfig.logTime ?? false,
|
|
448
|
-
// logPrefix
|
|
449
|
-
this.engineConfig.logPrefix ?? '[OVERLAY_ENGINE] ',
|
|
450
|
-
// throwOnBroadcastFailure
|
|
451
|
-
this.engineConfig.throwOnBroadcastFailure ?? false,
|
|
452
|
-
// overlayBroadcastFacilitator
|
|
453
|
-
this.engineConfig.overlayBroadcastFacilitator ?? new HTTPSOverlayBroadcastFacilitator(),
|
|
454
|
-
// logger
|
|
455
|
-
this.logger,
|
|
456
|
-
// suppressDefaultSyncAdvertisements
|
|
457
|
-
this.engineConfig.suppressDefaultSyncAdvertisements ?? true);
|
|
458
|
-
// Create the server wallet for BSV mutual authentication.
|
|
459
|
-
// This uses the same private key as the WalletAdvertiser.
|
|
432
|
+
}
|
|
433
|
+
/** Initialize the server wallet for BSV mutual authentication. */
|
|
434
|
+
initServerWallet() {
|
|
460
435
|
try {
|
|
461
436
|
const keyDeriver = new KeyDeriver(new PrivateKey(this.privateKey, 'hex'));
|
|
462
437
|
const storageManager = new WalletStorageManager(keyDeriver.identityKey);
|
|
463
438
|
const signer = new WalletSigner(this.network, keyDeriver, storageManager);
|
|
464
439
|
const services = new Services(this.network);
|
|
465
|
-
|
|
466
|
-
this.
|
|
467
|
-
// Auto-set the admin identity key from the server's own key if not configured
|
|
468
|
-
if (typeof this.adminIdentityKey === 'undefined') {
|
|
469
|
-
this.adminIdentityKey = keyDeriver.identityKey;
|
|
470
|
-
}
|
|
440
|
+
this.serverWallet = new Wallet(signer, services);
|
|
441
|
+
this.adminIdentityKey ??= keyDeriver.identityKey;
|
|
471
442
|
this.logger.log(chalk.blue('Server wallet initialized for BSV mutual authentication.'));
|
|
472
443
|
}
|
|
473
444
|
catch (e) {
|
|
474
|
-
this.logger.log(chalk.yellow(
|
|
445
|
+
this.logger.log(chalk.yellow(`Server wallet could not be initialized. BSV auth will not be available. Reason: ${e}`));
|
|
475
446
|
}
|
|
476
|
-
this.logger.log(chalk.green('Engine has been configured.'));
|
|
477
447
|
}
|
|
478
448
|
/**
|
|
479
449
|
* Ensures that Knex is configured and returns it.
|
|
480
450
|
* @throws Error if Knex is not configured
|
|
481
451
|
*/
|
|
482
452
|
ensureKnex() {
|
|
483
|
-
if (
|
|
484
|
-
throw new
|
|
453
|
+
if (this.knex === undefined) {
|
|
454
|
+
throw new TypeError('You must configure your SQL database with the .configureKnex() method first!');
|
|
485
455
|
}
|
|
486
456
|
return this.knex;
|
|
487
457
|
}
|
|
@@ -490,8 +460,8 @@ export default class OverlayExpress {
|
|
|
490
460
|
* @throws Error if MongoDB is not configured
|
|
491
461
|
*/
|
|
492
462
|
ensureMongo() {
|
|
493
|
-
if (
|
|
494
|
-
throw new
|
|
463
|
+
if (this.mongoDb === undefined) {
|
|
464
|
+
throw new TypeError('You must configure your MongoDB connection with the .configureMongo() method first!');
|
|
495
465
|
}
|
|
496
466
|
return this.mongoDb;
|
|
497
467
|
}
|
|
@@ -500,8 +470,8 @@ export default class OverlayExpress {
|
|
|
500
470
|
* @throws Error if the Engine is not configured
|
|
501
471
|
*/
|
|
502
472
|
ensureEngine() {
|
|
503
|
-
if (
|
|
504
|
-
throw new
|
|
473
|
+
if (this.engine === undefined) {
|
|
474
|
+
throw new TypeError('You must configure your Overlay Services engine with the .configureEngine() method first!');
|
|
505
475
|
}
|
|
506
476
|
return this.engine;
|
|
507
477
|
}
|
|
@@ -519,6 +489,70 @@ export default class OverlayExpress {
|
|
|
519
489
|
autoBanOnRemoval: this.janitorConfig.autoBanOnRemoval
|
|
520
490
|
});
|
|
521
491
|
}
|
|
492
|
+
/** Ban a domain and remove all its SHIP/SLAP records from MongoDB. */
|
|
493
|
+
async handleBanDomain(res, value, reason) {
|
|
494
|
+
await this.banService.banDomain(value, reason);
|
|
495
|
+
const db = this.ensureMongo();
|
|
496
|
+
const [shipDeleted, slapDeleted] = await Promise.all([
|
|
497
|
+
db.collection('shipRecords').deleteMany({ domain: value }),
|
|
498
|
+
db.collection('slapRecords').deleteMany({ domain: value })
|
|
499
|
+
]);
|
|
500
|
+
return res.status(200).json({
|
|
501
|
+
status: 'success',
|
|
502
|
+
message: `Domain "${value}" banned. Removed ${shipDeleted.deletedCount} SHIP and ${slapDeleted.deletedCount} SLAP records.`
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
/** Parse outpoint string, ban it, and evict it from all lookup services. */
|
|
506
|
+
async handleBanOutpoint(res, engine, value, reason) {
|
|
507
|
+
const dotIndex = value.lastIndexOf('.');
|
|
508
|
+
if (dotIndex === -1) {
|
|
509
|
+
return res.status(400).json({ status: 'error', message: 'Outpoint format must be "txid.outputIndex"' });
|
|
510
|
+
}
|
|
511
|
+
const txid = value.substring(0, dotIndex);
|
|
512
|
+
const outputIndex = Number.parseInt(value.substring(dotIndex + 1));
|
|
513
|
+
if (Number.isNaN(outputIndex)) {
|
|
514
|
+
return res.status(400).json({ status: 'error', message: 'Invalid outputIndex in outpoint' });
|
|
515
|
+
}
|
|
516
|
+
await this.banService.banOutpoint(txid, outputIndex, reason);
|
|
517
|
+
await this.evictFromServices(engine, txid, outputIndex);
|
|
518
|
+
return res.status(200).json({
|
|
519
|
+
status: 'success',
|
|
520
|
+
message: `Outpoint "${value}" banned and evicted from lookup services.`
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
/** Evict an output from a specific service or all services (silent per-service errors). */
|
|
524
|
+
async evictFromServices(engine, txid, outputIndex, service) {
|
|
525
|
+
if (typeof service === 'string') {
|
|
526
|
+
const svc = engine.lookupServices[service];
|
|
527
|
+
if (svc !== undefined)
|
|
528
|
+
await svc.outputEvicted(txid, outputIndex);
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
for (const svc of Object.values(engine.lookupServices)) {
|
|
532
|
+
try {
|
|
533
|
+
await svc.outputEvicted(txid, outputIndex);
|
|
534
|
+
}
|
|
535
|
+
catch { /* best-effort */ }
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
/** Look up the domain of an outpoint from SHIP or SLAP records. */
|
|
539
|
+
async lookupDomainForOutpoint(txid, outputIndex) {
|
|
540
|
+
const db = this.ensureMongo();
|
|
541
|
+
const [shipRecord, slapRecord] = await Promise.all([
|
|
542
|
+
db.collection('shipRecords').findOne({ txid, outputIndex }),
|
|
543
|
+
db.collection('slapRecords').findOne({ txid, outputIndex })
|
|
544
|
+
]);
|
|
545
|
+
return (shipRecord?.domain ?? slapRecord?.domain);
|
|
546
|
+
}
|
|
547
|
+
/** Ban a domain and delete all SHIP/SLAP records for it. */
|
|
548
|
+
async banDomainAndRemoveRecords(domain, reason) {
|
|
549
|
+
await this.banService.banDomain(domain, reason);
|
|
550
|
+
const db = this.ensureMongo();
|
|
551
|
+
await Promise.all([
|
|
552
|
+
db.collection('shipRecords').deleteMany({ domain }),
|
|
553
|
+
db.collection('slapRecords').deleteMany({ domain })
|
|
554
|
+
]);
|
|
555
|
+
}
|
|
522
556
|
async runHealthCheck(definition) {
|
|
523
557
|
const startedAt = Date.now();
|
|
524
558
|
try {
|
|
@@ -567,8 +601,8 @@ export default class OverlayExpress {
|
|
|
567
601
|
scope: 'ready',
|
|
568
602
|
critical: true,
|
|
569
603
|
handler: async () => {
|
|
570
|
-
if (
|
|
571
|
-
throw new
|
|
604
|
+
if (this.engine === undefined) {
|
|
605
|
+
throw new TypeError('Overlay engine is not configured');
|
|
572
606
|
}
|
|
573
607
|
return {
|
|
574
608
|
status: 'ok',
|
|
@@ -584,8 +618,8 @@ export default class OverlayExpress {
|
|
|
584
618
|
scope: 'ready',
|
|
585
619
|
critical: true,
|
|
586
620
|
handler: async () => {
|
|
587
|
-
if (
|
|
588
|
-
throw new
|
|
621
|
+
if (this.knex === undefined) {
|
|
622
|
+
throw new TypeError('Knex is not configured');
|
|
589
623
|
}
|
|
590
624
|
await this.knex.raw('select 1 as ok');
|
|
591
625
|
return {
|
|
@@ -601,8 +635,8 @@ export default class OverlayExpress {
|
|
|
601
635
|
scope: 'ready',
|
|
602
636
|
critical: true,
|
|
603
637
|
handler: async () => {
|
|
604
|
-
if (
|
|
605
|
-
throw new
|
|
638
|
+
if (this.mongoDb === undefined) {
|
|
639
|
+
throw new TypeError('MongoDB is not configured');
|
|
606
640
|
}
|
|
607
641
|
await this.mongoDb.command({ ping: 1 });
|
|
608
642
|
return {
|
|
@@ -653,7 +687,7 @@ export default class OverlayExpress {
|
|
|
653
687
|
port: this.port,
|
|
654
688
|
network: this.network,
|
|
655
689
|
startedAt: this.startTime?.toISOString(),
|
|
656
|
-
uptimeMs:
|
|
690
|
+
uptimeMs: this.startTime === undefined ? 0 : Date.now() - this.startTime.getTime(),
|
|
657
691
|
topicManagerCount: Object.keys(this.managers).length,
|
|
658
692
|
lookupServiceCount: Object.keys(this.services).length
|
|
659
693
|
},
|
|
@@ -898,7 +932,7 @@ export default class OverlayExpress {
|
|
|
898
932
|
const topicsHeader = req.headers['x-topics'];
|
|
899
933
|
const includesOffChain = req.headers['x-includes-off-chain-values'] === 'true';
|
|
900
934
|
if (typeof topicsHeader !== 'string') {
|
|
901
|
-
throw new
|
|
935
|
+
throw new TypeError('Missing x-topics header');
|
|
902
936
|
}
|
|
903
937
|
const topics = JSON.parse(topicsHeader);
|
|
904
938
|
let offChainValues;
|
|
@@ -1158,7 +1192,7 @@ export default class OverlayExpress {
|
|
|
1158
1192
|
data: {
|
|
1159
1193
|
nodeName: this.name,
|
|
1160
1194
|
network: this.network,
|
|
1161
|
-
uptime: this.startTime
|
|
1195
|
+
uptime: this.startTime != null ? Date.now() - this.startTime.getTime() : 0,
|
|
1162
1196
|
startedAt: this.startTime?.toISOString(),
|
|
1163
1197
|
shipRecordCount: shipCount,
|
|
1164
1198
|
slapRecordCount: slapCount,
|
|
@@ -1191,9 +1225,9 @@ export default class OverlayExpress {
|
|
|
1191
1225
|
const db = this.ensureMongo();
|
|
1192
1226
|
const collection = db.collection('shipRecords');
|
|
1193
1227
|
const search = typeof req.query.search === 'string' ? req.query.search : undefined;
|
|
1194
|
-
const rawPage = parseInt(req.query.page, 10);
|
|
1228
|
+
const rawPage = Number.parseInt(req.query.page, 10);
|
|
1195
1229
|
const page = Math.max(1, Number.isNaN(rawPage) ? 1 : rawPage);
|
|
1196
|
-
const rawLimit = parseInt(req.query.limit, 10);
|
|
1230
|
+
const rawLimit = Number.parseInt(req.query.limit, 10);
|
|
1197
1231
|
const limit = Math.min(200, Math.max(1, Number.isNaN(rawLimit) ? 50 : rawLimit));
|
|
1198
1232
|
const skip = (page - 1) * limit;
|
|
1199
1233
|
const query = {};
|
|
@@ -1234,9 +1268,9 @@ export default class OverlayExpress {
|
|
|
1234
1268
|
const db = this.ensureMongo();
|
|
1235
1269
|
const collection = db.collection('slapRecords');
|
|
1236
1270
|
const search = typeof req.query.search === 'string' ? req.query.search : undefined;
|
|
1237
|
-
const rawPage = parseInt(req.query.page, 10);
|
|
1271
|
+
const rawPage = Number.parseInt(req.query.page, 10);
|
|
1238
1272
|
const page = Math.max(1, Number.isNaN(rawPage) ? 1 : rawPage);
|
|
1239
|
-
const rawLimit = parseInt(req.query.limit, 10);
|
|
1273
|
+
const rawLimit = Number.parseInt(req.query.limit, 10);
|
|
1240
1274
|
const limit = Math.min(200, Math.max(1, Number.isNaN(rawLimit) ? 50 : rawLimit));
|
|
1241
1275
|
const skip = (page - 1) * limit;
|
|
1242
1276
|
const query = {};
|
|
@@ -1310,45 +1344,9 @@ export default class OverlayExpress {
|
|
|
1310
1344
|
return res.status(400).json({ status: 'error', message: 'value is required' });
|
|
1311
1345
|
}
|
|
1312
1346
|
if (type === 'domain') {
|
|
1313
|
-
await this.
|
|
1314
|
-
// Also remove any existing records for this domain from SHIP and SLAP
|
|
1315
|
-
const db = this.ensureMongo();
|
|
1316
|
-
const [shipDeleted, slapDeleted] = await Promise.all([
|
|
1317
|
-
db.collection('shipRecords').deleteMany({ domain: value }),
|
|
1318
|
-
db.collection('slapRecords').deleteMany({ domain: value })
|
|
1319
|
-
]);
|
|
1320
|
-
return res.status(200).json({
|
|
1321
|
-
status: 'success',
|
|
1322
|
-
message: `Domain "${value}" banned. Removed ${shipDeleted.deletedCount} SHIP and ${slapDeleted.deletedCount} SLAP records.`
|
|
1323
|
-
});
|
|
1324
|
-
}
|
|
1325
|
-
else {
|
|
1326
|
-
// Parse outpoint: "txid.outputIndex"
|
|
1327
|
-
const dotIndex = value.lastIndexOf('.');
|
|
1328
|
-
if (dotIndex === -1) {
|
|
1329
|
-
return res.status(400).json({ status: 'error', message: 'Outpoint format must be "txid.outputIndex"' });
|
|
1330
|
-
}
|
|
1331
|
-
const txid = value.substring(0, dotIndex);
|
|
1332
|
-
const outputIndex = parseInt(value.substring(dotIndex + 1));
|
|
1333
|
-
if (isNaN(outputIndex)) {
|
|
1334
|
-
return res.status(400).json({ status: 'error', message: 'Invalid outputIndex in outpoint' });
|
|
1335
|
-
}
|
|
1336
|
-
await this.banService.banOutpoint(txid, outputIndex, reason);
|
|
1337
|
-
// Also evict from lookup services
|
|
1338
|
-
const services = Object.values(engine.lookupServices);
|
|
1339
|
-
for (const service of services) {
|
|
1340
|
-
try {
|
|
1341
|
-
await service.outputEvicted(txid, outputIndex);
|
|
1342
|
-
}
|
|
1343
|
-
catch {
|
|
1344
|
-
continue;
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
return res.status(200).json({
|
|
1348
|
-
status: 'success',
|
|
1349
|
-
message: `Outpoint "${value}" banned and evicted from lookup services.`
|
|
1350
|
-
});
|
|
1347
|
+
return await this.handleBanDomain(res, value, reason);
|
|
1351
1348
|
}
|
|
1349
|
+
return await this.handleBanOutpoint(res, engine, value, reason);
|
|
1352
1350
|
}
|
|
1353
1351
|
catch (error) {
|
|
1354
1352
|
return res.status(400).json({
|
|
@@ -1426,49 +1424,25 @@ export default class OverlayExpress {
|
|
|
1426
1424
|
if (typeof txid !== 'string' || typeof outputIndex !== 'number') {
|
|
1427
1425
|
return res.status(400).json({ status: 'error', message: 'txid (string) and outputIndex (number) are required' });
|
|
1428
1426
|
}
|
|
1429
|
-
//
|
|
1427
|
+
// Look up domain before eviction if needed for banning
|
|
1430
1428
|
let removedDomain;
|
|
1431
1429
|
if (shouldBanDomain === true || ban === true) {
|
|
1432
|
-
|
|
1433
|
-
const shipRecord = await db.collection('shipRecords').findOne({ txid, outputIndex });
|
|
1434
|
-
const slapRecord = await db.collection('slapRecords').findOne({ txid, outputIndex });
|
|
1435
|
-
removedDomain = (shipRecord?.domain ?? slapRecord?.domain);
|
|
1436
|
-
}
|
|
1437
|
-
// Evict from specified service or all services
|
|
1438
|
-
if (typeof service === 'string') {
|
|
1439
|
-
const svc = engine.lookupServices[service];
|
|
1440
|
-
if (svc !== undefined) {
|
|
1441
|
-
await svc.outputEvicted(txid, outputIndex);
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
else {
|
|
1445
|
-
const services = Object.values(engine.lookupServices);
|
|
1446
|
-
for (const svc of services) {
|
|
1447
|
-
try {
|
|
1448
|
-
await svc.outputEvicted(txid, outputIndex);
|
|
1449
|
-
}
|
|
1450
|
-
catch {
|
|
1451
|
-
continue;
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1430
|
+
removedDomain = await this.lookupDomainForOutpoint(txid, outputIndex);
|
|
1454
1431
|
}
|
|
1455
|
-
|
|
1432
|
+
await this.evictFromServices(engine, txid, outputIndex, service);
|
|
1456
1433
|
if (ban === true && this.banService !== undefined) {
|
|
1457
1434
|
await this.banService.banOutpoint(txid, outputIndex, 'Manually removed by admin', removedDomain);
|
|
1458
1435
|
}
|
|
1459
|
-
// Ban the domain if requested
|
|
1460
1436
|
if (shouldBanDomain === true && typeof removedDomain === 'string' && this.banService !== undefined) {
|
|
1461
|
-
await this.
|
|
1462
|
-
// Remove all records for this domain
|
|
1463
|
-
const banDb = this.ensureMongo();
|
|
1464
|
-
await Promise.all([
|
|
1465
|
-
banDb.collection('shipRecords').deleteMany({ domain: removedDomain }),
|
|
1466
|
-
banDb.collection('slapRecords').deleteMany({ domain: removedDomain })
|
|
1467
|
-
]);
|
|
1437
|
+
await this.banDomainAndRemoveRecords(removedDomain, 'Domain banned by admin via token removal');
|
|
1468
1438
|
}
|
|
1439
|
+
const banMsg = ban === true ? ' Outpoint banned.' : '';
|
|
1440
|
+
const domainMsg = shouldBanDomain === true && typeof removedDomain === 'string'
|
|
1441
|
+
? ` Domain "${removedDomain}" banned.`
|
|
1442
|
+
: '';
|
|
1469
1443
|
return res.status(200).json({
|
|
1470
1444
|
status: 'success',
|
|
1471
|
-
message: `Token ${txid}.${outputIndex} removed.${
|
|
1445
|
+
message: `Token ${txid}.${outputIndex} removed.${banMsg}${domainMsg}`
|
|
1472
1446
|
});
|
|
1473
1447
|
}
|
|
1474
1448
|
catch (error) {
|
|
@@ -1542,9 +1516,9 @@ export default class OverlayExpress {
|
|
|
1542
1516
|
}
|
|
1543
1517
|
else {
|
|
1544
1518
|
const services = Object.values(engine.lookupServices);
|
|
1545
|
-
for (
|
|
1519
|
+
for (const service of services) {
|
|
1546
1520
|
try {
|
|
1547
|
-
await
|
|
1521
|
+
await service.outputEvicted(req.body.txid, req.body.outputIndex);
|
|
1548
1522
|
}
|
|
1549
1523
|
catch {
|
|
1550
1524
|
continue;
|