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
24d56663
Commit
24d56663
authored
7 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[enh] generate myself head immediatly after start
parent
cd1ff067
No related branches found
No related tags found
1 merge request
!58
Resolve "Add crates blockchain, conf, core, dal, message, module, network, tui and ws2p"
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ws2p/lib.rs
+52
-12
52 additions, 12 deletions
ws2p/lib.rs
with
52 additions
and
12 deletions
ws2p/lib.rs
+
52
−
12
View file @
24d56663
...
@@ -139,6 +139,7 @@ pub struct WS2PModuleDatas {
...
@@ -139,6 +139,7 @@ pub struct WS2PModuleDatas {
pub
threads_senders_channels
:
HashMap
<
NodeFullId
,
mpsc
::
Sender
<
WS2POrderForListeningThread
>>
,
pub
threads_senders_channels
:
HashMap
<
NodeFullId
,
mpsc
::
Sender
<
WS2POrderForListeningThread
>>
,
pub
requests_awaiting_response
:
HashMap
<
ModuleReqId
,
(
NetworkRequest
,
NodeFullId
,
SystemTime
)
>
,
pub
requests_awaiting_response
:
HashMap
<
ModuleReqId
,
(
NetworkRequest
,
NodeFullId
,
SystemTime
)
>
,
pub
heads_cache
:
HashMap
<
NodeFullId
,
NetworkHead
>
,
pub
heads_cache
:
HashMap
<
NodeFullId
,
NetworkHead
>
,
pub
my_head
:
Option
<
NetworkHead
>
,
pub
uids_cache
:
HashMap
<
ed25519
::
PublicKey
,
String
>
,
pub
uids_cache
:
HashMap
<
ed25519
::
PublicKey
,
String
>
,
}
}
...
@@ -208,7 +209,7 @@ impl DuniterModule<ed25519::PublicKey, ed25519::KeyPair, DuniterMessage> for WS2
...
@@ -208,7 +209,7 @@ impl DuniterModule<ed25519::PublicKey, ed25519::KeyPair, DuniterMessage> for WS2
keys
:
RequiredKeysContent
<
ed25519
::
PublicKey
,
ed25519
::
KeyPair
>
,
keys
:
RequiredKeysContent
<
ed25519
::
PublicKey
,
ed25519
::
KeyPair
>
,
duniter_conf
:
&
DuniterConf
,
duniter_conf
:
&
DuniterConf
,
module_conf
:
&
serde_json
::
Value
,
module_conf
:
&
serde_json
::
Value
,
main
_sender
:
mpsc
::
Sender
<
RooterThreadMessage
<
DuniterMessage
>>
,
rooter
_sender
:
mpsc
::
Sender
<
RooterThreadMessage
<
DuniterMessage
>>
,
load_conf_only
:
bool
,
load_conf_only
:
bool
,
)
->
Result
<
(),
ModuleInitError
>
{
)
->
Result
<
(),
ModuleInitError
>
{
let
start_time
=
SystemTime
::
now
();
let
start_time
=
SystemTime
::
now
();
...
@@ -224,6 +225,7 @@ impl DuniterModule<ed25519::PublicKey, ed25519::KeyPair, DuniterMessage> for WS2
...
@@ -224,6 +225,7 @@ impl DuniterModule<ed25519::PublicKey, ed25519::KeyPair, DuniterMessage> for WS2
threads_senders_channels
:
HashMap
::
new
(),
threads_senders_channels
:
HashMap
::
new
(),
requests_awaiting_response
:
HashMap
::
new
(),
requests_awaiting_response
:
HashMap
::
new
(),
heads_cache
:
HashMap
::
new
(),
heads_cache
:
HashMap
::
new
(),
my_head
:
None
,
uids_cache
:
HashMap
::
new
(),
uids_cache
:
HashMap
::
new
(),
};
};
...
@@ -259,12 +261,13 @@ impl DuniterModule<ed25519::PublicKey, ed25519::KeyPair, DuniterMessage> for WS2
...
@@ -259,12 +261,13 @@ impl DuniterModule<ed25519::PublicKey, ed25519::KeyPair, DuniterMessage> for WS2
// Launch a proxy thread that transform DuniterMessage to WS2PThreadSignal(DuniterMessage)
// Launch a proxy thread that transform DuniterMessage to WS2PThreadSignal(DuniterMessage)
thread
::
spawn
(
move
||
{
thread
::
spawn
(
move
||
{
// Send proxy sender to main
// Send proxy sender to main
match
main
_sender
.send
(
RooterThreadMessage
::
ModuleSender
(
proxy_sender_clone
))
{
match
rooter
_sender
.send
(
RooterThreadMessage
::
ModuleSender
(
proxy_sender_clone
))
{
Ok
(
_
)
=>
{
Ok
(
_
)
=>
{
debug!
(
"Send ws2p sender to main thread."
);
debug!
(
"Send ws2p sender to main thread."
);
}
}
Err
(
_
)
=>
panic!
(
"Fatal error : ws2p module fail to send is sender channel !"
),
Err
(
_
)
=>
panic!
(
"Fatal error : ws2p module fail to send is sender channel !"
),
}
}
//drop(rooter_sender);
loop
{
loop
{
match
proxy_receiver
.recv
()
{
match
proxy_receiver
.recv
()
{
Ok
(
message
)
=>
match
ws2p_sender_clone
Ok
(
message
)
=>
match
ws2p_sender_clone
...
@@ -335,14 +338,35 @@ impl DuniterModule<ed25519::PublicKey, ed25519::KeyPair, DuniterMessage> for WS2
...
@@ -335,14 +338,35 @@ impl DuniterModule<ed25519::PublicKey, ed25519::KeyPair, DuniterMessage> for WS2
for
new_follower
in
new_followers
{
for
new_follower
in
new_followers
{
debug!
(
"WS2PModule : push one follower."
);
debug!
(
"WS2PModule : push one follower."
);
ws2p_module
.followers
.push
(
new_follower
.clone
());
ws2p_module
.followers
.push
(
new_follower
.clone
());
if
current_blockstamp
==
Blockstamp
::
default
()
{
// Request local current blockstamp
// Request local current blockstamp
ws2p_module
.send_dal_request
(
&
DALRequest
::
BlockchainRequest
(
ws2p_module
.send_dal_request
(
&
DALRequest
::
BlockchainRequest
(
DALReqBlockchain
::
CurrentBlock
(
ModuleReqFullId
(
DALReqBlockchain
::
CurrentBlock
(
ModuleReqFullId
(
WS2PModule
::
id
(),
WS2PModule
::
id
(),
ModuleReqId
(
0
),
ModuleReqId
(
0
),
)),
)),
),
);
}
else
{
if
ws2p_module
.my_head
.is_none
()
{
ws2p_module
.my_head
=
Some
(
WS2PModuleDatas
::
generate_my_head
(
&
key_pair
.clone
(),
&
conf
.clone
(),
soft_name
,
soft_version
,
&
current_blockstamp
,
None
,
));
));
}
}
ws2p_module
.send_network_event
(
&
NetworkEvent
::
ReceiveHeads
(
vec!
[
ws2p_module
.my_head
.clone
()
.unwrap
(),
]),
);
}
}
}
}
&
DuniterMessage
::
NetworkRequest
(
ref
request
)
=>
match
request
{
&
DuniterMessage
::
NetworkRequest
(
ref
request
)
=>
match
request
{
&
NetworkRequest
::
GetBlocks
(
&
NetworkRequest
::
GetBlocks
(
...
@@ -414,16 +438,16 @@ impl DuniterModule<ed25519::PublicKey, ed25519::KeyPair, DuniterMessage> for WS2
...
@@ -414,16 +438,16 @@ impl DuniterModule<ed25519::PublicKey, ed25519::KeyPair, DuniterMessage> for WS2
"WS2PModule : current_blockstamp = {}"
,
"WS2PModule : current_blockstamp = {}"
,
current_blockstamp
current_blockstamp
);
);
let
my_head
=
WS2PModuleDatas
::
generate_my_head
(
ws2p_module
.
my_head
=
Some
(
WS2PModuleDatas
::
generate_my_head
(
&
key_pair
.clone
(),
&
key_pair
.clone
(),
&
conf
.clone
(),
&
conf
.clone
(),
soft_name
,
soft_name
,
soft_version
,
soft_version
,
&
current_blockstamp
,
&
current_blockstamp
,
None
,
None
,
);
)
);
ws2p_module
.send_network_event
(
&
NetworkEvent
::
ReceiveHeads
(
ws2p_module
.send_network_event
(
&
NetworkEvent
::
ReceiveHeads
(
vec!
[
my_head
],
vec!
[
ws2p_module
.my_head
.clone
()
.unwrap
()
],
));
));
}
}
_
=>
{}
_
=>
{}
...
@@ -439,6 +463,22 @@ impl DuniterModule<ed25519::PublicKey, ed25519::KeyPair, DuniterMessage> for WS2
...
@@ -439,6 +463,22 @@ impl DuniterModule<ed25519::PublicKey, ed25519::KeyPair, DuniterMessage> for WS2
current_block
.blockstamp
()
current_block
.blockstamp
()
);
);
current_blockstamp
=
current_block
.blockstamp
();
current_blockstamp
=
current_block
.blockstamp
();
if
ws2p_module
.my_head
.is_none
()
{
ws2p_module
.my_head
=
Some
(
WS2PModuleDatas
::
generate_my_head
(
&
key_pair
.clone
(),
&
conf
.clone
(),
soft_name
,
soft_version
,
&
current_blockstamp
,
None
,
));
}
ws2p_module
.send_network_event
(
&
NetworkEvent
::
ReceiveHeads
(
vec!
[
ws2p_module
.my_head
.clone
()
.unwrap
(),
]),
);
}
}
&
DALResBlockchain
::
UIDs
(
ref
uids
)
=>
{
&
DALResBlockchain
::
UIDs
(
ref
uids
)
=>
{
// Add uids to heads
// Add uids to heads
...
...
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