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
67
68
69
70
71
72
73
74
75
76
77
78
use std::{io, net::ToSocketAddrs};
use crate::connection::ConfigListenAddr;
/// Represents the parameters required to create a server.
#[derive(Debug, Clone)]
pub struct ServerConfig
{
/// The addresses to try to listen to.
pub addr: ConfigListenAddr,
/// If `Some`, then the server will use SSL to encode the communications.
pub ssl: Option<SslConfig>,
/// Minimum threads which always runs.
pub min_threads: Option<usize>,
/// Maximum threads which can be allocated.
pub max_threads: Option<usize>,
}
impl ServerConfig
{
pub
fn new_http<A>(addr: A) -> io::Result<ServerConfig>
where
A: ToSocketAddrs,
{
Ok(
ServerConfig
{
addr:
ConfigListenAddr::from_socket_addrs(addr)?,
ssl:
None,
min_threads:
None,
max_threads:
None,
}
)
}
pub
fn set_min_threads(mut self, cnt: usize) -> Self
{
self.min_threads = Some(cnt);
return self;
}
pub
fn set_max_threads(mut self, cnt: usize) -> Self
{
self.max_threads = Some(cnt);
return self;
}
pub
fn set_ssl(mut self, ssl: SslConfig) -> Self
{
self.ssl = Some(ssl);
return self;
}
}
/// Configuration of the server for SSL.
#[derive(Debug, Clone)]
pub struct SslConfig
{
/// Contains the public certificate to send to clients.
pub certificate: Vec<u8>,
/// Contains the ultra-secret private key used to decode communications.
pub private_key: Vec<u8>,
}