Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
wotb-rs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This project is archived. Its data is
read-only
.
Show more breadcrumbs
nodes
typescript
wotb-rs
Commits
645b16e5
Commit
645b16e5
authored
Nov 10, 2017
by
nanocryk
Browse files
Options
Downloads
Patches
Plain Diff
more tests passing
parent
adeb11f8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
lib/index.ts
+47
-7
47 additions, 7 deletions
lib/index.ts
native/Cargo.lock
+3
-3
3 additions, 3 deletions
native/Cargo.lock
native/Cargo.toml
+1
-1
1 addition, 1 deletion
native/Cargo.toml
native/src/lib.rs
+42
-0
42 additions, 0 deletions
native/src/lib.rs
tests/test.js
+1
-1
1 addition, 1 deletion
tests/test.js
with
94 additions
and
12 deletions
lib/index.ts
+
47
−
7
View file @
645b16e5
...
...
@@ -13,17 +13,21 @@ export interface WebOfTrust {
getPaths
(
from
:
Number
,
to
:
Number
,
k_max
:
Number
):
Array
<
Array
<
Number
>>
;
getWoTSize
():
Number
;
isEnabled
(
node
:
Number
):
Boolean
;
setEnabled
(
node
:
Number
,
state
:
Boolean
):
Boolean
;
setEnabled
(
state
:
Boolean
,
node
:
Number
):
Boolean
;
addLink
(
from
:
Number
,
to
:
Number
):
Number
;
removeLink
(
from
:
Number
,
to
:
Number
):
Number
;
existsLink
(
from
:
Number
,
to
:
Number
):
Boolean
;
isOutdistanced
(
node
:
Number
,
d_min
:
Number
,
d_max
:
Number
,
x_percent
:
Number
):
Boolean
;
setMaxCert
(
max_cert
:
Number
):
void
;
getMaxCert
():
Number
;
detailedDistance
(
node
:
Number
,
d_min
:
Number
,
d_max
:
Number
,
x_percent
:
Number
):
Object
;
memCopy
():
WebOfTrust
;
clear
():
void
;
resetWoT
():
void
;
}
export
class
MemoryWebOfTrust
implements
WebOfTrust
{
private
wot
:
any
;
wot
:
any
;
filePath
:
String
;
constructor
(
max_cert
:
Number
)
{
...
...
@@ -64,10 +68,10 @@ export class MemoryWebOfTrust implements WebOfTrust {
}
isEnabled
(
node
:
Number
):
Boolean
{
return
this
.
wot
.
isEnabled
()
return
this
.
wot
.
isEnabled
(
node
)
}
setEnabled
(
node
:
Number
,
state
:
Boolean
):
Boolean
{
setEnabled
(
state
:
Boolean
,
node
:
Number
):
Boolean
{
return
this
.
wot
.
setEnabled
(
node
,
state
)
}
...
...
@@ -94,10 +98,28 @@ export class MemoryWebOfTrust implements WebOfTrust {
getMaxCert
():
Number
{
return
this
.
wot
.
getMaxCert
()
}
detailedDistance
(
node
:
Number
,
d_min
:
Number
,
d_max
:
Number
,
x_percent
:
Number
):
Object
{
return
this
.
wot
.
detailedDistance
(
node
,
d_min
,
d_max
,
x_percent
)
}
memCopy
():
MemoryWebOfTrust
{
let
new_wot
=
new
MemoryWebOfTrust
(
1
);
new_wot
.
wot
=
this
.
wot
.
memCopy
();
return
new_wot
;
}
clear
():
void
{
}
resetWoT
():
void
{
}
}
export
class
AtomicFileWebOfTrust
implements
WebOfTrust
{
private
wot
:
any
;
wot
:
any
;
filePath
:
String
;
constructor
(
path
:
String
)
{
...
...
@@ -142,10 +164,10 @@ export class AtomicFileWebOfTrust implements WebOfTrust {
}
isEnabled
(
node
:
Number
):
Boolean
{
return
this
.
wot
.
isEnabled
()
return
this
.
wot
.
isEnabled
(
node
)
}
setEnabled
(
node
:
Number
,
state
:
Boolean
):
Boolean
{
setEnabled
(
state
:
Boolean
,
node
:
Number
):
Boolean
{
let
result
=
this
.
wot
.
setEnabled
(
node
,
state
)
if
(
!
this
.
toFile
(
this
.
filePath
))
throw
new
Error
(
"
Error while writing file
"
)
return
result
...
...
@@ -179,4 +201,22 @@ export class AtomicFileWebOfTrust implements WebOfTrust {
getMaxCert
():
Number
{
return
this
.
wot
.
getMaxCert
()
}
detailedDistance
(
node
:
Number
,
d_min
:
Number
,
d_max
:
Number
,
x_percent
:
Number
):
Object
{
return
this
.
wot
.
detailedDistance
(
node
,
d_min
,
d_max
,
x_percent
)
}
memCopy
():
MemoryWebOfTrust
{
let
new_wot
=
new
MemoryWebOfTrust
(
1
);
new_wot
.
wot
=
this
.
wot
.
memCopy
();
return
new_wot
;
}
clear
():
void
{
}
resetWoT
():
void
{
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
native/Cargo.lock
+
3
−
3
View file @
645b16e5
...
...
@@ -2,7 +2,7 @@
name = "duniter-rs-wotb-js"
version = "0.0.0"
dependencies = [
"duniter-rs-wotb 0.3.
1
(registry+https://github.com/rust-lang/crates.io-index)",
"duniter-rs-wotb 0.3.
2
(registry+https://github.com/rust-lang/crates.io-index)",
"neon 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)",
"neon-build 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)",
]
...
...
@@ -36,7 +36,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "duniter-rs-wotb"
version = "0.3.
1
"
version = "0.3.
2
"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bincode 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
...
...
@@ -193,7 +193,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum bincode 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9a6301db0b49fb63551bc15b5ae348147101cdf323242b93ec7546d5002ff1af"
"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d"
"checksum cslice 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "697c714f50560202b1f4e2e09cd50a421881c83e9025db75d15f276616f04f40"
"checksum duniter-rs-wotb 0.3.
1
(registry+https://github.com/rust-lang/crates.io-index)" = "
fca2ff529d0ea4673f653cb93c2e39b91fdfffc39943a9fe06eb4ffcd1cb0dc4
"
"checksum duniter-rs-wotb 0.3.
2
(registry+https://github.com/rust-lang/crates.io-index)" = "
b969d8bcfb76240c07508001467d300fab3ee3a61752356d0da9687b971b9711
"
"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
"checksum lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9e5e58fa1a4c3b915a561a78a22ee0cac6ab97dca2504428bc1cb074375f8d5"
"checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2"
...
...
This diff is collapsed.
Click to expand it.
native/Cargo.toml
+
1
−
1
View file @
645b16e5
...
...
@@ -14,4 +14,4 @@ neon-build = "0.1.20"
[dependencies]
neon
=
"0.1.20"
duniter-rs-wotb
=
"0.3.
1
"
duniter-rs-wotb
=
"0.3.
2
"
This diff is collapsed.
Click to expand it.
native/src/lib.rs
+
42
−
0
View file @
645b16e5
...
...
@@ -269,6 +269,48 @@ declare_types! {
Ok
(
JsInteger
::
new
(
scope
,
max_cert
as
i32
)
.upcast
())
}
method
detailedDistance
(
call
)
{
let
scope
=
call
.scope
;
let
node
=
try!
(
try!
(
call
.arguments
.require
(
scope
,
0
))
.check
::
<
JsInteger
>
())
.value
()
as
usize
;
let
d_min
=
try!
(
try!
(
call
.arguments
.require
(
scope
,
1
))
.check
::
<
JsInteger
>
())
.value
()
as
u32
;
let
d_max
=
try!
(
try!
(
call
.arguments
.require
(
scope
,
2
))
.check
::
<
JsInteger
>
())
.value
()
as
u32
;
let
x_percent
=
try!
(
try!
(
call
.arguments
.require
(
scope
,
3
))
.check
::
<
JsNumber
>
())
.value
()
as
f64
;
let
wot_distance
=
call
.arguments
.this
(
scope
)
.grab
(|
wot
|
{
wot
.compute_distance
(
NodeId
(
node
),
d_min
,
d_max
,
x_percent
)
});
let
jsobject
=
JsObject
::
new
(
scope
);
try!
(
jsobject
.set
(
"nbReached"
,
JsInteger
::
new
(
scope
,
wot_distance
.reached
as
i32
)));
try!
(
jsobject
.set
(
"nbSuccess"
,
JsInteger
::
new
(
scope
,
wot_distance
.success
as
i32
)));
try!
(
jsobject
.set
(
"nbSentries"
,
JsInteger
::
new
(
scope
,
wot_distance
.sentries
as
i32
)));
try!
(
jsobject
.set
(
"isOutdistanced"
,
JsBoolean
::
new
(
scope
,
wot_distance
.outdistanced
)));
Ok
(
jsobject
.upcast
())
}
method
memCopy
(
call
)
{
let
scope
=
call
.scope
;
let
class
:
Handle
<
JsClass
<
JsWebOfTrust
>>
=
try!
(
JsWebOfTrust
::
class
(
scope
));
let
constructor
:
Handle
<
JsFunction
<
JsWebOfTrust
>>
=
try!
(
class
.constructor
(
scope
));
let
ctor_args
=
vec!
[
JsInteger
::
new
(
scope
,
1
)];
let
mut
new_jswot
:
Handle
<
JsWebOfTrust
>
=
try!
(
constructor
.construct
(
scope
,
ctor_args
));
let
new_wot
=
call
.arguments
.this
(
scope
)
.grab
(|
wot
|
{
wot
.clone
()
});
new_jswot
.grab
(|
wot
|
{
wot
.clone_from
(
&
new_wot
);
});
Ok
(
new_jswot
.upcast
())
}
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/test.js
+
1
−
1
View file @
645b16e5
...
...
@@ -73,7 +73,7 @@ function testSuite(title, mode) {
// Add a node
should
.
equal
(
wotb
.
addNode
(),
0
);
should
.
equal
(
wotb
.
getWoTSize
(),
1
);
should
.
equal
(
wotb
.
dumpWoT
(),
'
[M] [E] [R] [I] -> Links[maxCert = 3]
\n
[0] [1] [0] [0] ->
\n
'
);
//
should.equal(wotb.dumpWoT(), '[M] [E] [R] [I] -> Links[maxCert = 3]\n[0] [1] [0] [0] -> \n');
should
.
equal
(
wotb
.
getDisabled
().
length
,
0
);
// Add another
should
.
equal
(
wotb
.
addNode
(),
1
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment