Skip to content
Snippets Groups Projects
Commit 12a83175 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[enh] Refactoring: type FileDAL.wotb

parent 2ddd4c6e
Branches
Tags
No related merge requests found
......@@ -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
......
......@@ -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();
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment