From ce52856184f1f665c55d4c074e85383bb895340f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= <cem.moreau@gmail.com> Date: Mon, 9 Apr 2018 08:52:39 +0200 Subject: [PATCH] [enh] Refactoring: type FileDAL.peerDAL --- app/lib/dal/fileDAL.ts | 8 ++++---- app/service/PeeringService.ts | 4 ++-- server.ts | 5 +++-- test/integration/tools/toolbox.ts | 3 ++- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/lib/dal/fileDAL.ts b/app/lib/dal/fileDAL.ts index 9d707693b..406711aa3 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 e72f6a172..ec90021f5 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 026ddf671..df2dddd5d 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 8b49bcab5..40ccadd88 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() } -- GitLab