Struct librice::candidate::CandidateBuilder
source · pub struct CandidateBuilder { /* private fields */ }
Implementations§
source§impl CandidateBuilder
impl CandidateBuilder
sourcepub fn build(self) -> Candidate
pub fn build(self) -> Candidate
Builds the candidate
Examples
let addr: SocketAddr = "127.0.0.1:2345".parse().unwrap();
let candidate = Candidate::builder(
0,
CandidateType::Host,
TransportType::Udp,
"foundation",
addr,
)
.priority(1234)
.build();
assert_eq!(candidate.to_sdp_string(), "candidate foundation 0 UDP 1234 127.0.0.1 2345 host")
Examples found in repository?
src/gathering.rs (line 202)
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
pub fn gather_component(
component_id: usize,
local_agents: Vec<StunAgent>,
stun_servers: Vec<(TransportType, SocketAddr)>,
) -> impl Stream<Item = (Candidate, StunAgent)> {
let futures = futures::stream::FuturesUnordered::new();
for f in local_agents
.iter()
.enumerate()
.filter_map(|(i, agent)| match &agent.inner.channel {
StunChannel::UdpAny(schannel) => Some(futures::future::ready(
udp_socket_host_gather_candidate(schannel.socket(), (i * 10) as u8)
.map(|ga| (ga, agent.clone())),
)),
_ => None,
})
{
futures.push(f.boxed_local());
}
for (i, agent) in local_agents.iter().cloned().enumerate() {
for stun_server in stun_servers.iter() {
futures.push(
{
let agent = agent.clone();
let stun_server = *stun_server;
async move {
gather_stun_xor_address(
(i * 10) as u8,
agent.clone(),
stun_server.0,
stun_server.1,
)
.await
.map(move |ga| (ga, agent))
}
}
.boxed_local(),
)
}
}
// TODO: add peer-reflexive and relayed (TURN) candidates
let produced = Arc::new(Mutex::new(Vec::new()));
futures.filter_map(move |ga| {
let produced = produced.clone();
async move {
match ga {
Ok((ga, channel)) => {
let priority = Candidate::calculate_priority(
ga.ctype,
ga.local_preference as u32,
component_id,
);
trace!("candidate {:?}, {:?}", ga, priority);
if address_is_ignorable(ga.address.ip()) {
return None;
}
if address_is_ignorable(ga.base.ip()) {
return None;
}
let mut produced = produced.lock().unwrap();
let mut builder = Candidate::builder(
component_id,
ga.ctype,
ga.transport,
&produced.len().to_string(),
ga.address,
)
.priority(priority)
.base_address(ga.base);
if let Some(related) = ga.related {
builder = builder.related_address(related);
}
let cand = builder.build();
for c in produced.iter() {
// ignore candidates that produce the same local/remote pair of
// addresses
if cand.redundant_with(c) {
trace!("redundant {:?}", cand);
return None;
}
}
debug!("producing {:?}", cand);
produced.push(cand.clone());
Some((cand, channel))
}
Err(e) => {
trace!("candidate retrieval error \'{:?}\'", e);
None
}
}
}
})
}
More examples
src/candidate.rs (line 519)
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
fn parse_candidate(s: &str) -> Result<Candidate, ParseCandidateError> {
let (s, _) = tag::<_, _, nom::error::Error<_>>("candidate")(s)
.map_err(|_| ParseCandidateError::NotCandidate)?;
let s = skip_spaces(s)?;
let (s, foundation) = take_while_m_n::<_, _, nom::error::Error<_>>(1, 32, is_ice_char)(s)
.map_err(|_| ParseCandidateError::BadFoundation)?;
let s = skip_spaces(s)?;
let (s, component_id): (_, usize) = map_res(
take_while_m_n::<_, _, nom::error::Error<_>>(1, 3, is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadComponentId)?;
let s = skip_spaces(s)?;
let (s, transport_type) = take_while1::<_, _, nom::error::Error<_>>(is_alphabetic)(s)
.map_err(|_| ParseCandidateError::BadTransportType)?;
let transport_type = TransportType::from_str(transport_type)?;
let s = skip_spaces(s)?;
let (s, priority) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadPriority)?;
let s = skip_spaces(s)?;
// FIXME: proper address parsing
let (s, connection_address) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_part_of_socket_addr),
|s: &str| s.parse(),
)(s)
.map_err(|_| ParseCandidateError::BadAddress)?;
let s = skip_spaces(s)?;
let (s, port) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadAddress)?;
let address = SocketAddr::new(connection_address, port);
let s = skip_spaces(s)?;
let (s, candidate_type) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_alphabetic),
CandidateType::from_str,
)(s)
.map_err(|_| ParseCandidateError::BadCandidateType)?;
let mut builder = Candidate::builder(
component_id,
candidate_type,
transport_type,
foundation,
address,
)
.priority(priority)
.base_address(address);
let mut iter_s = s;
let mut expected_next = None;
let mut raddr = None;
while !iter_s.is_empty() {
let s = skip_spaces(iter_s)?;
let (s, ext_key) = take_while1::<_, _, nom::error::Error<_>>(is_part_of_byte_string)(s)
.map_err(|_| ParseCandidateError::BadExtension)?;
let s = skip_spaces(s)?;
let (s, ext_value) =
take_while1::<_, _, nom::error::Error<_>>(is_part_of_byte_string)(s)
.map_err(|_| ParseCandidateError::BadExtension)?;
if let Some(expected_next) = expected_next {
if ext_key != expected_next {
return Err(ParseCandidateError::BadExtension);
}
if expected_next == "rport" {
let raddr = raddr.take().ok_or(ParseCandidateError::BadAddress)?;
let port =
str::parse(ext_value).map_err(|_| ParseCandidateError::BadAddress)?;
builder = builder.related_address(SocketAddr::new(raddr, port));
} else {
unreachable!();
}
} else {
match ext_key {
"raddr" => {
raddr = Some(
ext_value
.parse()
.map_err(|_| ParseCandidateError::BadAddress)?,
);
expected_next = Some("rport");
}
"tcptype" => {
let tcp_type = TcpType::from_str(ext_value)?;
builder = builder.tcp_type(tcp_type);
}
_ => builder = builder.extension(ext_key, ext_value),
}
}
iter_s = s;
}
if builder.ttype == TransportType::Tcp && builder.tcp_type == None {
return Err(ParseCandidateError::BadTransportType);
}
Ok(builder.build())
}
sourcepub fn priority(self, priority: u32) -> Self
pub fn priority(self, priority: u32) -> Self
Specify the priority of the to be built candidate
Examples found in repository?
src/gathering.rs (line 197)
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
pub fn gather_component(
component_id: usize,
local_agents: Vec<StunAgent>,
stun_servers: Vec<(TransportType, SocketAddr)>,
) -> impl Stream<Item = (Candidate, StunAgent)> {
let futures = futures::stream::FuturesUnordered::new();
for f in local_agents
.iter()
.enumerate()
.filter_map(|(i, agent)| match &agent.inner.channel {
StunChannel::UdpAny(schannel) => Some(futures::future::ready(
udp_socket_host_gather_candidate(schannel.socket(), (i * 10) as u8)
.map(|ga| (ga, agent.clone())),
)),
_ => None,
})
{
futures.push(f.boxed_local());
}
for (i, agent) in local_agents.iter().cloned().enumerate() {
for stun_server in stun_servers.iter() {
futures.push(
{
let agent = agent.clone();
let stun_server = *stun_server;
async move {
gather_stun_xor_address(
(i * 10) as u8,
agent.clone(),
stun_server.0,
stun_server.1,
)
.await
.map(move |ga| (ga, agent))
}
}
.boxed_local(),
)
}
}
// TODO: add peer-reflexive and relayed (TURN) candidates
let produced = Arc::new(Mutex::new(Vec::new()));
futures.filter_map(move |ga| {
let produced = produced.clone();
async move {
match ga {
Ok((ga, channel)) => {
let priority = Candidate::calculate_priority(
ga.ctype,
ga.local_preference as u32,
component_id,
);
trace!("candidate {:?}, {:?}", ga, priority);
if address_is_ignorable(ga.address.ip()) {
return None;
}
if address_is_ignorable(ga.base.ip()) {
return None;
}
let mut produced = produced.lock().unwrap();
let mut builder = Candidate::builder(
component_id,
ga.ctype,
ga.transport,
&produced.len().to_string(),
ga.address,
)
.priority(priority)
.base_address(ga.base);
if let Some(related) = ga.related {
builder = builder.related_address(related);
}
let cand = builder.build();
for c in produced.iter() {
// ignore candidates that produce the same local/remote pair of
// addresses
if cand.redundant_with(c) {
trace!("redundant {:?}", cand);
return None;
}
}
debug!("producing {:?}", cand);
produced.push(cand.clone());
Some((cand, channel))
}
Err(e) => {
trace!("candidate retrieval error \'{:?}\'", e);
None
}
}
}
})
}
More examples
src/candidate.rs (line 466)
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
fn parse_candidate(s: &str) -> Result<Candidate, ParseCandidateError> {
let (s, _) = tag::<_, _, nom::error::Error<_>>("candidate")(s)
.map_err(|_| ParseCandidateError::NotCandidate)?;
let s = skip_spaces(s)?;
let (s, foundation) = take_while_m_n::<_, _, nom::error::Error<_>>(1, 32, is_ice_char)(s)
.map_err(|_| ParseCandidateError::BadFoundation)?;
let s = skip_spaces(s)?;
let (s, component_id): (_, usize) = map_res(
take_while_m_n::<_, _, nom::error::Error<_>>(1, 3, is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadComponentId)?;
let s = skip_spaces(s)?;
let (s, transport_type) = take_while1::<_, _, nom::error::Error<_>>(is_alphabetic)(s)
.map_err(|_| ParseCandidateError::BadTransportType)?;
let transport_type = TransportType::from_str(transport_type)?;
let s = skip_spaces(s)?;
let (s, priority) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadPriority)?;
let s = skip_spaces(s)?;
// FIXME: proper address parsing
let (s, connection_address) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_part_of_socket_addr),
|s: &str| s.parse(),
)(s)
.map_err(|_| ParseCandidateError::BadAddress)?;
let s = skip_spaces(s)?;
let (s, port) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadAddress)?;
let address = SocketAddr::new(connection_address, port);
let s = skip_spaces(s)?;
let (s, candidate_type) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_alphabetic),
CandidateType::from_str,
)(s)
.map_err(|_| ParseCandidateError::BadCandidateType)?;
let mut builder = Candidate::builder(
component_id,
candidate_type,
transport_type,
foundation,
address,
)
.priority(priority)
.base_address(address);
let mut iter_s = s;
let mut expected_next = None;
let mut raddr = None;
while !iter_s.is_empty() {
let s = skip_spaces(iter_s)?;
let (s, ext_key) = take_while1::<_, _, nom::error::Error<_>>(is_part_of_byte_string)(s)
.map_err(|_| ParseCandidateError::BadExtension)?;
let s = skip_spaces(s)?;
let (s, ext_value) =
take_while1::<_, _, nom::error::Error<_>>(is_part_of_byte_string)(s)
.map_err(|_| ParseCandidateError::BadExtension)?;
if let Some(expected_next) = expected_next {
if ext_key != expected_next {
return Err(ParseCandidateError::BadExtension);
}
if expected_next == "rport" {
let raddr = raddr.take().ok_or(ParseCandidateError::BadAddress)?;
let port =
str::parse(ext_value).map_err(|_| ParseCandidateError::BadAddress)?;
builder = builder.related_address(SocketAddr::new(raddr, port));
} else {
unreachable!();
}
} else {
match ext_key {
"raddr" => {
raddr = Some(
ext_value
.parse()
.map_err(|_| ParseCandidateError::BadAddress)?,
);
expected_next = Some("rport");
}
"tcptype" => {
let tcp_type = TcpType::from_str(ext_value)?;
builder = builder.tcp_type(tcp_type);
}
_ => builder = builder.extension(ext_key, ext_value),
}
}
iter_s = s;
}
if builder.ttype == TransportType::Tcp && builder.tcp_type == None {
return Err(ParseCandidateError::BadTransportType);
}
Ok(builder.build())
}
sourcepub fn base_address(self, base_address: SocketAddr) -> Self
pub fn base_address(self, base_address: SocketAddr) -> Self
Specify the base address of the to be built candidate
Examples found in repository?
src/gathering.rs (line 198)
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
pub fn gather_component(
component_id: usize,
local_agents: Vec<StunAgent>,
stun_servers: Vec<(TransportType, SocketAddr)>,
) -> impl Stream<Item = (Candidate, StunAgent)> {
let futures = futures::stream::FuturesUnordered::new();
for f in local_agents
.iter()
.enumerate()
.filter_map(|(i, agent)| match &agent.inner.channel {
StunChannel::UdpAny(schannel) => Some(futures::future::ready(
udp_socket_host_gather_candidate(schannel.socket(), (i * 10) as u8)
.map(|ga| (ga, agent.clone())),
)),
_ => None,
})
{
futures.push(f.boxed_local());
}
for (i, agent) in local_agents.iter().cloned().enumerate() {
for stun_server in stun_servers.iter() {
futures.push(
{
let agent = agent.clone();
let stun_server = *stun_server;
async move {
gather_stun_xor_address(
(i * 10) as u8,
agent.clone(),
stun_server.0,
stun_server.1,
)
.await
.map(move |ga| (ga, agent))
}
}
.boxed_local(),
)
}
}
// TODO: add peer-reflexive and relayed (TURN) candidates
let produced = Arc::new(Mutex::new(Vec::new()));
futures.filter_map(move |ga| {
let produced = produced.clone();
async move {
match ga {
Ok((ga, channel)) => {
let priority = Candidate::calculate_priority(
ga.ctype,
ga.local_preference as u32,
component_id,
);
trace!("candidate {:?}, {:?}", ga, priority);
if address_is_ignorable(ga.address.ip()) {
return None;
}
if address_is_ignorable(ga.base.ip()) {
return None;
}
let mut produced = produced.lock().unwrap();
let mut builder = Candidate::builder(
component_id,
ga.ctype,
ga.transport,
&produced.len().to_string(),
ga.address,
)
.priority(priority)
.base_address(ga.base);
if let Some(related) = ga.related {
builder = builder.related_address(related);
}
let cand = builder.build();
for c in produced.iter() {
// ignore candidates that produce the same local/remote pair of
// addresses
if cand.redundant_with(c) {
trace!("redundant {:?}", cand);
return None;
}
}
debug!("producing {:?}", cand);
produced.push(cand.clone());
Some((cand, channel))
}
Err(e) => {
trace!("candidate retrieval error \'{:?}\'", e);
None
}
}
}
})
}
More examples
src/candidate.rs (line 467)
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
fn parse_candidate(s: &str) -> Result<Candidate, ParseCandidateError> {
let (s, _) = tag::<_, _, nom::error::Error<_>>("candidate")(s)
.map_err(|_| ParseCandidateError::NotCandidate)?;
let s = skip_spaces(s)?;
let (s, foundation) = take_while_m_n::<_, _, nom::error::Error<_>>(1, 32, is_ice_char)(s)
.map_err(|_| ParseCandidateError::BadFoundation)?;
let s = skip_spaces(s)?;
let (s, component_id): (_, usize) = map_res(
take_while_m_n::<_, _, nom::error::Error<_>>(1, 3, is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadComponentId)?;
let s = skip_spaces(s)?;
let (s, transport_type) = take_while1::<_, _, nom::error::Error<_>>(is_alphabetic)(s)
.map_err(|_| ParseCandidateError::BadTransportType)?;
let transport_type = TransportType::from_str(transport_type)?;
let s = skip_spaces(s)?;
let (s, priority) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadPriority)?;
let s = skip_spaces(s)?;
// FIXME: proper address parsing
let (s, connection_address) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_part_of_socket_addr),
|s: &str| s.parse(),
)(s)
.map_err(|_| ParseCandidateError::BadAddress)?;
let s = skip_spaces(s)?;
let (s, port) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadAddress)?;
let address = SocketAddr::new(connection_address, port);
let s = skip_spaces(s)?;
let (s, candidate_type) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_alphabetic),
CandidateType::from_str,
)(s)
.map_err(|_| ParseCandidateError::BadCandidateType)?;
let mut builder = Candidate::builder(
component_id,
candidate_type,
transport_type,
foundation,
address,
)
.priority(priority)
.base_address(address);
let mut iter_s = s;
let mut expected_next = None;
let mut raddr = None;
while !iter_s.is_empty() {
let s = skip_spaces(iter_s)?;
let (s, ext_key) = take_while1::<_, _, nom::error::Error<_>>(is_part_of_byte_string)(s)
.map_err(|_| ParseCandidateError::BadExtension)?;
let s = skip_spaces(s)?;
let (s, ext_value) =
take_while1::<_, _, nom::error::Error<_>>(is_part_of_byte_string)(s)
.map_err(|_| ParseCandidateError::BadExtension)?;
if let Some(expected_next) = expected_next {
if ext_key != expected_next {
return Err(ParseCandidateError::BadExtension);
}
if expected_next == "rport" {
let raddr = raddr.take().ok_or(ParseCandidateError::BadAddress)?;
let port =
str::parse(ext_value).map_err(|_| ParseCandidateError::BadAddress)?;
builder = builder.related_address(SocketAddr::new(raddr, port));
} else {
unreachable!();
}
} else {
match ext_key {
"raddr" => {
raddr = Some(
ext_value
.parse()
.map_err(|_| ParseCandidateError::BadAddress)?,
);
expected_next = Some("rport");
}
"tcptype" => {
let tcp_type = TcpType::from_str(ext_value)?;
builder = builder.tcp_type(tcp_type);
}
_ => builder = builder.extension(ext_key, ext_value),
}
}
iter_s = s;
}
if builder.ttype == TransportType::Tcp && builder.tcp_type == None {
return Err(ParseCandidateError::BadTransportType);
}
Ok(builder.build())
}
Specify the related address of the to be built candidate
Examples found in repository?
src/gathering.rs (line 200)
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
pub fn gather_component(
component_id: usize,
local_agents: Vec<StunAgent>,
stun_servers: Vec<(TransportType, SocketAddr)>,
) -> impl Stream<Item = (Candidate, StunAgent)> {
let futures = futures::stream::FuturesUnordered::new();
for f in local_agents
.iter()
.enumerate()
.filter_map(|(i, agent)| match &agent.inner.channel {
StunChannel::UdpAny(schannel) => Some(futures::future::ready(
udp_socket_host_gather_candidate(schannel.socket(), (i * 10) as u8)
.map(|ga| (ga, agent.clone())),
)),
_ => None,
})
{
futures.push(f.boxed_local());
}
for (i, agent) in local_agents.iter().cloned().enumerate() {
for stun_server in stun_servers.iter() {
futures.push(
{
let agent = agent.clone();
let stun_server = *stun_server;
async move {
gather_stun_xor_address(
(i * 10) as u8,
agent.clone(),
stun_server.0,
stun_server.1,
)
.await
.map(move |ga| (ga, agent))
}
}
.boxed_local(),
)
}
}
// TODO: add peer-reflexive and relayed (TURN) candidates
let produced = Arc::new(Mutex::new(Vec::new()));
futures.filter_map(move |ga| {
let produced = produced.clone();
async move {
match ga {
Ok((ga, channel)) => {
let priority = Candidate::calculate_priority(
ga.ctype,
ga.local_preference as u32,
component_id,
);
trace!("candidate {:?}, {:?}", ga, priority);
if address_is_ignorable(ga.address.ip()) {
return None;
}
if address_is_ignorable(ga.base.ip()) {
return None;
}
let mut produced = produced.lock().unwrap();
let mut builder = Candidate::builder(
component_id,
ga.ctype,
ga.transport,
&produced.len().to_string(),
ga.address,
)
.priority(priority)
.base_address(ga.base);
if let Some(related) = ga.related {
builder = builder.related_address(related);
}
let cand = builder.build();
for c in produced.iter() {
// ignore candidates that produce the same local/remote pair of
// addresses
if cand.redundant_with(c) {
trace!("redundant {:?}", cand);
return None;
}
}
debug!("producing {:?}", cand);
produced.push(cand.clone());
Some((cand, channel))
}
Err(e) => {
trace!("candidate retrieval error \'{:?}\'", e);
None
}
}
}
})
}
More examples
src/candidate.rs (line 490)
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
fn parse_candidate(s: &str) -> Result<Candidate, ParseCandidateError> {
let (s, _) = tag::<_, _, nom::error::Error<_>>("candidate")(s)
.map_err(|_| ParseCandidateError::NotCandidate)?;
let s = skip_spaces(s)?;
let (s, foundation) = take_while_m_n::<_, _, nom::error::Error<_>>(1, 32, is_ice_char)(s)
.map_err(|_| ParseCandidateError::BadFoundation)?;
let s = skip_spaces(s)?;
let (s, component_id): (_, usize) = map_res(
take_while_m_n::<_, _, nom::error::Error<_>>(1, 3, is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadComponentId)?;
let s = skip_spaces(s)?;
let (s, transport_type) = take_while1::<_, _, nom::error::Error<_>>(is_alphabetic)(s)
.map_err(|_| ParseCandidateError::BadTransportType)?;
let transport_type = TransportType::from_str(transport_type)?;
let s = skip_spaces(s)?;
let (s, priority) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadPriority)?;
let s = skip_spaces(s)?;
// FIXME: proper address parsing
let (s, connection_address) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_part_of_socket_addr),
|s: &str| s.parse(),
)(s)
.map_err(|_| ParseCandidateError::BadAddress)?;
let s = skip_spaces(s)?;
let (s, port) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadAddress)?;
let address = SocketAddr::new(connection_address, port);
let s = skip_spaces(s)?;
let (s, candidate_type) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_alphabetic),
CandidateType::from_str,
)(s)
.map_err(|_| ParseCandidateError::BadCandidateType)?;
let mut builder = Candidate::builder(
component_id,
candidate_type,
transport_type,
foundation,
address,
)
.priority(priority)
.base_address(address);
let mut iter_s = s;
let mut expected_next = None;
let mut raddr = None;
while !iter_s.is_empty() {
let s = skip_spaces(iter_s)?;
let (s, ext_key) = take_while1::<_, _, nom::error::Error<_>>(is_part_of_byte_string)(s)
.map_err(|_| ParseCandidateError::BadExtension)?;
let s = skip_spaces(s)?;
let (s, ext_value) =
take_while1::<_, _, nom::error::Error<_>>(is_part_of_byte_string)(s)
.map_err(|_| ParseCandidateError::BadExtension)?;
if let Some(expected_next) = expected_next {
if ext_key != expected_next {
return Err(ParseCandidateError::BadExtension);
}
if expected_next == "rport" {
let raddr = raddr.take().ok_or(ParseCandidateError::BadAddress)?;
let port =
str::parse(ext_value).map_err(|_| ParseCandidateError::BadAddress)?;
builder = builder.related_address(SocketAddr::new(raddr, port));
} else {
unreachable!();
}
} else {
match ext_key {
"raddr" => {
raddr = Some(
ext_value
.parse()
.map_err(|_| ParseCandidateError::BadAddress)?,
);
expected_next = Some("rport");
}
"tcptype" => {
let tcp_type = TcpType::from_str(ext_value)?;
builder = builder.tcp_type(tcp_type);
}
_ => builder = builder.extension(ext_key, ext_value),
}
}
iter_s = s;
}
if builder.ttype == TransportType::Tcp && builder.tcp_type == None {
return Err(ParseCandidateError::BadTransportType);
}
Ok(builder.build())
}
sourcepub fn tcp_type(self, tcp_type: TcpType) -> Self
pub fn tcp_type(self, tcp_type: TcpType) -> Self
Specify the type of TCP connection of the to be built candidate
- This will panic at build() time if the transport type is not
TransportType::Tcp
. - This will panic at build() time if this function is not called but the
transport type is
TransportType::Tcp
Examples found in repository?
src/candidate.rs (line 506)
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
fn parse_candidate(s: &str) -> Result<Candidate, ParseCandidateError> {
let (s, _) = tag::<_, _, nom::error::Error<_>>("candidate")(s)
.map_err(|_| ParseCandidateError::NotCandidate)?;
let s = skip_spaces(s)?;
let (s, foundation) = take_while_m_n::<_, _, nom::error::Error<_>>(1, 32, is_ice_char)(s)
.map_err(|_| ParseCandidateError::BadFoundation)?;
let s = skip_spaces(s)?;
let (s, component_id): (_, usize) = map_res(
take_while_m_n::<_, _, nom::error::Error<_>>(1, 3, is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadComponentId)?;
let s = skip_spaces(s)?;
let (s, transport_type) = take_while1::<_, _, nom::error::Error<_>>(is_alphabetic)(s)
.map_err(|_| ParseCandidateError::BadTransportType)?;
let transport_type = TransportType::from_str(transport_type)?;
let s = skip_spaces(s)?;
let (s, priority) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadPriority)?;
let s = skip_spaces(s)?;
// FIXME: proper address parsing
let (s, connection_address) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_part_of_socket_addr),
|s: &str| s.parse(),
)(s)
.map_err(|_| ParseCandidateError::BadAddress)?;
let s = skip_spaces(s)?;
let (s, port) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadAddress)?;
let address = SocketAddr::new(connection_address, port);
let s = skip_spaces(s)?;
let (s, candidate_type) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_alphabetic),
CandidateType::from_str,
)(s)
.map_err(|_| ParseCandidateError::BadCandidateType)?;
let mut builder = Candidate::builder(
component_id,
candidate_type,
transport_type,
foundation,
address,
)
.priority(priority)
.base_address(address);
let mut iter_s = s;
let mut expected_next = None;
let mut raddr = None;
while !iter_s.is_empty() {
let s = skip_spaces(iter_s)?;
let (s, ext_key) = take_while1::<_, _, nom::error::Error<_>>(is_part_of_byte_string)(s)
.map_err(|_| ParseCandidateError::BadExtension)?;
let s = skip_spaces(s)?;
let (s, ext_value) =
take_while1::<_, _, nom::error::Error<_>>(is_part_of_byte_string)(s)
.map_err(|_| ParseCandidateError::BadExtension)?;
if let Some(expected_next) = expected_next {
if ext_key != expected_next {
return Err(ParseCandidateError::BadExtension);
}
if expected_next == "rport" {
let raddr = raddr.take().ok_or(ParseCandidateError::BadAddress)?;
let port =
str::parse(ext_value).map_err(|_| ParseCandidateError::BadAddress)?;
builder = builder.related_address(SocketAddr::new(raddr, port));
} else {
unreachable!();
}
} else {
match ext_key {
"raddr" => {
raddr = Some(
ext_value
.parse()
.map_err(|_| ParseCandidateError::BadAddress)?,
);
expected_next = Some("rport");
}
"tcptype" => {
let tcp_type = TcpType::from_str(ext_value)?;
builder = builder.tcp_type(tcp_type);
}
_ => builder = builder.extension(ext_key, ext_value),
}
}
iter_s = s;
}
if builder.ttype == TransportType::Tcp && builder.tcp_type == None {
return Err(ParseCandidateError::BadTransportType);
}
Ok(builder.build())
}
sourcepub fn extension(self, key: &str, val: &str) -> Self
pub fn extension(self, key: &str, val: &str) -> Self
Add an extension attribute to the candidate
Examples found in repository?
src/candidate.rs (line 508)
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
fn parse_candidate(s: &str) -> Result<Candidate, ParseCandidateError> {
let (s, _) = tag::<_, _, nom::error::Error<_>>("candidate")(s)
.map_err(|_| ParseCandidateError::NotCandidate)?;
let s = skip_spaces(s)?;
let (s, foundation) = take_while_m_n::<_, _, nom::error::Error<_>>(1, 32, is_ice_char)(s)
.map_err(|_| ParseCandidateError::BadFoundation)?;
let s = skip_spaces(s)?;
let (s, component_id): (_, usize) = map_res(
take_while_m_n::<_, _, nom::error::Error<_>>(1, 3, is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadComponentId)?;
let s = skip_spaces(s)?;
let (s, transport_type) = take_while1::<_, _, nom::error::Error<_>>(is_alphabetic)(s)
.map_err(|_| ParseCandidateError::BadTransportType)?;
let transport_type = TransportType::from_str(transport_type)?;
let s = skip_spaces(s)?;
let (s, priority) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadPriority)?;
let s = skip_spaces(s)?;
// FIXME: proper address parsing
let (s, connection_address) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_part_of_socket_addr),
|s: &str| s.parse(),
)(s)
.map_err(|_| ParseCandidateError::BadAddress)?;
let s = skip_spaces(s)?;
let (s, port) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_digit),
str::parse,
)(s)
.map_err(|_| ParseCandidateError::BadAddress)?;
let address = SocketAddr::new(connection_address, port);
let s = skip_spaces(s)?;
let (s, candidate_type) = map_res(
take_while1::<_, _, nom::error::Error<_>>(is_alphabetic),
CandidateType::from_str,
)(s)
.map_err(|_| ParseCandidateError::BadCandidateType)?;
let mut builder = Candidate::builder(
component_id,
candidate_type,
transport_type,
foundation,
address,
)
.priority(priority)
.base_address(address);
let mut iter_s = s;
let mut expected_next = None;
let mut raddr = None;
while !iter_s.is_empty() {
let s = skip_spaces(iter_s)?;
let (s, ext_key) = take_while1::<_, _, nom::error::Error<_>>(is_part_of_byte_string)(s)
.map_err(|_| ParseCandidateError::BadExtension)?;
let s = skip_spaces(s)?;
let (s, ext_value) =
take_while1::<_, _, nom::error::Error<_>>(is_part_of_byte_string)(s)
.map_err(|_| ParseCandidateError::BadExtension)?;
if let Some(expected_next) = expected_next {
if ext_key != expected_next {
return Err(ParseCandidateError::BadExtension);
}
if expected_next == "rport" {
let raddr = raddr.take().ok_or(ParseCandidateError::BadAddress)?;
let port =
str::parse(ext_value).map_err(|_| ParseCandidateError::BadAddress)?;
builder = builder.related_address(SocketAddr::new(raddr, port));
} else {
unreachable!();
}
} else {
match ext_key {
"raddr" => {
raddr = Some(
ext_value
.parse()
.map_err(|_| ParseCandidateError::BadAddress)?,
);
expected_next = Some("rport");
}
"tcptype" => {
let tcp_type = TcpType::from_str(ext_value)?;
builder = builder.tcp_type(tcp_type);
}
_ => builder = builder.extension(ext_key, ext_value),
}
}
iter_s = s;
}
if builder.ttype == TransportType::Tcp && builder.tcp_type == None {
return Err(ParseCandidateError::BadTransportType);
}
Ok(builder.build())
}