diff --git a/crates/tor-dirclient/semver.md b/crates/tor-dirclient/semver.md new file mode 100644 index 000000000..42d5de6b1 --- /dev/null +++ b/crates/tor-dirclient/semver.md @@ -0,0 +1 @@ +BREAKING: `download()` is renamed to `send_request()` diff --git a/crates/tor-dirclient/src/lib.rs b/crates/tor-dirclient/src/lib.rs index f094c63e4..714ce9df8 100644 --- a/crates/tor-dirclient/src/lib.rs +++ b/crates/tor-dirclient/src/lib.rs @@ -79,7 +79,7 @@ pub type RequestResult = std::result::Result; /// constructed using `dirinfo`. /// /// For more fine-grained control over the circuit and stream used, -/// construct them yourself, and then call [`download`] instead. +/// construct them yourself, and then call [`send_request`] instead. /// /// # TODO /// @@ -122,7 +122,7 @@ where // TODO: Perhaps we want separate timeouts for each phase of this. // For now, we just use higher-level timeouts in `dirmgr`. - let r = download(runtime, req, &mut stream, Some(source.clone())).await; + let r = send_request(runtime, req, &mut stream, Some(source.clone())).await; if should_retire_circ(&r) { retire_circ(&circ_mgr, &source, "Partial response"); @@ -140,7 +140,7 @@ fn should_retire_circ(result: &Result) -> bool { } } -/// Fetch a Tor directory object from a provided stream. +/// Fetch or upload a Tor directory object using the provided stream. /// /// To do this, we send a simple HTTP/1.0 request for the described /// object in `req` over `stream`, and then wait for a response. In @@ -158,7 +158,7 @@ fn should_retire_circ(result: &Result) -> bool { /// The only error variant returned is [`Error::RequestFailed`]. // TODO: should the error return type change to `RequestFailedError`? // If so, that would simplify some code in_dirmgr::bridgedesc. -pub async fn download( +pub async fn send_request( runtime: &SP, req: &R, stream: &mut S, @@ -660,7 +660,7 @@ mod test { ) = futures::join!( async { // Run the download function. - let r = download(&rt, &req, &mut s1, None).await; + let r = send_request(&rt, &req, &mut s1, None).await; s1.close().await.map_err(|error| { Error::RequestFailed(RequestFailedError { source: None, @@ -703,7 +703,7 @@ mod test { } #[test] - fn test_download() -> RequestResult<()> { + fn test_send_request() -> RequestResult<()> { let req: request::MicrodescRequest = vec![[9; 32]].into_iter().collect(); let (response, request) = run_download_test( diff --git a/crates/tor-dirclient/src/util.rs b/crates/tor-dirclient/src/util.rs index 5c9b0685f..ccb713ce6 100644 --- a/crates/tor-dirclient/src/util.rs +++ b/crates/tor-dirclient/src/util.rs @@ -16,6 +16,7 @@ pub(crate) fn encode_request(req: &http::Request<()>) -> String { ) .unwrap(); } + // TODO HSS encode the body s.push_str("\r\n"); s } diff --git a/crates/tor-dirmgr/src/bridgedesc.rs b/crates/tor-dirmgr/src/bridgedesc.rs index dd9a13045..982de829a 100644 --- a/crates/tor-dirmgr/src/bridgedesc.rs +++ b/crates/tor-dirmgr/src/bridgedesc.rs @@ -212,11 +212,11 @@ impl mockable::MockableAPI for () { .await .map_err(Error::StreamFailed)?; let request = tor_dirclient::request::RoutersOwnDescRequest::new(); - let response = tor_dirclient::download(runtime, &request, &mut stream, None) + let response = tor_dirclient::send_request(runtime, &request, &mut stream, None) .await .map_err(|dce| match dce { tor_dirclient::Error::RequestFailed(re) => Error::RequestFailed(re), - _ => internal!("tor_dirclient::download gave non-RequestFailed {:?}", dce).into(), + _ => internal!("tor_dirclient::send_request gave non-RequestFailed {:?}", dce).into(), })?; let output = response.into_output_string()?; Ok(Some(output)) diff --git a/crates/tor-hsclient/src/connect.rs b/crates/tor-hsclient/src/connect.rs index 7a261e981..69ffb0f16 100644 --- a/crates/tor-hsclient/src/connect.rs +++ b/crates/tor-hsclient/src/connect.rs @@ -580,7 +580,7 @@ impl<'c, R: Runtime, M: MocksForConnect> Context<'c, R, M> { .await .map_err(DescriptorErrorDetail::Stream)?; - let response = tor_dirclient::download(self.runtime, &request, &mut stream, None) + let response = tor_dirclient::send_request(self.runtime, &request, &mut stream, None) .await .map_err(|dir_error| match dir_error { tor_dirclient::Error::RequestFailed(rfe) => DescriptorErrorDetail::from(rfe.error),