Skip to content
Snippets Groups Projects
Commit 03193931 authored by Éloïs's avatar Éloïs
Browse files

Merge branch '2-add-basics-methods-with-neon' into 'master'

Resolve "add basics methods with Neon"

Closes #2

See merge request !1
parents 8f573950 c0d98f1c
Branches
Tags
1 merge request!1Resolve "add basics methods with Neon"
Pipeline #
native/target
native/index.node
native/artifacts.json
**/*~
**/node_modules
**/.DS_Store
stages:
- build_and_tests
.nvm_env: &nvm_env
tags:
- redshift
image: duniter/duniter-js-rs-ci:v0.0.3
before_script:
- export NVM_DIR="$HOME/.nvm"
- . "$NVM_DIR/nvm.sh"
- export PATH="$HOME/.cargo/bin:$PATH"
- nvm install 9.4.0
- nvm use 9.4.0
build_and_tests:
<<: *nvm_env
stage: build_and_tests
script:
- npm install
- npm test
"use strict";
const addon = require('../native');
const path = require('path');
module.exports = {
newFileInstance: (filePath, sigStock) => {
const instance = Object.create(WotB)
if (process.platform == 'win32') {
let bufferedPath = new Buffer(filePath,'ascii');
instance.init(addon.new_file_instance_win_32(bufferedPath, bufferedPath.length, sigStock))
} else {
instance.init(addon.new_file_instance(filePath, sigStock));
}
instance.setFilePath(filePath)
return instance
},
newMemoryInstance: (sigStock) => {
const instance = Object.create(WotB)
const id = addon.new_memory_instance(sigStock);
instance.init(id)
return instance
},
};
const WotB = {
instanceID: -1,
filePath: "",
init: function(instanceId){
this.instanceID = instanceId
},
/**
* Eventually has a file path if it is a file instance.
* @param filePath
*/
setFilePath: function(filePath) {
this.filePath = filePath
},
write: function() {
return addon.write_instance_in_file(this.instanceID, this.filePath);
},
memCopy: function() {
const copy = Object.create(WotB)
copy.instanceID = addon.mem_copy(this.instanceID);
return copy;
},
getMaxCert: function() {
return addon.get_max_links(this.instanceID);
},
getWoTSize: function() {
return addon.get_wot_size(this.instanceID);
},
isEnabled: function(nodeId) {
return addon.is_enabled(this.instanceID, nodeId);
},
getEnabled: function() {
return addon.get_enabled(this.instanceID);
},
getDisabled: function() {
return addon.get_disabled(this.instanceID);
},
getSentries: function(sentry_requirement) {
return addon.get_sentries(this.instanceID, sentry_requirement);
},
getNonSentries: function(sentry_requirement) {
return addon.get_non_sentries(this.instanceID, sentry_requirement);
},
existsLink: function(source, target) {
return addon.exist_link(this.instanceID, source, target);
},
setMaxCert: function(maxCert) {
return addon.set_max_links(this.instanceID, maxCert);
},
addNode: function() {
return addon.add_node(this.instanceID);
},
removeNode: function() {
return addon.rem_node(this.instanceID);
},
setEnabled: function(is_enabled, nodeId) {
return addon.set_enabled(this.instanceID, is_enabled, nodeId);
},
addLink: function(source, target) {
return addon.add_link(this.instanceID, source, target);
},
removeLink: function(source, target) {
return addon.rem_link(this.instanceID, source, target);
},
isOutdistanced: function(node, sentry_requirement, step_max, x_percent) {
var distance_result = addon.compute_distance(this.instanceID, node, sentry_requirement, step_max, x_percent);
return distance_result.outdistanced;
},
detailedDistance: function(node, sentry_requirement, step_max, x_percent) {
var distance_result = addon.compute_distance(this.instanceID, node, sentry_requirement, step_max, x_percent);
return {
nbReached: distance_result.reached,
nbSuccess: distance_result.success,
nbSentries: distance_result.sentries,
isOutdistanced: distance_result.outdistanced
};
},
detailedDistanceV2: function(node, sentry_requirement, step_max, x_percent) {
return addon.compute_distance(this.instanceID, node, sentry_requirement, step_max, x_percent);
},
getPaths: function(from, to, step_max) {
return addon.find_paths(this.instanceID, from, to, step_max);
},
clear: function() {
return addon.remove_wot(this.instanceID);
}
}
\ No newline at end of file
[[package]]
name = "aho-corasick"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "arrayvec"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bincode"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "byteorder"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cfg-if"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "crossbeam-deque"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "crossbeam-epoch"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "crossbeam-utils"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cslice"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "duniter-wotb"
version = "0.8.0-a0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bincode 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "either"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "fuchsia-zircon-sys"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "gcc"
version = "0.3.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "memchr"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "memoffset"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "neon"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cslice 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"neon-build 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
"neon-runtime 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "neon-build"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "neon-runtime"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cslice 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "nodrop"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "num_cpus"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro2"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quote"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rayon"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rayon-core"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "scopeguard"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "1.0.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_derive"
version = "1.0.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive_internals 0.23.1 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_derive_internals"
version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ucd-util"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unreachable"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "utf8-ranges"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "wotb-rs"
version = "0.1.0"
dependencies = [
"duniter-wotb 0.8.0-a0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"neon 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
"neon-build 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
"checksum aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6531d44de723825aa81398a6415283229725a00fa30713812ab9323faa82fc4"
"checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef"
"checksum bincode 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9a6301db0b49fb63551bc15b5ae348147101cdf323242b93ec7546d5002ff1af"
"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
"checksum byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "73b5bdfe7ee3ad0b99c9801d58807a9dbc9e09196365b0203853b99889ab3c87"
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
"checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3"
"checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150"
"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9"
"checksum cslice 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "697c714f50560202b1f4e2e09cd50a421881c83e9025db75d15f276616f04f40"
"checksum duniter-wotb 0.8.0-a0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "873a948b6755405ec2da9f25b1266fcfaf45f9ef043b08e01eab4a6f91e9e6ad"
"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d"
"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b"
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
"checksum neon 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "6f6078a0767408131206f802cb4ee2b1d78a035f23c209c3c0cb1dbe258a8737"
"checksum neon-build 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "0220c1150ca0ac00df8fc1001dde699cf17762f208f43c497d90e91c910c0a17"
"checksum neon-runtime 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "9a53b08f4dfc0ebc9ecb8bd8a02ace763e833d657f03614293254420a413c036"
"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2"
"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30"
"checksum proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "49b6a521dc81b643e9a51e0d1cf05df46d5a2f3c0280ea72bcb68276ba64a118"
"checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8"
"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5"
"checksum rayon 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80e811e76f1dbf68abf87a759083d34600017fc4e10b6bd5ad84a700f9dba4b1"
"checksum rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d24ad214285a7729b174ed6d3bcfcb80177807f959d95fafd5bfc5c4f201ac8"
"checksum regex 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "aec3f58d903a7d2a9dc2bf0e41a746f4530e0cab6b615494e058f67a3ef947fb"
"checksum regex-syntax 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bd90079345f4a4c3409214734ae220fd773c6f2e8a543d07370c6c1c369cfbfb"
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum serde 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)" = "a73973861352c932ed1365ce22b32467ce260ac4c8db11cf750ce56334ff2dcf"
"checksum serde_derive 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b392c5a0cebb98121454531c50e60e2ffe0fbeb1a44da277da2d681d08d7dc0b"
"checksum serde_derive_internals 0.23.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9d30c4596450fd7bbda79ef15559683f9a79ac0193ea819db90000d7e1cae794"
"checksum syn 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "91b52877572087400e83d24b9178488541e3d535259e04ff17a63df1e5ceff59"
"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963"
"checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[package]
name = "wotb-rs"
version = "0.1.0"
authors = ["librelois <elois@ifee.fr>"]
license = "AGPL-3.0"
build = "build.rs"
[lib]
name = "wotb_rs"
crate-type = ["dylib"]
[build-dependencies]
neon-build = "0.1.22"
[dependencies]
neon = "0.1.22"
num_cpus = "1.8.0"
duniter-wotb = "0.8.0-a0.5"
extern crate neon_build;
fn main() {
neon_build::setup(); // must be called in build.rs
// add project-specific build logic here...
}
#[macro_use]
extern crate neon;
extern crate duniter_wotb;
extern crate num_cpus;
use duniter_wotb::data::rusty::RustyWebOfTrust;
use duniter_wotb::data::{HasLinkResult, NewLinkResult, NodeId, RemLinkResult, WebOfTrust};
use duniter_wotb::operations::distance::{DistanceCalculator, RustyDistanceCalculator, WotDistance,
WotDistanceParameters};
use duniter_wotb::operations::file::{BinaryFileFormater, FileFormater};
use duniter_wotb::operations::path::{PathFinder, RustyPathFinder};
use neon::js::{JsArray, JsBoolean, JsInteger, JsNumber, JsObject, JsString, Object};
use neon::vm::{Call, JsResult};
use std::collections::HashMap;
use std::ops::{Deref, DerefMut};
static mut WOT_INSTANCES: Option<HashMap<usize, Box<RustyWebOfTrust>>> = None;
static DISTANCE_CALCULATOR: RustyDistanceCalculator = RustyDistanceCalculator {};
static FILE_FORMATER: BinaryFileFormater = BinaryFileFormater {};
static PATH_FINDER: RustyPathFinder = RustyPathFinder {};
fn get_wots() -> &'static mut HashMap<usize, Box<RustyWebOfTrust>> {
unsafe {
match WOT_INSTANCES {
Some(ref mut x) => &mut *x,
None => {
WOT_INSTANCES = Some(HashMap::new());
match WOT_INSTANCES {
Some(ref mut x) => &mut *x,
None => panic!(),
}
}
}
}
}
fn new_wot(max_links: usize) -> usize {
let wots = get_wots();
let mut instance_id = 0;
while wots.contains_key(&instance_id) {
instance_id += 1;
}
wots.insert(instance_id, Box::new(RustyWebOfTrust::new(max_links)));
instance_id
}
fn get_wot<'a>(instance_id: usize) -> &'a RustyWebOfTrust {
let wots = get_wots();
let wot = wots.get(&instance_id);
match wot {
Some(wot) => wot.deref(),
None => panic!("This instance don't exist !"),
}
}
fn get_mut_wot<'a>(instance_id: usize) -> &'a mut RustyWebOfTrust {
let wots = get_wots();
let wot = wots.get_mut(&instance_id);
match wot {
Some(wot) => wot.deref_mut(),
None => panic!("This instance don't exist !"),
}
}
fn hello(call: Call) -> JsResult<JsString> {
let scope = call.scope;
let args = call.arguments;
let mut str_ = String::from("hello node");
//let x = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
if let Some(arg) = args.get(scope, 0) {
let x = try!(arg.check::<JsInteger>()).value();
str_.push_str(&format!(" {}", x));
}
Ok(JsString::new(scope, &str_).unwrap())
}
fn threading_hint(call: Call) -> JsResult<JsNumber> {
Ok(JsNumber::new(call.scope, num_cpus::get() as f64))
}
fn new_file_instance(call: Call) -> JsResult<JsInteger> {
let scope = call.scope;
let file_path = try!(try!(call.arguments.require(scope, 0)).check::<JsString>()).value();
let max_links = try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value();
let (wot, _blockstamp) = FILE_FORMATER
.from_file(&file_path, max_links as usize)
.unwrap();
let wots = get_wots();
let mut instance_id = 0;
while wots.contains_key(&instance_id) {
instance_id += 1;
}
wots.insert(instance_id, Box::new(wot));
Ok(JsInteger::new(scope, instance_id as i32))
}
fn write_instance_in_file(call: Call) -> JsResult<JsBoolean> {
let scope = call.scope;
let instance_id =
try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value() as usize;
let file_path = try!(try!(call.arguments.require(scope, 1)).check::<JsString>()).value();
let wot = get_wot(instance_id as usize);
let header: Vec<u8> = Vec::with_capacity(0);
match FILE_FORMATER.to_file(wot, &header, &file_path) {
Ok(_) => Ok(JsBoolean::new(scope, true)),
Err(e) => panic!("Fatal error : fail to write wot in file : {:?}", e),
}
}
fn new_memory_instance(call: Call) -> JsResult<JsInteger> {
let scope = call.scope;
let max_links = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let _instance_id = new_wot(max_links as usize);
Ok(JsInteger::new(scope, _instance_id as i32))
}
fn mem_copy(call: Call) -> JsResult<JsInteger> {
let scope = call.scope;
let instance_id =
try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value() as usize;
let wots = get_wots();
let wot_copy = wots.get(&instance_id)
.expect("This instance don't exist !")
.deref()
.clone();
let mut new_instance_id = 0;
while wots.contains_key(&new_instance_id) {
new_instance_id += 1;
}
wots.insert(new_instance_id, Box::new(wot_copy));
Ok(JsInteger::new(scope, new_instance_id as i32))
}
fn get_max_links(call: Call) -> JsResult<JsInteger> {
let scope = call.scope;
let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let mut _max_links = 0;
_max_links = get_wot(instance_id as usize).get_max_link();
Ok(JsInteger::new(scope, _max_links as i32))
}
fn get_wot_size(call: Call) -> JsResult<JsInteger> {
let scope = call.scope;
let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let mut _size = 0;
_size = get_wot(instance_id as usize).size();
Ok(JsInteger::new(scope, _size as i32))
}
fn is_enabled(call: Call) -> JsResult<JsBoolean> {
let scope = call.scope;
let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let node_id = try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value();
if get_wot(instance_id as usize)
.is_enabled(NodeId(node_id as usize))
.unwrap()
{
Ok(JsBoolean::new(scope, true))
} else {
Ok(JsBoolean::new(scope, false))
}
}
fn get_enabled(call: Call) -> JsResult<JsArray> {
let scope = call.scope;
let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let enabled = get_mut_wot(instance_id as usize).get_enabled();
let mut js_array = JsArray::new(scope, enabled.len() as u32);
let mut index: u32 = 0;
for node_id in enabled {
let _bool = try!(JsArray::set(
*js_array.deref_mut(),
index,
JsInteger::new(scope, node_id.0 as i32),
));
index += 1;
}
Ok(js_array)
}
fn get_disabled(call: Call) -> JsResult<JsArray> {
let scope = call.scope;
let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let disabled = get_mut_wot(instance_id as usize).get_disabled();
let js_array = JsArray::new(scope, disabled.len() as u32);
let mut index: u32 = 0;
for node_id in disabled {
let _bool = try!(JsArray::set(
*js_array.deref(),
index,
JsInteger::new(scope, node_id.0 as i32),
));
index += 1;
}
Ok(js_array)
}
fn get_sentries(call: Call) -> JsResult<JsArray> {
let scope = call.scope;
let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let sentry_requirement =
try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value();
let sentries = get_mut_wot(instance_id as usize).get_sentries(sentry_requirement as usize);
let js_array = JsArray::new(scope, sentries.len() as u32);
let mut index: u32 = 0;
for node_id in sentries {
let _bool = try!(JsArray::set(
*js_array.deref(),
index,
JsInteger::new(scope, node_id.0 as i32),
));
index += 1;
}
Ok(js_array)
}
fn get_non_sentries(call: Call) -> JsResult<JsArray> {
let scope = call.scope;
let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let sentry_requirement =
try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value();
let non_sentries =
get_mut_wot(instance_id as usize).get_non_sentries(sentry_requirement as usize);
let js_array = JsArray::new(scope, non_sentries.len() as u32);
let mut index: u32 = 0;
for node_id in non_sentries {
let _bool = try!(JsArray::set(
*js_array.deref(),
index,
JsInteger::new(scope, node_id.0 as i32),
));
index += 1;
}
Ok(js_array)
}
fn exist_link(call: Call) -> JsResult<JsBoolean> {
let scope = call.scope;
let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let source = try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value();
let target = try!(try!(call.arguments.require(scope, 2)).check::<JsInteger>()).value();
let result =
get_wot(instance_id as usize).has_link(NodeId(source as usize), NodeId(target as usize));
if let HasLinkResult::Link(has_link) = result {
Ok(JsBoolean::new(scope, has_link))
} else {
panic!("Fatal Error : {:?}", result)
}
}
fn set_max_links(call: Call) -> JsResult<JsBoolean> {
let scope = call.scope;
let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let max_links = try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value();
let _result = get_mut_wot(instance_id as usize).set_max_link(max_links as usize);
Ok(JsBoolean::new(scope, true))
}
fn add_node(call: Call) -> JsResult<JsInteger> {
let scope = call.scope;
let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let _node_id = get_mut_wot(instance_id as usize).add_node();
Ok(JsInteger::new(scope, _node_id.0 as i32))
}
fn rem_node(call: Call) -> JsResult<JsInteger> {
let scope = call.scope;
let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
if let Some(node_id) = get_mut_wot(instance_id as usize).rem_node() {
Ok(JsInteger::new(scope, node_id.0 as i32))
} else {
panic!("Fatal error : wotb : you try to remove a node to empty wot !")
}
}
fn set_enabled(call: Call) -> JsResult<JsBoolean> {
let scope = call.scope;
let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let is_enabled = try!(try!(call.arguments.require(scope, 1)).check::<JsBoolean>()).value();
let node_id = try!(try!(call.arguments.require(scope, 2)).check::<JsInteger>()).value();
if let Some(enabled) =
get_mut_wot(instance_id as usize).set_enabled(NodeId(node_id as usize), is_enabled)
{
Ok(JsBoolean::new(scope, enabled))
} else {
panic!("Fatal error : wotb : node id don't exist !")
}
}
fn add_link(call: Call) -> JsResult<JsInteger> {
let scope = call.scope;
let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let source = try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value();
let target = try!(try!(call.arguments.require(scope, 2)).check::<JsInteger>()).value();
let result = get_mut_wot(instance_id as usize)
.add_link(NodeId(source as usize), NodeId(target as usize));
if let NewLinkResult::Ok(links_count) = result {
Ok(JsInteger::new(scope, links_count as i32))
} else {
panic!("Fatal error wotb : {:?}", result)
}
}
fn rem_link(call: Call) -> JsResult<JsInteger> {
let scope = call.scope;
let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let source = try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value();
let target = try!(try!(call.arguments.require(scope, 2)).check::<JsInteger>()).value();
let result = get_mut_wot(instance_id as usize)
.rem_link(NodeId(source as usize), NodeId(target as usize));
if let RemLinkResult::Removed(links_count) = result {
Ok(JsInteger::new(scope, links_count as i32))
} else {
panic!("Fatal Error : {:?}", result)
}
}
fn compute_distance(call: Call) -> JsResult<JsObject> {
let scope = call.scope;
let instance_id = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let node_id = try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value();
let sentry_requirement =
try!(try!(call.arguments.require(scope, 2)).check::<JsInteger>()).value() as u32;
let step_max = try!(try!(call.arguments.require(scope, 3)).check::<JsInteger>()).value() as u32;
let x_percent = try!(try!(call.arguments.require(scope, 4)).check::<JsNumber>()).value() as f64;
let distance_params = WotDistanceParameters {
node: NodeId(node_id as usize),
sentry_requirement,
step_max,
x_percent,
};
let wot = get_wot(instance_id as usize);
let WotDistance {
sentries,
success,
success_at_border,
reached,
reached_at_border,
outdistanced,
} = DISTANCE_CALCULATOR
.compute_distance(wot, distance_params)
.unwrap();
let js_object = JsObject::new(scope);
let _bool = try!(JsObject::set(
*js_object.deref(),
"sentries",
JsInteger::new(scope, sentries as i32),
));
let _bool = try!(JsObject::set(
*js_object.deref(),
"success",
JsInteger::new(scope, success as i32),
));
let _bool = try!(JsObject::set(
*js_object.deref(),
"success_at_border",
JsInteger::new(scope, success_at_border as i32),
));
let _bool = try!(JsObject::set(
*js_object.deref(),
"reached",
JsInteger::new(scope, reached as i32),
));
let _bool = try!(JsObject::set(
*js_object.deref(),
"reached_at_border",
JsInteger::new(scope, reached_at_border as i32),
));
let _bool = try!(JsObject::set(
*js_object.deref(),
"outdistanced",
JsBoolean::new(scope, outdistanced),
));
Ok(js_object)
}
fn find_paths(call: Call) -> JsResult<JsArray> {
let scope = call.scope;
let instance_id =
try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value() as usize;
let from = try!(try!(call.arguments.require(scope, 1)).check::<JsInteger>()).value() as u32;
let to = try!(try!(call.arguments.require(scope, 2)).check::<JsInteger>()).value() as u32;
let step_max = try!(try!(call.arguments.require(scope, 3)).check::<JsInteger>()).value() as u32;
let wot = get_wot(instance_id as usize);
let paths = PATH_FINDER.find_paths(wot, NodeId(from as usize), NodeId(to as usize), step_max);
let mut i: u32 = 0;
let js_paths = JsArray::new(scope, paths.len() as u32);
for path in paths {
let mut j: u32 = 0;
let js_path = JsArray::new(scope, path.len() as u32);
for node_id in path {
let _bool = try!(JsArray::set(
*js_path.deref(),
j,
JsInteger::new(scope, node_id.0 as i32),
));
j += 1;
}
let _bool = try!(JsArray::set(*js_paths.deref(), i, js_path,));
i += 1;
}
Ok(js_paths)
}
fn remove_wot(call: Call) -> JsResult<JsBoolean> {
let scope = call.scope;
let instance_id =
try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value() as usize;
let wots = get_wots();
if wots.len() > instance_id {
wots.remove(&instance_id).unwrap();
Ok(JsBoolean::new(scope, true))
} else {
Ok(JsBoolean::new(scope, false))
}
}
register_module!(m, {
m.export("hello", hello)?;
m.export("threadingHint", threading_hint)?;
m.export("new_file_instance", new_file_instance)?;
m.export("write_instance_in_file", write_instance_in_file)?;
m.export("new_memory_instance", new_memory_instance)?;
m.export("mem_copy", mem_copy)?;
m.export("get_max_links", get_max_links)?;
m.export("get_wot_size", get_wot_size)?;
m.export("is_enabled", is_enabled)?;
m.export("get_enabled", get_enabled)?;
m.export("get_disabled", get_disabled)?;
m.export("get_sentries", get_sentries)?;
m.export("get_non_sentries", get_non_sentries)?;
m.export("exist_link", exist_link)?;
m.export("set_max_links", set_max_links)?;
m.export("add_node", add_node)?;
m.export("rem_node", rem_node)?;
m.export("set_enabled", set_enabled)?;
m.export("add_link", add_link)?;
m.export("rem_link", rem_link)?;
m.export("compute_distance", compute_distance)?;
m.export("find_paths", find_paths)?;
m.export("remove_wot", remove_wot)?;
Ok(())
});
This diff is collapsed.
{
"name": "wotb-rs",
"version": "0.1.0",
"description": "Makes Web of Trust computations for the Duniter project.",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "https://git.duniter.org/nodes/typescript/wotb-rs"
},
"author": "librelois <elois@ifee.fr>",
"license": "AGPL-3.0",
"engines": {
"node": ">=9.4.0",
"npm": ">=5.6.0"
},
"dependencies": {
"neon-cli": "^0.1.22"
},
"devDependencies": {
"aws-sdk": "2.2.43",
"mocha": "2.2.5",
"should": "8.1.1"
},
"scripts": {
"test": "node \"node_modules/mocha/bin/mocha\" tests/",
"install": "neon build"
}
}
File added
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment