diff --git a/app/lib/dal/fileDAL.ts b/app/lib/dal/fileDAL.ts index 9d707693b39c94ac9cb33e8666cc7ef42a87376f..406711aa3ae2444ec014a01d68659dc797d2efb2 100644 --- a/app/lib/dal/fileDAL.ts +++ b/app/lib/dal/fileDAL.ts @@ -19,7 +19,7 @@ import {BlockDTO} from "../dto/BlockDTO" import {DBHead} from "../db/DBHead" import {DBIdentity, IdentityDAL} from "./sqliteDAL/IdentityDAL" import {CindexEntry, FullMindexEntry, IindexEntry, IndexEntry, SindexEntry} from "../indexer" -import {DBPeer} from "./sqliteDAL/PeerDAL" +import {DBPeer, PeerDAL} from "./sqliteDAL/PeerDAL" import {TransactionDTO} from "../dto/TransactionDTO" import {CertDAL, DBCert} from "./sqliteDAL/CertDAL" import {DBWallet, WalletDAL} from "./sqliteDAL/WalletDAL" @@ -65,7 +65,7 @@ export class FileDAL { powDAL:PowDAL confDAL:any metaDAL:MetaDAL - peerDAL:any + peerDAL:PeerDAL blockDAL:any txsDAL:TxsDAL statDAL:StatDAL @@ -161,7 +161,7 @@ export class FileDAL { async getPeer(pubkey:string) { try { - return this.peerDAL.getPeer(pubkey) + return await this.peerDAL.getPeer(pubkey) } catch (err) { throw Error('Unknown peer ' + pubkey); } @@ -803,7 +803,7 @@ export class FileDAL { return _.chain(peers).filter((p:DBPeer) => p.status == 'UP').filter((p:DBPeer) => p.pubkey !== pub).value(); } - async findPeers(pubkey:string) { + async findPeers(pubkey:string): Promise<DBPeer[]> { try { const peer = await this.getPeer(pubkey); return [peer]; diff --git a/app/service/PeeringService.ts b/app/service/PeeringService.ts index e72f6a172fb826d12f382eede5e9351b1a84f7a7..ec90021f590af93888e9cb1d4e55652c5b3021f1 100644 --- a/app/service/PeeringService.ts +++ b/app/service/PeeringService.ts @@ -186,7 +186,7 @@ export class PeeringService { return this.server.writePeer(pretendedNewer) } - async generateSelfPeer(theConf:ConfDTO, signalTimeInterval = 0) { + async generateSelfPeer(theConf:ConfDTO, signalTimeInterval = 0): Promise<DBPeer|null> { const current = await this.server.dal.getCurrentBlockOrNull(); const currency = theConf.currency || constants.DEFAULT_CURRENCY_NAME; const peers = await this.dal.findPeers(this.selfPubkey); @@ -213,7 +213,7 @@ export class PeeringService { logger.error('It seems there is an issue with your configuration.'); logger.error('Please restart your node with:'); logger.error('$ duniter restart'); - return new Promise(() => null); + return null } const endpointsToDeclare = localEndpoints.concat(toConserve).concat(this.conf.endpoints || []) if (currentSelfPeer && endpointsToDeclare.length === 0 && currentSelfPeer.endpoints.length === 0) { diff --git a/server.ts b/server.ts index 026ddf671f33b9ca98489bb4005e2257c2aad78b..df2dddd5de05c7daa20ec56cbd3281f08e4a0d23 100644 --- a/server.ts +++ b/server.ts @@ -37,7 +37,8 @@ import {PeerDTO} from "./app/lib/dto/PeerDTO" import {OtherConstants} from "./app/lib/other_constants" import {WS2PCluster} from "./app/modules/ws2p/lib/WS2PCluster" import {DBBlock} from "./app/lib/db/DBBlock" -import { ProxiesConf } from './app/lib/proxy'; +import {ProxiesConf} from './app/lib/proxy'; +import {DBPeer} from "./app/lib/dal/sqliteDAL/PeerDAL" export interface HookableServer { generatorGetJoinData: (...args:any[]) => Promise<any> @@ -341,7 +342,7 @@ export class Server extends stream.Duplex implements HookableServer { await this.BlockchainService.forkResolution() } - recomputeSelfPeer() { + recomputeSelfPeer(): Promise<DBPeer | null> { return this.PeeringService.generateSelfPeer(this.conf) } diff --git a/test/integration/tools/toolbox.ts b/test/integration/tools/toolbox.ts index 8b49bcab5dae9d958b2140e3ba7a2a148bdb7c5f..40ccadd8836d052b1462d873aece31e780b15fc7 100644 --- a/test/integration/tools/toolbox.ts +++ b/test/integration/tools/toolbox.ts @@ -39,6 +39,7 @@ import {TestUser} from "./TestUser" import {RouterDependency} from "../../../app/modules/router" import {ProverDependency} from "../../../app/modules/prover/index" import {WS2PClient} from "../../../app/modules/ws2p/lib/WS2PClient" +import {DBPeer} from "../../../app/lib/dal/sqliteDAL/PeerDAL" const assert = require('assert'); const _ = require('underscore'); @@ -387,7 +388,7 @@ export class TestingServer { return this.server.on(event, f) } - recomputeSelfPeer() { + recomputeSelfPeer(): Promise<DBPeer | null> { return this.server.recomputeSelfPeer() }