rtc_ice/candidate/
candidate_host.rs1use super::*;
2use crate::rand::generate_cand_id;
3
4#[derive(Default)]
6pub struct CandidateHostConfig {
7 pub base_config: CandidateConfig,
8
9 pub tcp_type: TcpType,
10}
11
12impl CandidateHostConfig {
13 pub fn new_candidate_host(self) -> Result<Candidate> {
15 let mut candidate_id = self.base_config.candidate_id;
16 if candidate_id.is_empty() {
17 candidate_id = generate_cand_id();
18 }
19
20 let ip: IpAddr = match self.base_config.address.parse() {
21 Ok(ip) => ip,
22 Err(_) => return Err(Error::ErrAddressParseFailed),
23 };
24 let network_type = determine_network_type(&self.base_config.network, &ip)?;
25
26 Ok(Candidate {
27 id: candidate_id,
28 network_type,
29 candidate_type: CandidateType::Host,
30 address: self.base_config.address,
31 port: self.base_config.port,
32 resolved_addr: SocketAddr::new(ip, self.base_config.port),
33 component: self.base_config.component,
34 foundation_override: self.base_config.foundation,
35 priority_override: self.base_config.priority,
36 network: self.base_config.network,
37 tcp_type: self.tcp_type,
38 ..Candidate::default()
39 })
40 }
41}