pub fn validate(&self) -> Result<(), RequestError> {
        match self {
            Request::Sync(peer_requests) => {
                // make sure peer request lists is neither too long nor too short
                if peer_requests.is_empty() {
                    return Err(RequestError::PeerRequestListTooShort);
                }
                if peer_requests.len() > MAX_NUM_SYNC_PEERS {
                    return Err(RequestError::PeerRequestListTooLong(peer_requests.len()));
                }
                // TODO: use non-cryptographic hashing
                let mut unique_objects = HashSet::new();
                for peer_request in peer_requests.iter() {
                    peer_request.validate()?;
                    let incoming_objects = peer_request.incoming_objects();
                    // if a duplicate ID is found, return an error
                    for oid in incoming_objects {
                        if !unique_objects.insert(oid) {
                            return Err(RequestError::DuplicateObjectIds);
                        }
                    }
                }
            }
            Request::Take(object_ids) | Request::Copy(object_ids) => {
                // make sure object ID list is neither too long nor too short
                if object_ids.is_empty() {
                    return Err(RequestError::ObjectIdListTooShort);
                }
                if object_ids.len() > MAX_OBJECT_ID_LIST_LEN {
                    return Err(RequestError::ObjectIdListTooLong(object_ids.len()));
                }
                // if a duplicate ID is found, return an error
                // TODO: use non-cryptographic hashing
                let mut unique_objects = HashSet::new();
                for oid in object_ids {
                    if !unique_objects.insert(oid) {
                        return Err(RequestError::DuplicateObjectIds);
                    }
                }
            }
        }
        Ok(())
    }
/// Checks if this request is valid. Specifically, makes sure:
/// * There are no duplicated object IDs present in the request.
/// * Number of objects in a single request does not exceed the allowed limit.
Checks if this request is valid. Specifically, makes sure:
There are no duplicated object IDs present in the request.
Number of objects in a single request does not exceed the allowed limit.
Checks if this request is valid . Specifically makes sure : There are no duplicated object IDs present in the request . Number of objects in a single request does not exceed the allowed limit .
pub fn validate(&self) -> Result<(), RequestError> {
        match self {
            Request::Sync(peer_requests) => {
                // make sure peer request lists is neither too long nor too short
                if peer_requests.is_empty() {
                    return Err(RequestError::PeerRequestListTooShort);
                }
                if peer_requests.len() > MAX_NUM_SYNC_PEERS {
                    return Err(RequestError::PeerRequestListTooLong(peer_requests.len()));
                }
                // TODO: use non-cryptographic hashing
                let mut unique_objects = HashSet::new();
                for peer_request in peer_requests.iter() {
                    peer_request.validate()?;
                    let incoming_objects = peer_request.incoming_objects();
                    // if a duplicate ID is found, return an error
                    for oid in incoming_objects {
                        if !unique_objects.insert(oid) {
                            return Err(RequestError::DuplicateObjectIds);
                        }
                    }
                }
            }
            Request::Take(object_ids) | Request::Copy(object_ids) => {
                // make sure object ID list is neither too long nor too short
                if object_ids.is_empty() {
                    return Err(RequestError::ObjectIdListTooShort);
                }
                if object_ids.len() > MAX_OBJECT_ID_LIST_LEN {
                    return Err(RequestError::ObjectIdListTooLong(object_ids.len()));
                }
                // if a duplicate ID is found, return an error
                // TODO: use non-cryptographic hashing
                let mut unique_objects = HashSet::new();
                for oid in object_ids {
                    if !unique_objects.insert(oid) {
                        return Err(RequestError::DuplicateObjectIds);
                    }
                }
            }
        }
        Ok(())
    }
pub fn validate ( & self ) -> Result < ( ) , RequestError > { match self { Request :: Sync ( peer_requests ) => { // make sure peer request lists is neither too long nor too short if peer_requests . is_empty ( ) { return Err ( RequestError :: PeerRequestListTooShort ) ; } if peer_requests . len ( ) > MAX_NUM_SYNC_PEERS { return Err ( RequestError :: PeerRequestListTooLong ( peer_requests . len ( ) ) ) ; } // TODO: use non-cryptographic hashing let mut unique_objects = HashSet :: new ( ) ; for peer_request in peer_requests . iter ( ) { peer_request . validate ( ) ? ; let incoming_objects = peer_request . incoming_objects ( ) ; // if a duplicate ID is found, return an error for oid in incoming_objects { if ! unique_objects . insert ( oid ) { return Err ( RequestError :: DuplicateObjectIds ) ; } } } } Request :: Take ( object_ids ) | Request :: Copy ( object_ids ) => { // make sure object ID list is neither too long nor too short if object_ids . is_empty ( ) { return Err ( RequestError :: ObjectIdListTooShort ) ; } if object_ids . len ( ) > MAX_OBJECT_ID_LIST_LEN { return Err ( RequestError :: ObjectIdListTooLong ( object_ids . len ( ) ) ) ; } // if a duplicate ID is found, return an error // TODO: use non-cryptographic hashing let mut unique_objects = HashSet :: new ( ) ; for oid in object_ids { if ! unique_objects . insert ( oid ) { return Err ( RequestError :: DuplicateObjectIds ) ; } } } } Ok ( ( ) ) }
Checks if this request is valid.
Checks if this request is valid .
&self
&self