Skip to content

Commit

Permalink
fix: use their_max_payload_size
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed Aug 12, 2024
1 parent 8a104f1 commit f43e0b4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
12 changes: 6 additions & 6 deletions iroh-willow/src/session/challenge.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{Error, Role};
use crate::proto::{
keys::{UserPublicKey, UserSecretKey, UserSignature},
keys::{UserPublicKey, UserSignature},
wgps::challenge::{AccessChallenge, AccessChallengeBytes, ChallengeHash},
};

Expand Down Expand Up @@ -57,11 +57,11 @@ impl ChallengeState {
matches!(self, Self::Revealed { .. })
}

pub fn sign(&self, secret_key: &UserSecretKey) -> Result<UserSignature, Error> {
let signable = self.signable()?;
let signature = secret_key.sign(&signable);
Ok(signature)
}
// pub fn sign(&self, secret_key: &UserSecretKey) -> Result<UserSignature, Error> {
// let signable = self.signable()?;
// let signature = secret_key.sign(&signable);
// Ok(signature)
// }

pub fn signable(&self) -> Result<[u8; 32], Error> {
let challenge = self.get_ours()?;
Expand Down
6 changes: 6 additions & 0 deletions iroh-willow/src/session/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ use super::Error;

pub const DEFAULT_CHUNK_SIZE: usize = 1024 * 64;

/// Send a payload in chunks.
///
/// Returns `true` if the payload was sent.
/// Returns `false` if blob is not found in `payload_store`.
/// Returns an error if the store or sending on the `senders` return an error.
// TODO: Include outboards.
pub async fn send_payload_chunked<P: PayloadStore>(
digest: PayloadDigest,
payload_store: &P,
Expand Down
22 changes: 11 additions & 11 deletions iroh-willow/src/session/reconciler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
session::{
aoi_finder::AoiIntersection,
channels::{ChannelSenders, MessageReceiver},
payload::{send_payload_chunked, CurrentPayload},
payload::{send_payload_chunked, CurrentPayload, DEFAULT_CHUNK_SIZE},
static_tokens::StaticTokens,
Error, Role, SessionId,
},
Expand Down Expand Up @@ -73,6 +73,7 @@ impl<S: Storage> Reconciler<S> {
session_id: SessionId,
send: ChannelSenders,
our_role: Role,
max_eager_payload_size: u64,
) -> impl futures_lite::Stream<Item = Result<Output, Error>> {
GenStream::new(|co| {
let shared = Shared {
Expand All @@ -82,6 +83,7 @@ impl<S: Storage> Reconciler<S> {
send,
static_tokens,
session_id,
max_eager_payload_size,
};
Self {
shared,
Expand Down Expand Up @@ -366,6 +368,7 @@ struct Shared<S: Storage> {
send: ChannelSenders,
static_tokens: StaticTokens,
session_id: SessionId,
max_eager_payload_size: u64,
}

#[derive(Debug)]
Expand Down Expand Up @@ -563,7 +566,8 @@ impl<S: Storage> Target<S> {
let static_token = token.capability.into();
let dynamic_token = token.signature;
// TODO: partial payloads
let available = entry.payload_length();
let payload_len = entry.payload_length();
let available = payload_len;
let static_token_handle = shared
.static_tokens
.bind_and_send_ours(static_token, &shared.send)
Expand All @@ -577,21 +581,17 @@ impl<S: Storage> Target<S> {
shared.send.send(msg).await?;

// TODO: only send payload if configured to do so and/or under size limit.
let send_payloads = true;
let chunk_size = 1024 * 64;
if send_payloads
&& send_payload_chunked(
if payload_len <= shared.max_eager_payload_size {
send_payload_chunked(
digest,
shared.store.payloads(),
&shared.send,
chunk_size,
DEFAULT_CHUNK_SIZE,
|bytes| ReconciliationSendPayload { bytes }.into(),
)
.await?
{
let msg = ReconciliationTerminatePayload;
shared.send.send(msg).await?;
.await?;
}
shared.send.send(ReconciliationTerminatePayload).await?;
}
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions iroh-willow/src/session/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ pub(crate) async fn run_session<S: Storage>(
session_id,
channel_sender.clone(),
our_role,
initial_transmission.their_max_payload_size,
);
while let Some(output) = gen.try_next().await? {
match output {
Expand Down

0 comments on commit f43e0b4

Please sign in to comment.