Skip to content

Commit

Permalink
feat: add more debug logs to client API
Browse files Browse the repository at this point in the history
  • Loading branch information
ermineJose committed Dec 5, 2024
1 parent 58e940e commit 409127c
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 18 deletions.
15 changes: 12 additions & 3 deletions autonomi/src/client/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,18 @@ impl Archive {
.as_secs();
meta.modified = now;
self.map.insert(new_path.to_path_buf(), (data_addr, meta));
debug!(
"Renamed file successfully in the archive, old path: {:?} new_path: {:?}",
old_path, new_path
);
Ok(())
}

/// Add a file to a local archive
/// Note that this does not upload the archive to the network
pub fn add_file(&mut self, path: PathBuf, data_addr: DataAddr, meta: Metadata) {
self.map.insert(path, (data_addr, meta));
self.map.insert(path.clone(), (data_addr, meta));
debug!("Added a new file to the archive, path: {:?}", path);
}

/// List all files in the archive
Expand Down Expand Up @@ -160,14 +165,18 @@ impl Client {
let bytes = archive
.into_bytes()
.map_err(|e| PutError::Serialization(format!("Failed to serialize archive: {e:?}")))?;
self.data_put(bytes, wallet.into()).await
let result = self.data_put(bytes, wallet.into()).await;
debug!("Uploaded archive {archive:?} to the network and the address is {result:?}");
result
}

/// Get the cost to upload an archive
pub async fn archive_cost(&self, archive: Archive) -> Result<AttoTokens, CostError> {
let bytes = archive
.into_bytes()
.map_err(|e| CostError::Serialization(format!("Failed to serialize archive: {e:?}")))?;
self.data_cost(bytes).await
let result = self.data_cost(bytes).await;
debug!("Calculated the cost to upload archive {archive:?} is {result:?}");
result
}
}
14 changes: 12 additions & 2 deletions autonomi/src/client/archive_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,18 @@ impl PrivateArchive {
.as_secs();
meta.modified = now;
self.map.insert(new_path.to_path_buf(), (data_addr, meta));
debug!(
"Renamed file successfully in the private archive, old path: {:?} new_path: {:?}",
old_path, new_path
);
Ok(())
}

/// Add a file to a local archive
/// Note that this does not upload the archive to the network
pub fn add_file(&mut self, path: PathBuf, data_map: PrivateDataAccess, meta: Metadata) {
self.map.insert(path, (data_map, meta));
self.map.insert(path.clone(), (data_map, meta));
debug!("Added a new file to the archive, path: {:?}", path);
}

/// List all files in the archive
Expand Down Expand Up @@ -129,6 +134,11 @@ impl Client {
let bytes = archive
.into_bytes()
.map_err(|e| PutError::Serialization(format!("Failed to serialize archive: {e:?}")))?;
self.private_data_put(bytes, payment_option).await
let result = self.private_data_put(bytes, payment_option).await;
debug!(
"Uploaded private archive {:?} to the network and address is {:?}",
archive, result
);
result
}
}
8 changes: 7 additions & 1 deletion autonomi/src/client/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl Client {
.fetch_from_data_map_chunk(data_map_chunk.value())
.await?;

debug!("Successfully fetched a blob of data from the network");
Ok(data)
}

Expand Down Expand Up @@ -214,7 +215,7 @@ impl Client {
info!("Getting chunk: {addr:?}");

let key = NetworkAddress::from_chunk_address(ChunkAddress::new(addr)).to_record_key();

debug!("Fetching chunk from network at: {key:?}");
let get_cfg = GetRecordCfg {
get_quorum: Quorum::One,
retry_strategy: None,
Expand All @@ -234,6 +235,10 @@ impl Client {
let chunk: Chunk = try_deserialize_record(&record)?;
Ok(chunk)
} else {
error!(
"Record kind mismatch: expected Chunk, got {:?}",
header.kind
);
Err(NetworkError::RecordKindMismatch(RecordKind::Chunk).into())
}
}
Expand Down Expand Up @@ -267,6 +272,7 @@ impl Client {
.map(|quote| quote.2.cost.as_atto())
.sum::<Amount>(),
);
debug!("Total cost calculated: {:?}", total_cost);
Ok(total_cost)
}

