Complete milestone 09 world integration gate (#75)
This commit is contained in:
1 parent
55424dbd7f
commit
fdda05b53f
18 files changed
+767
-82
No files matched your search
@@ -11,6 +11,7 @@ use libremetaverse_types::compat::{CancellationToken, HttpResponse, Uri};
|
||||
use libremetaverse_types::{AssetType, UUID};
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
const MAX_FOLDER_DEPTH_REQUEST: i32 = 50;
|
||||
const MAX_AIS_OBJECTS: usize = 100_000;
|
||||
@@ -110,6 +111,31 @@ impl InventoryAISClient {
|
||||
caps.capability_uri(name.to_owned())
|
||||
}
|
||||
|
||||
fn wait_for_capability(
|
||||
&self,
|
||||
name: &str,
|
||||
cancellation: &CancellationToken,
|
||||
) -> Result<Option<Uri>, Error> {
|
||||
let client = self.client()?;
|
||||
let Some(simulator) = client.native_network()?.current_sim() else {
|
||||
return Ok(None);
|
||||
};
|
||||
let Some(caps) = simulator.native_caps() else {
|
||||
return Ok(None);
|
||||
};
|
||||
let deadline = Instant::now() + Duration::from_secs(2);
|
||||
loop {
|
||||
cancellation.throw_if_cancellation_requested()?;
|
||||
if let Some(uri) = caps.capability_uri(name.to_owned())? {
|
||||
return Ok(Some(uri));
|
||||
}
|
||||
if caps.seed_request_finished() || Instant::now() >= deadline {
|
||||
return Ok(None);
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(1));
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn native_is_available(&self) -> bool {
|
||||
self.capability(Self::INVENTORY_CAP_NAME)
|
||||
.ok()
|
||||
@@ -147,7 +173,7 @@ impl InventoryAISClient {
|
||||
) -> Result<Option<(HttpResponse, Vec<u8>)>, Error> {
|
||||
let token = Self::token(cancellation_token);
|
||||
token.throw_if_cancellation_requested()?;
|
||||
let Some(capability) = self.capability(cap_name)? else {
|
||||
let Some(capability) = self.wait_for_capability(cap_name, &token)? else {
|
||||
return Ok(None);
|
||||
};
|
||||
let bytes = match payload {
|
||||
@@ -359,18 +385,27 @@ impl InventoryAISClient {
|
||||
new_inventory: OSD,
|
||||
cancellation_token: Option<CancellationToken>,
|
||||
) -> Result<Vec<InventoryItem>, Error> {
|
||||
let path = format!("category/{parent_uuid}?tid={}", Self::tid()?);
|
||||
let (_, _, _, links) = self
|
||||
.mutation(
|
||||
let Some((response, bytes)) = self
|
||||
.request(
|
||||
Self::INVENTORY_CAP_NAME,
|
||||
"POST",
|
||||
path,
|
||||
format!("category/{parent_uuid}"),
|
||||
BTreeMap::new(),
|
||||
Some(new_inventory),
|
||||
false,
|
||||
cancellation_token,
|
||||
)
|
||||
.await?;
|
||||
.await?
|
||||
else {
|
||||
return Ok(Vec::new());
|
||||
};
|
||||
if !Self::status_ok(&response) {
|
||||
return Err(Error::HttpRequest);
|
||||
}
|
||||
let Some(map) = Self::decode_map(bytes)? else {
|
||||
return Ok(Vec::new());
|
||||
};
|
||||
let (folders, items, links) = self.parse_all_map(&map)?;
|
||||
self.reconcile(&map, &folders, &items, &links)?;
|
||||
Ok(links)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user