Struct librice::stun::attribute::XorMappedAddress
source · pub struct XorMappedAddress { /* private fields */ }
Expand description
The XorMappedAddress Attribute
Implementations§
source§impl XorMappedAddress
impl XorMappedAddress
sourcepub fn new(addr: SocketAddr, transaction: TransactionId) -> Self
pub fn new(addr: SocketAddr, transaction: TransactionId) -> Self
sourcepub fn addr(&self, transaction: TransactionId) -> SocketAddr
pub fn addr(&self, transaction: TransactionId) -> SocketAddr
Retrieve the address stored in a XorMappedAddress
Examples
let addr = "[::1]:1234".parse().unwrap();
let mapped_addr = XorMappedAddress::new(addr, 0x5678.into());
assert_eq!(mapped_addr.addr(0x5678.into()), addr);
Examples found in repository?
More examples
src/gathering.rs (line 96)
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
async fn gather_stun_xor_address(
local_preference: u8,
agent: StunAgent,
transport: TransportType,
stun_server: SocketAddr,
) -> Result<GatherCandidateAddress, StunError> {
let msg = generate_bind_request()?;
agent
.stun_request_transaction(&msg, stun_server)?
.build()?
.perform()
.await
.and_then(move |(response, from)| {
if let Some(attr) = response.attribute::<XorMappedAddress>(XOR_MAPPED_ADDRESS) {
debug!(
"got external address {:?}",
attr.addr(response.transaction_id())
);
return Ok(GatherCandidateAddress {
ctype: CandidateType::ServerReflexive,
local_preference,
transport,
address: attr.addr(response.transaction_id()),
base: from,
related: Some(stun_server),
});
}
Err(StunError::Failed)
})
}
src/conncheck.rs (line 232)
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
async fn do_stun_request(
conncheck: Arc<ConnCheck>,
stun_request: StunRequest,
) -> Result<ConnCheckResponse, AgentError> {
// send binding request
// wait for response
// if timeout -> resend?
// if longer timeout -> fail
// TODO: optional: if icmp error -> fail
let (response, from) = match stun_request.perform().await {
Err(e) => {
warn!("connectivity check produced error: {:?}", e);
return Ok(ConnCheckResponse::Failure(conncheck));
}
Ok(v) => v,
};
trace!("have response: {}", response);
if !response.is_response() {
// response is not a response!
return Ok(ConnCheckResponse::Failure(conncheck));
}
// if response error -> fail TODO: might be a recoverable error!
if response.has_class(MessageClass::Error) {
warn!("error response {}", response);
if let Some(err) = response.attribute::<ErrorCode>(ERROR_CODE) {
if err.code() == ErrorCode::ROLE_CONFLICT {
info!("Role conflict received {}", response);
return Ok(ConnCheckResponse::RoleConflict(
conncheck,
stun_request.request().has_attribute(ICE_CONTROLLED),
));
}
}
// FIXME: some failures are recoverable
return Ok(ConnCheckResponse::Failure(conncheck));
}
// if response success:
// if mismatched address -> fail
if from != stun_request.peer_address() {
warn!(
"response came from different ip {:?} than candidate {:?}",
from,
stun_request.peer_address()
);
return Ok(ConnCheckResponse::Failure(conncheck));
}
if let Some(xor) = response.attribute::<XorMappedAddress>(XOR_MAPPED_ADDRESS) {
let xor_addr = xor.addr(response.transaction_id());
// TODO: if response mapped address not in remote candidate list -> new peer-reflexive candidate
// TODO glare
return Ok(ConnCheckResponse::Success(conncheck, xor_addr));
}
Ok(ConnCheckResponse::Failure(conncheck))
}
Trait Implementations§
source§impl Attribute for XorMappedAddress
impl Attribute for XorMappedAddress
source§fn get_type(&self) -> AttributeType
fn get_type(&self) -> AttributeType
Retrieve the
AttributeType
of an Attribute
source§fn length(&self) -> u16
fn length(&self) -> u16
Retrieve the length of an
Attribute
. This is not the padded length as stored in a
Message
source§fn to_raw(&self) -> RawAttribute
fn to_raw(&self) -> RawAttribute
Convert an
Attribute
to a RawAttribute
source§fn from_raw(raw: &RawAttribute) -> Result<Self, StunParseError>
fn from_raw(raw: &RawAttribute) -> Result<Self, StunParseError>
Convert an
Attribute
from a RawAttribute
source§impl Clone for XorMappedAddress
impl Clone for XorMappedAddress
source§fn clone(&self) -> XorMappedAddress
fn clone(&self) -> XorMappedAddress
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for XorMappedAddress
impl Debug for XorMappedAddress
source§impl Display for XorMappedAddress
impl Display for XorMappedAddress
source§impl From<XorMappedAddress> for RawAttribute
impl From<XorMappedAddress> for RawAttribute
source§fn from(f: XorMappedAddress) -> Self
fn from(f: XorMappedAddress) -> Self
Converts to this type from the input type.
source§impl TryFrom<&RawAttribute> for XorMappedAddress
impl TryFrom<&RawAttribute> for XorMappedAddress
§type Error = StunParseError
type Error = StunParseError
The type returned in the event of a conversion error.