Expand Down
1 change: 1 addition & 0 deletions autonomi/src/client/data_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl Client {
);
let data = self.fetch_from_data_map_chunk(data_map.0.value()).await?;

debug!("Successfully fetched a blob of private data from the network");
Ok(data)
}

Expand Down
4 changes: 4 additions & 0 deletions autonomi/src/client/external_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ impl Client {
let (quote_payments, free_chunks) = extract_quote_payments(&cost_map);
let quotes = cost_map_to_quotes(cost_map);

debug!(
"Got the quotes , quote_payments and freechunks from the network {:?}",
(quotes.clone(), quote_payments.clone(), free_chunks.clone())
);
Ok((quotes, quote_payments, free_chunks))
}
}
Expand Down
15 changes: 13 additions & 2 deletions autonomi/src/client/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ impl Client {
let data = self.data_get(data_addr).await?;
if let Some(parent) = to_dest.parent() {
tokio::fs::create_dir_all(parent).await?;
debug!("Created parent directories {parent:?} for {to_dest:?}");
}
tokio::fs::write(to_dest, data).await?;
tokio::fs::write(to_dest.clone(), data).await?;
debug!("Downloaded file to {to_dest:?} from the network address {data_addr:?}");
Ok(())
}

Expand All @@ -101,9 +103,15 @@ impl Client {
to_dest: PathBuf,
) -> Result<(), DownloadError> {
let archive = self.archive_get(archive_addr).await?;
debug!("Downloaded archive for the directory from the network at {archive_addr:?}");
for (path, addr, _meta) in archive.iter() {
self.file_download(*addr, to_dest.join(path)).await?;
}
debug!(
"All files in the directory downloaded to {:?} from the network address {:?}",
to_dest.parent(),
archive_addr
);
Ok(())
}

Expand Down Expand Up @@ -159,6 +167,7 @@ impl Client {
info!("Complete archive upload completed in {:?}", start.elapsed());
#[cfg(feature = "loud")]
println!("Upload completed in {:?}", start.elapsed());
debug!("Directory uploaded to the network at {arch_addr:?}");
Ok(arch_addr)
}

Expand All @@ -173,9 +182,10 @@ impl Client {
#[cfg(feature = "loud")]
println!("Uploading file: {path:?}");

let data = tokio::fs::read(path).await?;
let data = tokio::fs::read(path.clone()).await?;
let data = Bytes::from(data);
let addr = self.data_put(data, wallet.into()).await?;
debug!("File {path:?} uploaded to the network at {addr:?}");
Ok(addr)
}

Expand Down Expand Up @@ -217,6 +227,7 @@ impl Client {
let archive_cost = self.data_cost(Bytes::from(root_serialized)).await?;

total_cost += archive_cost.as_atto();
debug!("Total cost for the directory: {total_cost:?}");
Ok(total_cost.into())
}
}
Expand Down
9 changes: 8 additions & 1 deletion autonomi/src/client/fs_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ impl Client {
let data = self.private_data_get(data_access).await?;
if let Some(parent) = to_dest.parent() {
tokio::fs::create_dir_all(parent).await?;
debug!("Created parent directories for {to_dest:?}");
}
tokio::fs::write(to_dest, data).await?;
tokio::fs::write(to_dest.clone(), data).await?;
debug!("Downloaded file to {to_dest:?}");
Ok(())
}

Expand All @@ -52,6 +54,7 @@ impl Client {
self.private_file_download(addr.clone(), to_dest.join(path))
.await?;
}
debug!("Downloaded directory to {to_dest:?}");
Ok(())
}

