diff --git a/app/lib/dal/fileDAL.ts b/app/lib/dal/fileDAL.ts index 539da781e70915b24c2033be170965ba79296987..557e0d422f021bf6cde21bded77d789c833137c1 100644 --- a/app/lib/dal/fileDAL.ts +++ b/app/lib/dal/fileDAL.ts @@ -40,6 +40,7 @@ import {DataErrors} from "../common-libs/errors" import {BasicRevocableIdentity, IdentityDTO} from "../dto/IdentityDTO" import {BlockDAL} from "./sqliteDAL/BlockDAL" import {FileSystem} from "../system/directory" +import {WoTBInstance} from "../wot" const fs = require('fs') const path = require('path') @@ -53,14 +54,14 @@ export interface FileDALParams { home:string fs:FileSystem dbf:() => SQLiteDriver - wotb:any + wotb:WoTBInstance } export class FileDAL { rootPath:string sqliteDriver:SQLiteDriver - wotb:any + wotb:WoTBInstance profile:string powDAL:PowDAL diff --git a/app/lib/system/directory.ts b/app/lib/system/directory.ts index 8f7a89f28f85a799441da4e11b05bb918bd74d53..8e1dc9af37ea427b92ea1b67c5705402740e44bc 100644 --- a/app/lib/system/directory.ts +++ b/app/lib/system/directory.ts @@ -13,7 +13,7 @@ import {SQLiteDriver} from "../dal/drivers/SQLiteDriver" import {CFSCore} from "../dal/fileDALs/CFSCore" -import {WoTBObject} from "../wot" +import {WoTBInstance, WoTBObject} from "../wot" import {FileDALParams} from "../dal/fileDAL" const opts = require('optimist').argv; @@ -109,7 +109,7 @@ export const Directory = { const params = await Directory.getHomeFS(isMemory, theHome) const home = params.home; let dbf: () => SQLiteDriver - let wotb: any + let wotb: WoTBInstance if (isMemory) { dbf = () => new SQLiteDriver(':memory:'); wotb = WoTBObject.memoryInstance(); diff --git a/app/lib/wot.ts b/app/lib/wot.ts index b535ca68e81e533af1f52581e946e27825d92a3f..a3a68b2dd8642ef21fa7e6612d33a2ad52875de2 100644 --- a/app/lib/wot.ts +++ b/app/lib/wot.ts @@ -13,6 +13,169 @@ const wotb = require('wotb'); +export interface WoTBInstance { + + readonly instanceID:number + readonly filePath:string + + /** + * Gets this instance ID. + * @returns {number} The instance technical ID. + */ + getId(): number + + /** + * Makes a memory copy of the WoT instance, and returns this new instance. + * @returns {WoTBInstance} The new memory instance. + */ + memCopy(): WoTBInstance + + /** + * Remove the WoT from the computer's memory. + */ + clear(): void + + /** + * Returns a dump of the WoT as a string. + * @returns {string} The dump. + */ + dumpWoT(): string + + /** + * Makes a dump of the WoT on standard output. + */ + showGraph(): void + + /** + * Removes any node and certification from the WoT. + */ + resetWoT(): void + + /** + * Gets the total number of nodes in the WoT, enabled or not. + * @returns {number} The total of nodes ever added to the WoT. + */ + getWoTSize(): number + + /** + * Add a node and returns its wotb_id. + * @returns {number} The new node identifier. + */ + addNode(): number + + /** + * Remove the lastly added node from the WoT, as well as the certifications it received. + */ + removeNode(): void + + /** + * Sets the maximum number of certifications a node can emit. + * @param {number} max The maximum number of emitted certifications. + */ + setMaxCert(max:number): void + + /** + * Gets the maximum number of certifications a node can emit in the WoT. + * @returns {number} The maximum's value. + */ + getMaxCert(): number + + /** + * Tells wether a node is enabled or not (= member or not). + * @param node Node's ID. + * @returns {boolean} True if enabled, false otherwise. + */ + isEnabled(node:number): boolean + + /** + * Enables or disables a node. + * @param enabled True to enable, False to disable. + * @param node The node to change. + */ + setEnabled(enabled:boolean, node:number): void + + /** + * Tells wether a link exists from a member to another. + * @param from The emitting node. + * @param to The receiving node. + * @returns {boolean} + */ + existsLink(from:number, to:number): boolean + + /** + * Adds a link from a node to another. + * @param from The emitting node. + * @param to The receiving node. + * @returns {boolean} True if the link was added, false otherwise (for example if it from exceeded the maximum quota). + */ + addLink(from:number, to:number): boolean + + /** + * Removes a link from a node to another. Returns the new number of links issued to the destination node. + * @param from Issuer. + * @param to Receiver. + * @returns {number} The new number of links reaching Receiver. + */ + removeLink(from:number, to:number): number + + /** + * Tells wether a node is outdistanced from the WoT. + * @param {number} node The node we want to test. + * @param {number} d_min The minimum number of both issued and received certifications to be considered a sentry. + * @param {number} k_max The maximum distance from the sentries to the node. + * @param {number} x_percent The percentage of sentries to reach to not be considered outdistanced. + * @returns {boolean} True is the node is outdistanced, false otherwise. + */ + isOutdistanced(node:number, d_min:number, k_max:number, x_percent:number): boolean + + /** + * Gives details about the distance of a node from the WoT. + * @param {number} node The node we want to test. + * @param {number} d_min The minimum number of both issued and received certifications to be considered a sentry. + * @param {number} k_max The maximum distance from the sentries to the node. + * @param {number} x_percent The percentage of sentries to reach to not be considered outdistanced. + * @returns {{nbSuccess: number; nbSentries: number; nbReached: number; isOutdistanced: boolean}} The number of reached sentries, the number of sentries, the number of reached members, the distance test. + */ + detailedDistance(node:number, d_min:number, k_max:number, x_percent:number): { + nbSuccess: number + nbSentries: number + nbReached: number + isOutdistanced: boolean + } + + /** + * Returns the sentries of the WoT. + * @param {number} d_min The minimum number of both issued and received certifications to be considered a sentry. + * @returns {number} An array of node ID (= array of integers). + */ + getSentries(d_min:number): number[] + + /** + * Returns the non-sentires of the WoT. + * @param {number} d_min The minimum number of both issued and received certifications to be considered a sentry. + * @returns {number} An array of node ID (= array of integers). + */ + getNonSentries(d_min:number): number[] + + /** + * Returns the non-members of the WoT. + * @returns {number} An array of node ID (= array of integers). + */ + getDisabled(): number[] + + /** + * Returns the list of existing paths from a node to another, using a maximum of k_max steps. + * @param {number} from The departure node. + * @param {number} to The arrival node. + * @param {number} k_max The maximum number of steps allowed for reaching the arrival node from departure node. + * @returns {number[][]} A list of paths. Example of paths from ID 5 to ID 189 using k_max 4 + * [0] = [5, 822, 333, 12, 189] + * [1] = [5, 29, 189] + * [2] = [5, 189] + */ + getPaths(from:number, to:number, k_max:number): number[][] +} + export interface WoTBInterface { fileInstance: (filepath:string) => any memoryInstance: () => any