Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
6c6d1528
Commit
6c6d1528
authored
4 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[feat] server: add method get_shared_dbs()
parent
38ee199d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
rust-libs/duniter-server/src/legacy/dunp.rs
+4
-2
4 additions, 2 deletions
rust-libs/duniter-server/src/legacy/dunp.rs
rust-libs/duniter-server/src/lib.rs
+24
-33
24 additions, 33 deletions
rust-libs/duniter-server/src/lib.rs
with
28 additions
and
35 deletions
rust-libs/duniter-server/src/legacy/dunp.rs
+
4
−
2
View file @
6c6d1528
...
@@ -90,7 +90,8 @@ mod tests {
...
@@ -90,7 +90,8 @@ mod tests {
#[test]
#[test]
fn
test_receive_new_heads
()
->
anyhow
::
Result
<
()
>
{
fn
test_receive_new_heads
()
->
anyhow
::
Result
<
()
>
{
let
(
server
,
dbs
)
=
DuniterServer
::
test
(
DuniterConf
::
default
())
?
;
let
server
=
DuniterServer
::
test
(
DuniterConf
::
default
())
?
;
let
dbs
=
server
.get_shared_dbs
();
let
head
=
(
let
head
=
(
duniter_dbs
::
DunpNodeIdV1Db
::
new
(
53
,
PublicKey
::
default
()),
duniter_dbs
::
DunpNodeIdV1Db
::
new
(
53
,
PublicKey
::
default
()),
...
@@ -118,7 +119,8 @@ mod tests {
...
@@ -118,7 +119,8 @@ mod tests {
#[test]
#[test]
fn
test_save_peer
()
->
anyhow
::
Result
<
()
>
{
fn
test_save_peer
()
->
anyhow
::
Result
<
()
>
{
use
duniter_dbs
::
databases
::
dunp_v1
::
DunpV1DbReadable
as
_
;
use
duniter_dbs
::
databases
::
dunp_v1
::
DunpV1DbReadable
as
_
;
let
(
server
,
dbs
)
=
DuniterServer
::
test
(
DuniterConf
::
default
())
?
;
let
server
=
DuniterServer
::
test
(
DuniterConf
::
default
())
?
;
let
dbs
=
server
.get_shared_dbs
();
let
peer
=
PeerCardDbV1
{
let
peer
=
PeerCardDbV1
{
version
:
0
,
version
:
0
,
...
...
This diff is collapsed.
Click to expand it.
rust-libs/duniter-server/src/lib.rs
+
24
−
33
View file @
6c6d1528
...
@@ -81,24 +81,13 @@ pub struct DuniterServer {
...
@@ -81,24 +81,13 @@ pub struct DuniterServer {
pending_txs_subscriber
:
pending_txs_subscriber
:
flume
::
Receiver
<
Arc
<
Events
<
duniter_dbs
::
databases
::
txs_mp_v2
::
TxsEvent
>>>
,
flume
::
Receiver
<
Arc
<
Events
<
duniter_dbs
::
databases
::
txs_mp_v2
::
TxsEvent
>>>
,
profile_path_opt
:
Option
<
PathBuf
>
,
profile_path_opt
:
Option
<
PathBuf
>
,
shared_dbs
:
SharedDbs
<
FileBackend
>
,
txs_mempool
:
TxsMempool
,
txs_mempool
:
TxsMempool
,
}
}
#[cfg(not(test))]
type
DuniterServerInstance
=
DuniterServer
;
#[cfg(test)]
type
DuniterServerInstance
=
(
DuniterServer
,
SharedDbs
<
FileBackend
>
);
impl
DuniterServer
{
impl
DuniterServer
{
#[cfg(test)]
pub
fn
get_shared_dbs
(
&
self
)
->
SharedDbs
<
FileBackend
>
{
pub
(
crate
)
fn
test
(
conf
:
DuniterConf
)
->
anyhow
::
Result
<
DuniterServerInstance
>
{
self
.shared_dbs
.clone
()
DuniterServer
::
start
(
None
,
conf
,
"test"
.to_owned
(),
None
,
duniter_module
::
SOFTWARE_NAME
,
)
}
}
pub
fn
start
(
pub
fn
start
(
command_name
:
Option
<
String
>
,
command_name
:
Option
<
String
>
,
...
@@ -106,7 +95,7 @@ impl DuniterServer {
...
@@ -106,7 +95,7 @@ impl DuniterServer {
currency
:
String
,
currency
:
String
,
profile_path_opt
:
Option
<&
Path
>
,
profile_path_opt
:
Option
<&
Path
>
,
software_version
:
&
'static
str
,
software_version
:
&
'static
str
,
)
->
anyhow
::
Result
<
DuniterServer
Instance
>
{
)
->
anyhow
::
Result
<
DuniterServer
>
{
let
command
=
match
command_name
.unwrap_or_default
()
.as_str
()
{
let
command
=
match
command_name
.unwrap_or_default
()
.as_str
()
{
"sync"
=>
DuniterCommand
::
Sync
,
"sync"
=>
DuniterCommand
::
Sync
,
_
=>
DuniterCommand
::
Start
,
_
=>
DuniterCommand
::
Start
,
...
@@ -115,11 +104,11 @@ impl DuniterServer {
...
@@ -115,11 +104,11 @@ impl DuniterServer {
let
txs_mempool
=
TxsMempool
::
new
(
conf
.txs_mempool_size
);
let
txs_mempool
=
TxsMempool
::
new
(
conf
.txs_mempool_size
);
log
::
info!
(
"open duniter databases..."
);
log
::
info!
(
"open duniter databases..."
);
let
(
bc_db
,
dbs
)
=
duniter_dbs
::
open_dbs
(
profile_path_opt
)
?
;
let
(
bc_db
,
shared_
dbs
)
=
duniter_dbs
::
open_dbs
(
profile_path_opt
)
?
;
dbs
.dunp_db
.heads_old_write
()
.clear
()
?
;
// Clear WS2Pv1 HEADs
shared_
dbs
.dunp_db
.heads_old_write
()
.clear
()
?
;
// Clear WS2Pv1 HEADs
duniter_dbs_write_ops
::
cm
::
init
(
&
bc_db
,
&
dbs
.cm_db
)
?
;
duniter_dbs_write_ops
::
cm
::
init
(
&
bc_db
,
&
shared_
dbs
.cm_db
)
?
;
log
::
info!
(
"Databases successfully opened."
);
log
::
info!
(
"Databases successfully opened."
);
let
current
=
duniter_dbs_read_ops
::
get_current_block_meta
(
&
dbs
.cm_db
)
let
current
=
duniter_dbs_read_ops
::
get_current_block_meta
(
&
shared_
dbs
.cm_db
)
.context
(
"Fail to get current"
)
?
;
.context
(
"Fail to get current"
)
?
;
if
let
Some
(
current
)
=
current
{
if
let
Some
(
current
)
=
current
{
log
::
info!
(
"Current block: #{}-{}"
,
current
.number
,
current
.hash
);
log
::
info!
(
"Current block: #{}-{}"
,
current
.number
,
current
.hash
);
...
@@ -128,18 +117,16 @@ impl DuniterServer {
...
@@ -128,18 +117,16 @@ impl DuniterServer {
}
}
let
(
s
,
pending_txs_subscriber
)
=
flume
::
unbounded
();
let
(
s
,
pending_txs_subscriber
)
=
flume
::
unbounded
();
dbs
.txs_mp_db
shared_dbs
.txs_mp_db
.txs
()
.txs
()
.subscribe
(
s
)
.subscribe
(
s
)
.context
(
"Fail to subscribe to txs col"
)
?
;
.context
(
"Fail to subscribe to txs col"
)
?
;
log
::
info!
(
"start dbs threadpool..."
);
log
::
info!
(
"start dbs threadpool..."
);
#[cfg(test)]
let
threadpool
=
let
threadpool
=
fast_threadpool
::
ThreadPool
::
start
(
ThreadPoolConfig
::
default
(),
dbs
.clone
());
fast_threadpool
::
ThreadPool
::
start
(
ThreadPoolConfig
::
default
(),
shared_dbs
.clone
());
#[cfg(not(test))]
let
threadpool
=
fast_threadpool
::
ThreadPool
::
start
(
ThreadPoolConfig
::
default
(),
dbs
);
if
command
!=
DuniterCommand
::
Sync
&&
conf
.gva
.is_some
()
{
if
command
!=
DuniterCommand
::
Sync
&&
conf
.gva
.is_some
()
{
let
mut
runtime
=
tokio
::
runtime
::
Builder
::
new
()
let
mut
runtime
=
tokio
::
runtime
::
Builder
::
new
()
...
@@ -163,21 +150,25 @@ impl DuniterServer {
...
@@ -163,21 +150,25 @@ impl DuniterServer {
});
});
}
}
let
duniter_server
=
DuniterServer
{
Ok
(
DuniterServer
{
bc_db
,
bc_db
,
conf
,
conf
,
current
,
current
,
dbs_pool
:
threadpool
.into_sync_handler
(),
dbs_pool
:
threadpool
.into_sync_handler
(),
pending_txs_subscriber
,
pending_txs_subscriber
,
profile_path_opt
:
profile_path_opt
.map
(
ToOwned
::
to_owned
),
profile_path_opt
:
profile_path_opt
.map
(
ToOwned
::
to_owned
),
shared_dbs
,
txs_mempool
,
txs_mempool
,
};
})
cfg_if
::
cfg_if!
{
if
#[cfg(test)]
{
Ok
((
duniter_server
,
dbs
))
}
else
{
Ok
(
duniter_server
)
}
}
}
#[cfg(test)]
pub
(
crate
)
fn
test
(
conf
:
DuniterConf
)
->
anyhow
::
Result
<
DuniterServer
>
{
DuniterServer
::
start
(
None
,
conf
,
"test"
.to_owned
(),
None
,
duniter_module
::
SOFTWARE_NAME
,
)
}
}
}
}
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
register
or
sign in
to comment