Skip to content

Commit

Permalink
feat: public encoding path, better version control, client user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
sstelfox committed Feb 18, 2024
1 parent 0d506b7 commit b42d3a4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/api/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,13 @@ impl ApiClient {

fn default_reqwest_client() -> Result<RClient, ApiClientError> {
let mut default_headers = HeaderMap::new();

default_headers.insert("Content-Type", HeaderValue::from_static("application/json"));

let user_agent = format!("banyanfs/{}", crate::version::version());
default_headers.insert(
"User-Agent",
HeaderValue::from_str(&user_agent).expect("valid user agent version"),
);
let user_agent = format!("banyanfs/{}", crate::version::minimal_version());

let client = RClient::builder()
.default_headers(default_headers)
.user_agent(user_agent)
.build()?;

Ok(client)
Expand Down
17 changes: 16 additions & 1 deletion src/filesystem/drive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use crate::filesystem::nodes::{Node, NodeBuilder, NodeBuilderError, NodeId};
pub struct Drive {
current_key: Arc<SigningKey>,
filesystem_id: FilesystemId,
private: bool,

// todo: need to switch to a mutex, can't have state being modified during an encoding session
// and the cooperative multitasking model of async/await means we can't guarantee that some
// other task isn't going to tweak it
Expand All @@ -44,7 +46,19 @@ pub(crate) struct InnerDrive {
}

impl Drive {
pub async fn encode_private<W: AsyncWrite + Unpin + Send>(
pub async fn encode<W: AsyncWrite + Unpin + Send>(
&self,
rng: &mut impl CryptoRngCore,
writer: &mut W,
) -> std::io::Result<usize> {
if self.private {
self.encode_private(rng, writer).await
} else {
unimplemented!("public encoding not implemented")
}
}

async fn encode_private<W: AsyncWrite + Unpin + Send>(
&self,
rng: &mut impl CryptoRngCore,
writer: &mut W,
Expand Down Expand Up @@ -115,6 +129,7 @@ impl Drive {
let drive = Self {
current_key,
filesystem_id,
private: true,

inner: Arc::new(RwLock::new(InnerDrive {
access,
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn main() -> BanyanFsResult<()> {
.with_filter(env_filter);

tracing_subscriber::registry().with(stderr_layer).init();
debug!("running banyanfs {}", version());
debug!("running banyanfs {}", full_version());

let mut rng = banyanfs::utils::crypto_rng();

Expand Down Expand Up @@ -114,7 +114,7 @@ async fn main() -> BanyanFsResult<()> {
}
};

if let Err(err) = drive.encode_private(&mut rng, &mut fh).await {
if let Err(err) = drive.encode(&mut rng, &mut fh).await {
tracing::error!("failed to encode drive to file: {err}");
return Ok(());
}
Expand Down
6 changes: 5 additions & 1 deletion src/version.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub fn version() -> String {
pub fn full_version() -> String {
format!(
"build-profile={} build-timestamp={} features={} repo-version={}",
env!("BUILD_PROFILE"),
Expand All @@ -7,3 +7,7 @@ pub fn version() -> String {
env!("REPO_VERSION"),
)
}

pub fn minimal_version() -> String {
format!("repo-version={}", env!("REPO_VERSION"),)
}
9 changes: 7 additions & 2 deletions src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ pub(crate) mod tomb_compat;
#[cfg(feature = "tomb-compat")]
pub use tomb_compat::*;

use crate::version::version;
use crate::version::full_version;

use tracing::info;

// Pending needed improvements for the WASM components:
//
Expand All @@ -32,7 +34,10 @@ pub fn wasm_init() -> Result<(), JsValue> {
.build();

tracing_wasm::set_as_global_default_with_config(wasm_log_config);
tracing::info!("successfully loaded banyanfs WASM module {}", version());
info!(
"successfully loaded banyanfs WASM module {}",
full_version()
);

Ok(())
}
Expand Down

0 comments on commit b42d3a4

Please sign in to comment.