1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::{
persistent_safety_storage::PersistentSafetyStorage,
remote_service::{self, RemoteService},
};
use diem_config::utils;
use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
thread::{self, JoinHandle},
};
pub struct ThreadService {
_child: JoinHandle<()>,
server_addr: SocketAddr,
network_timeout: u64,
}
impl ThreadService {
pub fn new(
storage: PersistentSafetyStorage,
verify_vote_proposal_signature: bool,
export_consensus_key: bool,
timeout: u64,
decoupled_execution: bool,
) -> Self {
let listen_port = utils::get_available_port();
let listen_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), listen_port);
let server_addr = listen_addr;
let child = thread::spawn(move || {
remote_service::execute(
storage,
listen_addr,
verify_vote_proposal_signature,
export_consensus_key,
timeout,
decoupled_execution,
)
});
Self {
_child: child,
server_addr,
network_timeout: timeout,
}
}
}
impl RemoteService for ThreadService {
fn server_address(&self) -> SocketAddr {
self.server_addr
}
fn network_timeout_ms(&self) -> u64 {
self.network_timeout
}
}