Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
duniter
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
timothe
duniter
Commits
f1ed3f1e
Commit
f1ed3f1e
authored
Jun 03, 2020
by
Éloïs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cpp wot
parent
13c29d24
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
120 deletions
+18
-120
app/lib/blockchain/DuniterBlockchain.ts
app/lib/blockchain/DuniterBlockchain.ts
+1
-1
app/lib/system/directory.ts
app/lib/system/directory.ts
+14
-18
app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts
app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts
+1
-1
neon/native/src/wot/read_from_file.rs
neon/native/src/wot/read_from_file.rs
+2
-85
test/neon/test_wot.ts
test/neon/test_wot.ts
+0
-15
No files found.
app/lib/blockchain/DuniterBlockchain.ts
View file @
f1ed3f1e
...
...
@@ -329,7 +329,7 @@ export class DuniterBlockchain {
// Save wot file
if
(
!
dal
.
fs
.
isMemoryOnly
())
{
let
wotbFilepath
=
await
Directory
.
getWotbFilePath
(
dal
.
rootPath
);
const
wotbFilepath
=
Directory
.
getWotbFilePath
(
dal
.
rootPath
);
dal
.
wotb
.
writeInFile
(
wotbFilepath
);
}
...
...
app/lib/system/directory.ts
View file @
f1ed3f1e
...
...
@@ -19,8 +19,6 @@ import { Wot, WotBuilder } from "../../../neon/lib";
import
{
FileDALParams
}
from
"
../dal/fileDAL
"
;
import
{
cliprogram
}
from
"
../common-libs/programOptions
"
;
import
{
LevelDBDriver
}
from
"
../dal/drivers/LevelDBDriver
"
;
import
{
LevelUp
}
from
"
levelup
"
;
import
{
AbstractLevelDOWN
}
from
"
abstract-leveldown
"
;
const
opts
=
cliprogram
;
const
qfs
=
require
(
"
q-io/fs
"
);
...
...
@@ -196,22 +194,15 @@ export const Directory = {
return
params
;
},
getWotbFilePath
Sync
:
(
home
:
string
):
string
=>
{
getWotbFilePath
:
(
home
:
string
):
string
=>
{
let
datas_dir
=
path
.
join
(
home
,
Directory
.
DATA_DIR
);
le
t
wotbFilePath
=
path
.
join
(
datas_dir
,
Directory
.
NEW_WOTB_FILE
);
le
t
existsFile
=
fs
.
existsSync
(
wotbFilePath
);
cons
t
wotbFilePath
=
path
.
join
(
datas_dir
,
Directory
.
NEW_WOTB_FILE
);
cons
t
existsFile
=
fs
.
existsSync
(
wotbFilePath
);
if
(
!
existsFile
)
{
wotbFilePath
=
path
.
join
(
home
,
Directory
.
OLD_WOTB_FILE
);
}
return
wotbFilePath
;
},
getWotbFilePath
:
async
(
home
:
string
):
Promise
<
string
>
=>
{
let
datas_dir
=
path
.
join
(
home
,
Directory
.
DATA_DIR
);
let
wotbFilePath
=
path
.
join
(
datas_dir
,
Directory
.
NEW_WOTB_FILE
);
let
existsFile
=
qfs
.
exists
(
wotbFilePath
);
if
(
!
existsFile
)
{
wotbFilePath
=
path
.
join
(
home
,
Directory
.
OLD_WOTB_FILE
);
const
oldWotbFilePath
=
path
.
join
(
home
,
Directory
.
OLD_WOTB_FILE
);
if
(
fs
.
existsSync
(
oldWotbFilePath
))
{
throw
"
This upgrade requires resetting the data and resynchronization (duniter reset data && duniter sync).
"
;
}
}
return
wotbFilePath
;
},
...
...
@@ -233,8 +224,13 @@ export const Directory = {
// File DB
const
sqlitePath
=
path
.
join
(
home
,
Directory
.
DUNITER_DB_NAME
+
"
.db
"
);
dbf
=
()
=>
new
SQLiteDriver
(
sqlitePath
);
let
wotbFilePath
=
await
Directory
.
getWotbFilePath
(
home
);
wotbf
=
()
=>
WotBuilder
.
fromFile
(
wotbFilePath
);
try
{
const
wotbFilePath
=
Directory
.
getWotbFilePath
(
home
);
wotbf
=
()
=>
WotBuilder
.
fromFile
(
wotbFilePath
);
}
catch
(
e
)
{
console
.
log
(
e
);
throw
e
;
}
}
return
{
home
:
params
.
home
,
...
...
app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts
View file @
f1ed3f1e
...
...
@@ -105,7 +105,7 @@ export class GlobalIndexStream extends Duplex {
this
.
wotbMem
=
dal
.
wotb
;
if
(
!
this
.
memoryOnly
)
{
this
.
wotbFilePath
=
Directory
.
getWotbFilePath
Sync
(
dal
.
rootPath
);
this
.
wotbFilePath
=
Directory
.
getWotbFilePath
(
dal
.
rootPath
);
}
const
nbBlocksToDownload
=
Math
.
max
(
0
,
to
-
localNumber
);
...
...
neon/native/src/wot/read_from_file.rs
View file @
f1ed3f1e
...
...
@@ -13,12 +13,11 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use
dubp_wot
::
data
::
{
rusty
::
RustyWebOfTrust
,
WebOfTrust
,
WotId
}
;
use
dubp_wot
::
data
::
rusty
::
RustyWebOfTrust
;
use
flate2
::
read
::
ZlibDecoder
;
use
std
::
convert
::
TryFrom
;
use
std
::
fs
::
File
;
use
std
::
io
::
prelude
::
*
;
use
std
::
io
::
BufReader
;
use
std
::
path
::{
Path
,
PathBuf
};
pub
(
crate
)
fn
wot_from_file
(
file_path_str
:
String
)
->
Result
<
RustyWebOfTrust
,
String
>
{
...
...
@@ -32,23 +31,10 @@ pub(crate) fn wot_from_file(file_path_str: String) -> Result<RustyWebOfTrust, St
Ok
(
bincode
::
deserialize
::
<
RustyWebOfTrust
>
(
&
bytes
)
.map_err
(|
e
|
format!
(
"{}"
,
e
))
?
)
}
}
else
{
let
bytes
=
read_bytes_from_file
(
file_path
.as_path
())
.map_err
(|
e
|
format!
(
"{}"
,
e
))
?
;
from_cpp_wot
(
&
bytes
)
Err
(
"invalid wot file format."
.to_owned
())
}
}
/// Read bytes from file
fn
read_bytes_from_file
(
file_path
:
&
Path
)
->
Result
<
Vec
<
u8
>
,
std
::
io
::
Error
>
{
let
file
=
File
::
open
(
file_path
)
?
;
let
mut
buf_reader
=
BufReader
::
new
(
file
);
let
mut
decompressed_bytes
=
Vec
::
new
();
buf_reader
.read_to_end
(
&
mut
decompressed_bytes
)
?
;
Ok
(
decompressed_bytes
)
}
/// Read and decompress bytes from file
fn
read_and_decompress_bytes_from_file
(
file_path
:
&
Path
)
->
Result
<
Vec
<
u8
>
,
std
::
io
::
Error
>
{
if
!
file_path
.exists
()
{
...
...
@@ -68,72 +54,3 @@ fn read_and_decompress_bytes_from_file(file_path: &Path) -> Result<Vec<u8>, std:
Ok
(
vec!
[])
}
}
fn
from_cpp_wot
(
bytes
:
&
[
u8
])
->
Result
<
RustyWebOfTrust
,
String
>
{
if
bytes
.len
()
<
8
{
return
Err
(
"wot file is corrupted"
.to_owned
());
}
let
mut
buffer
=
[
0u8
;
4
];
let
mut
cursor
=
0
;
// Read max_links and create empty wot
buffer
.copy_from_slice
(
&
bytes
[
cursor
..
cursor
+
4
]);
cursor
+=
4
;
let
max_links
=
u32
::
from_le_bytes
(
buffer
);
let
mut
wot
=
RustyWebOfTrust
::
new
(
max_links
as
usize
);
// Read nodes count
buffer
.copy_from_slice
(
&
bytes
[
cursor
..
cursor
+
4
]);
cursor
+=
4
;
let
nodes_count
=
u32
::
from_le_bytes
(
buffer
);
for
_
in
0
..
nodes_count
{
let
wot_id
=
wot
.add_node
();
// Read enabled
let
enabled
=
bytes
[
cursor
];
cursor
+=
1
;
if
enabled
==
0
{
wot
.set_enabled
(
wot_id
,
false
);
}
// Read certs_count
buffer
.copy_from_slice
(
&
bytes
[
cursor
..
cursor
+
4
]);
cursor
+=
4
;
let
certs_count
=
u32
::
from_le_bytes
(
buffer
);
// Read certs
for
_
in
0
..
certs_count
{
buffer
.copy_from_slice
(
&
bytes
[
cursor
..
cursor
+
4
]);
cursor
+=
4
;
let
cert_source
=
WotId
(
u32
::
from_le_bytes
(
buffer
)
as
usize
);
wot
.add_link
(
cert_source
,
wot_id
);
}
}
Ok
(
wot
)
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
use
dubp_wot
::
data
::
HasLinkResult
;
#[test]
fn
test_from_cpp_wot
()
->
Result
<
(),
std
::
io
::
Error
>
{
let
bytes
=
read_bytes_from_file
(
PathBuf
::
from
(
"tests/wotb.bin"
)
.as_path
())
?
;
let
wot
=
from_cpp_wot
(
&
bytes
)
.expect
(
"fail to read cpp wot"
);
assert_eq!
(
wot
.get_max_link
(),
100
);
assert_eq!
(
wot
.size
(),
3394
);
assert_eq!
(
wot
.has_link
(
WotId
(
33
),
WotId
(
35
)),
HasLinkResult
::
Link
(
true
),
);
Ok
(())
}
}
test/neon/test_wot.ts
View file @
f1ed3f1e
...
...
@@ -500,19 +500,4 @@ const __OK__ = false;
assert
.
equal
(
wot
.
getSentries
(
FROM_3_LINKS_SENTRIES
).
length
,
48
);
});
}));
describe
(
'
tests cpp wot
'
,
newInstance
((
wot
)
=>
{
before
(()
=>
{
wot
=
WotBuilder
.
fromFile
(
CPP_FILE
);
});
it
(
'
should have 100 max links
'
,
function
()
{
assert
.
equal
(
wot
.
getMaxCert
(),
100
)
});
it
(
'
should have 3394 nodes
'
,
function
()
{
assert
.
equal
(
wot
.
getWoTSize
(),
3394
)
});
}));
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment