diff --git a/app/lib/dal/fileDAL.ts b/app/lib/dal/fileDAL.ts index 0caef83d78987d33b52c2c46da988c2313407765..94d06e0cf21fc49ec9bac53cdb5c161e1c51c02f 100644 --- a/app/lib/dal/fileDAL.ts +++ b/app/lib/dal/fileDAL.ts @@ -33,6 +33,7 @@ import {Initiable} from "./sqliteDAL/Initiable" import {MetaDAL} from "./sqliteDAL/MetaDAL" import {BIndexDAL} from "./sqliteDAL/index/BIndexDAL" import {MIndexDAL} from "./sqliteDAL/index/MIndexDAL" +import {CIndexDAL} from "./sqliteDAL/index/CIndexDAL" const fs = require('fs') const path = require('path') @@ -72,7 +73,7 @@ export class FileDAL { mindexDAL:MIndexDAL iindexDAL:any sindexDAL:any - cindexDAL:any + cindexDAL:CIndexDAL newDals:{ [k:string]: Initiable } loadConfHook: (conf:ConfDTO) => Promise<void> diff --git a/app/service/BlockchainService.ts b/app/service/BlockchainService.ts index dfdc7bee1b38d1758ad73bdcd5aa6c582611fabb..b013a3f2db3b492ffff4bcb6afa1e8fbb1ce80f7 100644 --- a/app/service/BlockchainService.ts +++ b/app/service/BlockchainService.ts @@ -46,6 +46,15 @@ export interface IdentityForRequirements { revoked:boolean revoked_on:number } + +export interface ValidCert { + from:string + to:string + sig:string + timestamp:number + expiresIn:number +} + export class BlockchainService extends FIFOService { mainContext:BlockchainContext @@ -288,7 +297,7 @@ export class BlockchainService extends FIFOService { let wasMember = false; let expiresMS = 0; let expiresPending = 0; - let certs = []; + let certs:ValidCert[] = []; let certsPending = []; let mssPending = []; try { @@ -315,7 +324,7 @@ export class BlockchainService extends FIFOService { const newCerts = await this.server.generatorComputeNewCerts(nextBlockNumber, [join.identity.pubkey], joinData, updates); const newLinks = await this.server.generatorNewCertsToLinks(newCerts, updates); const currentTime = current ? current.medianTime : 0; - certs = await this.getValidCerts(pubkey, newCerts); + certs = await this.getValidCerts(pubkey, newCerts, currentTime); if (computeDistance) { outdistanced = await GLOBAL_RULES_HELPERS.isOver3Hops(pubkey, newLinks, someNewcomers, current, this.conf, this.dal); } @@ -348,10 +357,6 @@ export class BlockchainService extends FIFOService { } wasMember = idty.wasMember; isSentry = idty.member && (await this.dal.isSentry(idty.pubkey, this.conf)); - // Expiration of certifications - for (const cert of certs) { - cert.expiresIn = Math.max(0, cert.timestamp + this.conf.sigValidity - currentTime); - } } catch (e) { // We throw whatever isn't "Too old identity" error if (!(e && e.uerr && e.uerr.ucode == constants.ERRORS.TOO_OLD_IDENTITY.uerr.ucode)) { @@ -382,9 +387,16 @@ export class BlockchainService extends FIFOService { }; } - async getValidCerts(newcomer:string, newCerts:any) { + async getValidCerts(newcomer:string, newCerts:any, currentTime:number): Promise<ValidCert[]> { const links = await this.dal.getValidLinksTo(newcomer); - const certsFromLinks = links.map((lnk:any) => { return { from: lnk.issuer, to: lnk.receiver, timestamp: lnk.expires_on - this.conf.sigValidity }; }); + const certsFromLinks = links.map((lnk:any) => { return { + from: lnk.issuer, + to: lnk.receiver, + sig: lnk.sig, + timestamp: lnk.expires_on - this.conf.sigValidity, + expiresIn: 0 + } + }) const certsFromCerts = []; const certs = newCerts[newcomer] || []; for (const cert of certs) { @@ -393,10 +405,14 @@ export class BlockchainService extends FIFOService { from: cert.from, to: cert.to, sig: cert.sig, - timestamp: block.medianTime + timestamp: block.medianTime, + expiresIn: 0 }); } - return certsFromLinks.concat(certsFromCerts); + return certsFromLinks.concat(certsFromCerts).map(c => { + c.expiresIn = Math.max(0, c.timestamp + this.conf.sigValidity - currentTime) + return c + }) } isMember() { diff --git a/app/service/IdentityService.ts b/app/service/IdentityService.ts index 3458d95e0eb80865b2fac917f36a2d1cd73390e8..9bccc12bc93793063c77c89d852e3419eedda733 100644 --- a/app/service/IdentityService.ts +++ b/app/service/IdentityService.ts @@ -14,7 +14,7 @@ import {GlobalFifoPromise} from "./GlobalFifoPromise" import {FileDAL} from "../lib/dal/fileDAL" import {ConfDTO} from "../lib/dto/ConfDTO" -import {DBIdentity} from "../lib/dal/sqliteDAL/IdentityDAL" +import {DBIdentity, ExistingDBIdentity} from "../lib/dal/sqliteDAL/IdentityDAL" import {GLOBAL_RULES_FUNCTIONS, GLOBAL_RULES_HELPERS} from "../lib/rules/global_rules" import {BlockDTO} from "../lib/dto/BlockDTO" import {RevocationDTO} from "../lib/dto/RevocationDTO" @@ -50,7 +50,7 @@ export class IdentityService extends FIFOService { return this.dal.searchJustIdentities(search) } - async findMember(search:string) { + async findMember(search:string): Promise<{ idty: ExistingDBIdentity; memberships: { blockstamp: string; membership: string; number: number; fpr: string; written_number: number | null }[] }> { let idty = null; if (search.match(constants.PUBLIC_KEY)) { idty = await this.dal.getWrittenIdtyByPubkey(search);