Skip to content

Commit

Permalink
Remove url from DapRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
mendess committed Dec 6, 2023
1 parent 282398b commit 9ce6412
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 98 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions daphne/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,9 +1135,6 @@ pub struct DapRequest<S> {
/// Request payload.
pub payload: Vec<u8>,

/// Requst path (i.e., URL).
pub url: Url,

/// Sender authorization, e.g., a bearer token.
pub sender_auth: Option<S>,

Expand All @@ -1154,7 +1151,6 @@ impl<S> Default for DapRequest<S> {
task_id: Default::default(),
resource: Default::default(),
payload: Default::default(),
url: Url::parse("http://example.com").unwrap(),
sender_auth: Default::default(),
taskprov: Default::default(),
}
Expand Down Expand Up @@ -1196,12 +1192,6 @@ impl<S> DapRequest<S> {
))
}
}

/// Return the hostname of the request URL. The value is "unspecified-host" if the URL does not
/// indicate a hostname.
pub fn host(&self) -> &str {
self.url.host_str().unwrap_or("unspecified-host")
}
}

/// DAP response.
Expand Down
4 changes: 1 addition & 3 deletions daphne/src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,9 +1221,7 @@ pub fn encode_base64url<T: AsRef<[u8]>>(input: T) -> String {
}

/// Decode the input as a URL-safe, base64 encoding of an `OUT_LEN`-length byte string.
pub(crate) fn decode_base64url<T: AsRef<[u8]>, const OUT_LEN: usize>(
input: T,
) -> Option<[u8; OUT_LEN]> {
pub fn decode_base64url<T: AsRef<[u8]>, const OUT_LEN: usize>(input: T) -> Option<[u8; OUT_LEN]> {
let mut bytes = [0; OUT_LEN];
// NOTE(cjpatton) It would be better to use `decode_slice` here, but this function uses a
// conservative estimate of the decoded length (`decoded_len_estimate`). See
Expand Down
26 changes: 8 additions & 18 deletions daphne/src/roles/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use crate::{
error::DapAbort,
hpke::{HpkeConfig, HpkeDecrypter},
messages::{
decode_base64url, BatchId, BatchSelector, HpkeConfigList, PartialBatchSelector, ReportId,
TaskId, Time,
BatchId, BatchSelector, HpkeConfigList, PartialBatchSelector, ReportId, TaskId, Time,
},
metrics::{DaphneMetrics, DaphneRequestType},
vdaf::{EarlyReportStateConsumed, EarlyReportStateInitialized},
Expand Down Expand Up @@ -159,38 +158,29 @@ pub trait DapAggregator<S: Sync>: HpkeDecrypter + DapReportInitializer + Sized {

/// Access the audit log.
fn audit_log(&self) -> &dyn AuditLog;

/// Return the hostname of the request URL. The value is "unspecified-host" if the URL does not
/// indicate a hostname.
fn host(&self) -> &str;
}

/// Handle request for the Aggregator's HPKE configuration.
pub async fn handle_hpke_config_req<S, A>(
aggregator: &A,
req: &DapRequest<S>,
task_id: Option<TaskId>,
) -> Result<DapResponse, DapError>
where
S: Sync,
A: DapAggregator<S>,
{
let metrics = aggregator.metrics();

// Parse the task ID from the query string, ensuring that it is the only query parameter.
let mut id = None;
for (k, v) in req.url.query_pairs() {
if k != "task_id" {
return Err(DapAbort::BadRequest("unexpected query parameter".into()).into());
}

let bytes = decode_base64url(v.as_bytes()).ok_or(DapAbort::BadRequest(
"failed to parse query parameter as URL-safe Base64".into(),
))?;

id = Some(TaskId(bytes));
}

let hpke_config = aggregator
.get_hpke_config_for(req.version, id.as_ref())
.get_hpke_config_for(req.version, task_id.as_ref())
.await?;

if let Some(task_id) = id {
if let Some(task_id) = task_id {
let task_config = aggregator
.get_task_config_for(&task_id)
.await?
Expand Down
4 changes: 2 additions & 2 deletions daphne/src/roles/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub async fn handle_agg_job_init_req<'req, S: Sync, A: DapHelper<S>>(
};

aggregator.audit_log().on_aggregation_job(
req.host(),
aggregator.host(),
task_id,
task_config,
agg_job_init_req.prep_inits.len() as u64,
Expand Down Expand Up @@ -288,7 +288,7 @@ pub async fn handle_agg_job_cont_req<'req, S: Sync, A: DapHelper<S>>(
.try_into()
.expect("usize to fit in u64");
aggregator.audit_log().on_aggregation_job(
req.host(),
aggregator.host(),
task_id,
task_config,
out_shares_count,
Expand Down
9 changes: 4 additions & 5 deletions daphne/src/roles/leader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ async fn leader_send_http_request<S: Sync>(
media_type: req_media_type.clone(),
task_id: Some(*task_id),
resource,
url,
sender_auth: Some(
role.authorize(task_id, task_config, &req_media_type, &req_data)
.await?,
Expand All @@ -76,8 +75,8 @@ async fn leader_send_http_request<S: Sync>(
};

let resp = match method {
LeaderHttpRequestMethod::Put => role.send_http_put(req).await?,
LeaderHttpRequestMethod::Post => role.send_http_post(req).await?,
LeaderHttpRequestMethod::Put => role.send_http_put(req, url).await?,
LeaderHttpRequestMethod::Post => role.send_http_post(req, url).await?,
};

check_response_content_type(&resp, resp_media_type)?;
Expand Down Expand Up @@ -147,10 +146,10 @@ pub trait DapLeader<S: Sync>: DapAuthorizedSender<S> + DapAggregator<S> {
) -> Result<(), DapError>;

/// Send an HTTP POST request.
async fn send_http_post(&self, req: DapRequest<S>) -> Result<DapResponse, DapError>;
async fn send_http_post(&self, req: DapRequest<S>, url: Url) -> Result<DapResponse, DapError>;

/// Send an HTTP PUT request.
async fn send_http_put(&self, req: DapRequest<S>) -> Result<DapResponse, DapError>;
async fn send_http_put(&self, req: DapRequest<S>, url: Url) -> Result<DapResponse, DapError>;
}

/// Handle a report from a Client.
Expand Down
Loading

0 comments on commit 9ce6412

Please sign in to comment.