Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Dunitrust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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 is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nodes
rust
Dunitrust
Commits
76c92f0b
Commit
76c92f0b
authored
6 years ago
by
Éloïs
Browse files
Options
Downloads
Plain Diff
Merge branch '101-rooter-create-conf-thread-to-write-config-changes' into 'dev'
Resolve "Rooter: create conf thread to write config changes" Closes
#101
See merge request
!87
parents
2b19a920
49fcd889
No related branches found
No related tags found
1 merge request
!87
Resolve "Rooter: create conf thread to write config changes"
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
core/lib.rs
+5
-3
5 additions, 3 deletions
core/lib.rs
core/rooter.rs
+54
-4
54 additions, 4 deletions
core/rooter.rs
message/lib.rs
+1
-1
1 addition, 1 deletion
message/lib.rs
module/lib.rs
+9
-5
9 additions, 5 deletions
module/lib.rs
with
69 additions
and
13 deletions
core/lib.rs
+
5
−
3
View file @
76c92f0b
...
...
@@ -287,15 +287,17 @@ impl<'a, 'b: 'a> DuniterCore<'b, 'a, DuRsConf> {
self
.user_command
=
Some
(
UserCommand
::
ListModules
(
ListModulesOpt
::
from_clap
(
matches
)));
// Start rooter thread
self
.rooter_sender
=
Some
(
rooter
::
start_rooter
::
<
DuRsConf
>
(
0
,
vec!
[]));
self
.rooter_sender
=
Some
(
rooter
::
start_rooter
(
0
,
profile
.clone
(),
conf
,
vec!
[]));
true
}
else
if
let
Some
(
_matches
)
=
cli_args
.subcommand_matches
(
"start"
)
{
// Store user command
self
.user_command
=
Some
(
UserCommand
::
Start
());
// Start rooter thread
self
.rooter_sender
=
Some
(
rooter
::
start_rooter
::
<
DuRsConf
>
(
self
.rooter_sender
=
Some
(
rooter
::
start_rooter
(
self
.run_duration_in_secs
,
profile
.clone
(),
conf
,
external_followers
,
));
true
...
...
@@ -314,7 +316,7 @@ impl<'a, 'b: 'a> DuniterCore<'b, 'a, DuRsConf> {
verif_hashs
:
opts
.unsafe_mode
,
}));
// Start rooter thread
self
.rooter_sender
=
Some
(
rooter
::
start_rooter
::
<
DuRsConf
>
(
0
,
vec!
[]));
self
.rooter_sender
=
Some
(
rooter
::
start_rooter
(
0
,
profile
.clone
(),
conf
,
vec!
[]));
true
}
else
if
let
Some
(
matches
)
=
cli_args
.subcommand_matches
(
"sync_ts"
)
{
let
opts
=
SyncTsOpt
::
from_clap
(
matches
);
...
...
This diff is collapsed.
Click to expand it.
core/rooter.rs
+
54
−
4
View file @
76c92f0b
...
...
@@ -15,6 +15,8 @@
//! Relay messages between durs modules.
use
duniter_conf
;
use
duniter_conf
::
DuRsConf
;
use
duniter_message
::
*
;
use
duniter_module
::
*
;
use
std
::
collections
::
HashMap
;
...
...
@@ -176,6 +178,29 @@ fn start_broadcasting_thread(
}
}
/// Start conf thread
fn
start_conf_thread
(
profile
:
&
str
,
conf
:
&
mut
DuRsConf
,
receiver
:
&
mpsc
::
Receiver
<
DursMsgContent
>
,
)
{
loop
{
match
receiver
.recv
()
{
Ok
(
msg
)
=>
{
if
let
DursMsgContent
::
SaveNewModuleConf
(
module_static_name
,
new_json_conf
)
=
msg
{
conf
.set_module_conf
(
module_static_name
.to_string
(),
new_json_conf
);
duniter_conf
::
write_conf_file
(
&
profile
,
conf
)
.expect
(
"Fail to write new module conf in conf file ! "
);
}
}
Err
(
_
)
=>
{
info!
(
"Conf thread stops."
);
break
;
}
}
}
}
/// Send msg to several receivers
fn
send_msg_to_several_receivers
(
msg
:
DursMsg
,
...
...
@@ -226,8 +251,10 @@ fn store_msg_in_pool(
}
/// Start rooter thread
pub
fn
start_rooter
<
DC
:
DuniterConf
>
(
pub
fn
start_rooter
(
run_duration_in_secs
:
u64
,
profile
:
String
,
conf
:
DuRsConf
,
external_followers
:
Vec
<
mpsc
::
Sender
<
DursMsgContent
>>
,
)
->
mpsc
::
Sender
<
RooterThreadMessage
<
DursMsg
>>
{
let
start_time
=
SystemTime
::
now
();
...
...
@@ -256,6 +283,17 @@ pub fn start_rooter<DC: DuniterConf>(
);
});
// Create conf thread channel
let
(
conf_sender
,
conf_receiver
):
(
mpsc
::
Sender
<
DursMsgContent
>
,
mpsc
::
Receiver
<
DursMsgContent
>
,
)
=
mpsc
::
channel
();
// Create conf thread
thread
::
spawn
(
move
||
{
start_conf_thread
(
&
profile
,
&
mut
conf
.clone
(),
&
conf_receiver
);
});
// Define variables
let
mut
modules_senders
:
HashMap
<
ModuleStaticName
,
mpsc
::
Sender
<
DursMsg
>>
=
HashMap
::
new
();
let
mut
pool_msgs
:
HashMap
<
ModuleStaticName
,
Vec
<
DursMsgContent
>>
=
HashMap
::
new
();
...
...
@@ -320,9 +358,21 @@ pub fn start_rooter<DC: DuniterConf>(
break
;
}
}
DursMsgReceiver
::
Role
(
_module_role
)
=>
broadcasting_sender
DursMsgReceiver
::
Role
(
role
)
=>
// If the message is intended for role "ChangeConf", forward it to the conf thread
{
if
let
ModuleRole
::
ChangeConf
=
role
{
conf_sender
.send
(
msg
.1
)
.expect
(
"Fail to reach conf thread !"
);
}
else
{
broadcasting_sender
.send
(
RooterThreadMessage
::
ModuleMessage
(
msg
))
.expect
(
"Fail to relay message to broadcasting thread !"
),
.expect
(
"Fail to relay message to broadcasting thread !"
,
);
}
}
DursMsgReceiver
::
Event
(
_module_event
)
=>
broadcasting_sender
.send
(
RooterThreadMessage
::
ModuleMessage
(
msg
))
.expect
(
"Fail to relay message to broadcasting thread !"
),
...
...
This diff is collapsed.
Click to expand it.
message/lib.rs
+
1
−
1
View file @
76c92f0b
...
...
@@ -75,7 +75,7 @@ pub enum DursMsgContent {
/// Brut binary message
Binary
(
Vec
<
u8
>
),
/// New configuration of a module to save
SaveNewModuleConf
(
ModuleName
,
serde_json
::
Value
),
SaveNewModuleConf
(
Module
Static
Name
,
serde_json
::
Value
),
/// Response of DALRequest
DALResponse
(
Box
<
DALResponse
>
),
/// Blockchain event
...
...
This diff is collapsed.
Click to expand it.
module/lib.rs
+
9
−
5
View file @
76c92f0b
...
...
@@ -105,7 +105,9 @@ impl ToString for ModuleReqFullId {
}
/// Duniter configuration
pub
trait
DuniterConf
:
Clone
+
Debug
+
Default
+
PartialEq
+
Serialize
+
DeserializeOwned
{
pub
trait
DuniterConf
:
Clone
+
Debug
+
Default
+
PartialEq
+
Serialize
+
DeserializeOwned
+
Send
+
ToOwned
{
/// Get conf version profile
fn
version
(
&
self
)
->
usize
;
/// Get currency
...
...
@@ -155,16 +157,18 @@ pub enum ModuleRole {
BlockValidation
,
/// Generates the content of the next block
BlockGeneration
,
/// Manage pending data for the wot
WotPool
,
/// Change configuration file
ChangeConf
,
/// Communicates with client software
ClientsNetwork
,
/// Manage pending data for the currency (transactions and scripts)
CurrencyPool
,
/// Manages the network between nodes implementing the DUP protocol
InterNodesNetwork
,
/// Communicates with client software
ClientsNetwork
,
/// Communicates with the node user
UserInterface
,
/// Manage pending data for the wot
WotPool
,
}
#[derive(Debug,
Copy,
Clone,
PartialEq,
Eq,
Hash)]
...
...
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