1use std::io::Write;
4use std::path::PathBuf;
5use std::time::Duration;
6
7use crate::client::Client;
8use crate::error::Result;
9use crate::wire::DATA_TAG;
10
11pub struct ClientBuilder {
14 pub(crate) dir: PathBuf,
15 pub(crate) simplex: simplex_client::ClientBuilder,
16 pub(crate) timeout: Duration,
17 pub(crate) join_timeout: Duration,
18 pub(crate) transfer_timeout: Duration,
19 pub(crate) relays: Vec<String>,
21}
22
23impl ClientBuilder {
24 pub(crate) fn new(dir: PathBuf) -> Self {
25 Self {
26 simplex: simplex_client::Client::builder(dir.clone()).data_tag(DATA_TAG),
27 dir,
28 timeout: Duration::from_secs(60),
29 join_timeout: Duration::from_secs(120),
30 transfer_timeout: Duration::from_secs(600),
31 relays: Vec::new(),
32 }
33 }
34
35 #[must_use]
37 pub fn name(mut self, name: impl Into<String>) -> Self {
38 self.simplex = self.simplex.name(name);
39 self
40 }
41
42 #[must_use]
44 pub fn key(mut self, key: impl Into<String>) -> Self {
45 self.simplex = self.simplex.key(key);
46 self
47 }
48
49 #[must_use]
55 pub fn relay(mut self, address: impl Into<String>) -> Self {
56 let address = address.into();
57 self.relays.push(address.clone());
58 self.simplex = self.simplex.relay(address);
59 self
60 }
61
62 #[must_use]
64 pub fn log(mut self, sink: impl Write + Send + 'static) -> Self {
65 self.simplex = self.simplex.log(sink);
66 self
67 }
68
69 #[must_use]
71 pub const fn timeout(mut self, timeout: Duration) -> Self {
72 self.timeout = timeout;
73 self
74 }
75
76 #[must_use]
78 pub const fn join_timeout(mut self, timeout: Duration) -> Self {
79 self.join_timeout = timeout;
80 self
81 }
82
83 #[must_use]
85 pub const fn transfer_timeout(mut self, timeout: Duration) -> Self {
86 self.transfer_timeout = timeout;
87 self
88 }
89
90 pub fn start(self) -> Result<Client> {
95 Client::start(self)
96 }
97}