pub struct XorMappedAddress { /* private fields */ }
Expand description

The XorMappedAddress Attribute

Implementations§

Create a new XorMappedAddress Attribute

Examples
let addr = "127.0.0.1:1234".parse().unwrap();
let mapped_addr = XorMappedAddress::new(addr, 0x5678.into());
assert_eq!(mapped_addr.addr(0x5678.into()), addr);
Examples found in repository?
src/conncheck.rs (line 773)
767
768
769
770
771
772
773
774
775
776
777
fn binding_success_response(
    msg: &Message,
    from: SocketAddr,
    local_credentials: MessageIntegrityCredentials,
) -> Result<Message, AgentError> {
    let mut response = Message::new_success(msg);
    response.add_attribute(XorMappedAddress::new(from, msg.transaction_id()))?;
    response.add_message_integrity(&local_credentials)?;
    response.add_fingerprint()?;
    Ok(response)
}

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?
src/stun/attribute.rs (line 1009)
1007
1008
1009
1010
1011
1012
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self.addr {
            SocketAddr::V4(_) => write!(f, "{}: {:?}", self.get_type(), self.addr(0x0.into())),
            SocketAddr::V6(addr) => write!(f, "{}: XOR({:?})", self.get_type(), addr),
        }
    }
More examples
Hide additional 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§

Retrieve the AttributeType of an Attribute
Retrieve the length of an Attribute. This is not the padded length as stored in a Message
Convert an Attribute to a RawAttribute
Convert an Attribute from a RawAttribute
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more