Expand Down Expand Up @@ -129,6 +132,10 @@ impl Client {
let data = tokio::fs::read(path).await?;
let data = Bytes::from(data);
let addr = self.private_data_put(data, wallet.into()).await?;
debug!(
"Uploaded file successfully in the privateAchive: {:?}",
addr
);
Ok(addr)
}
}
4 changes: 4 additions & 0 deletions autonomi/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl Client {
ant_networking::target_arch::spawn(handle_event_receiver(event_receiver, sender));

receiver.await.expect("sender should not close")?;
debug!("Client is connected to the network");

Ok(Self {
network,
Expand All @@ -127,6 +128,8 @@ impl Client {
let (client_event_sender, client_event_receiver) =
tokio::sync::mpsc::channel(CLIENT_EVENT_CHANNEL_SIZE);
self.client_event_sender = Arc::new(Some(client_event_sender));
debug!("All events to the clients are enabled");

client_event_receiver
}
}
Expand All @@ -140,6 +143,7 @@ fn build_client_and_run_swarm(local: bool) -> (Network, mpsc::Receiver<NetworkEv
network_builder.build_client().expect("mdns to succeed");

let _swarm_driver = ant_networking::target_arch::spawn(swarm_driver.run());
debug!("Client swarm driver is running");

(network, event_receiver)
}
Expand Down
4 changes: 4 additions & 0 deletions autonomi/src/client/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ impl Client {
match payment_option {
PaymentOption::Wallet(wallet) => {
let (receipt, _) = self.pay(content_addrs, &wallet).await?;
debug!(
"Paid for content addresses with wallet and the receipt is {:?}",
receipt
);
Ok(receipt)
}
PaymentOption::Receipt(receipt) => Ok(receipt),
Expand Down
20 changes: 15 additions & 5 deletions autonomi/src/client/registers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ impl Register {
if let Some(value) = initial_value {
register.write_atop(&value, &owner)?;
}

debug!(
"Created register {:?} with address: {:?}",
register,
register.address()
);
Ok(register)
}

Expand Down Expand Up @@ -166,10 +170,12 @@ impl Client {
}
}

Ok(Register {
let register = Register {
signed_reg,
crdt_reg,
})
};
debug!("Fetched register {register:?} from the address: {address} in the network");
Ok(register)
}

/// Updates a Register on the network with a new value. This will overwrite existing value(s).
Expand Down Expand Up @@ -217,7 +223,11 @@ impl Client {
register.address()
)
})?;

debug!(
"Updated register {:?} with new value {:?}",
register.address(),
new_value
);
Ok(())
}

Expand All @@ -244,7 +254,7 @@ impl Client {
.map(|quote| quote.2.cost.as_atto())
.sum::<Amount>(),
);

debug!("Calculated the cost to create register with name: {name} is {total_cost}");
Ok(total_cost)
}

Expand Down
12 changes: 9 additions & 3 deletions autonomi/src/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ use crate::self_encryption::DataMapLevel;
impl Client {
/// Fetch and decrypt all chunks in the data map.
pub(crate) async fn fetch_from_data_map(&self, data_map: &DataMap) -> Result<Bytes, GetError> {
debug!(
"Fetching encrypted data chunks from data map {:?}",
data_map
);
let mut download_tasks = vec![];
for info in data_map.infos() {
download_tasks.push(async move {
Expand All @@ -53,7 +57,7 @@ impl Client {
}
});
}

debug!("Successfully fetched all the encrypted chunks");
let encrypted_chunks =
process_tasks_with_max_concurrency(download_tasks, *CHUNK_DOWNLOAD_BATCH_SIZE)
.await
Expand All @@ -64,7 +68,7 @@ impl Client {
error!("Error decrypting encrypted_chunks: {e:?}");
GetError::Decryption(crate::self_encryption::Error::SelfEncryption(e))
})?;

debug!("Successfully decrypted all the chunks");
Ok(data)
}

Expand Down Expand Up @@ -153,7 +157,9 @@ impl Client {
use_put_record_to: Some(vec![storing_node]),
verification,
};
Ok(self.network.put_record(record, &put_cfg).await?)
let payment_upload = Ok(self.network.put_record(record, &put_cfg).await?);
debug!("Successfully stored chunk: {chunk:?} to {:?}", storing_node);
payment_upload
}

/// Pay for the chunks and get the proof of payment.
Expand Down
3 changes: 2 additions & 1 deletion autonomi/src/client/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ impl Client {
&self,
secret_key: &VaultSecretKey,
) -> Result<(Bytes, VaultContentType), VaultError> {
info!("Fetching and decrypting vault");
info!("Fetching and decrypting vault...");
let pad = self.get_vault_from_network(secret_key).await?;

let data = pad.decrypt_data(secret_key)?;
debug!("vault data is successfully fetched and decrypted");
Ok((data, pad.data_encoding()))
}

Expand Down

0 comments on commit 409127c

Please sign in to comment.