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
use crate::remote_service::{self, RemoteService};
use diem_config::utils;
use diem_crypto::ed25519::Ed25519PrivateKey;
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_addr: SocketAddr,
prikey: Option<Ed25519PrivateKey>,
network_timeout: u64,
) -> 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_addr, listen_addr, prikey, network_timeout)
});
Self {
_child: child,
server_addr,
network_timeout,
}
}
}
impl RemoteService for ThreadService {
fn server_address(&self) -> SocketAddr {
self.server_addr
}
fn network_timeout(&self) -> u64 {
self.network_timeout
}
}