tor-dirclient: Rename download() to send_request().
`download()` is actually a general-purpose function for sending HTTP requests on a stream. We will soon repurpose it for `POST`-ing descriptors, so let's rename it to `send_request`.
This commit is contained in:
parent
b2c37b0570
commit
9a08f04a76
|
@ -0,0 +1 @@
|
||||||
|
BREAKING: `download()` is renamed to `send_request()`
|
|
@ -79,7 +79,7 @@ pub type RequestResult<T> = std::result::Result<T, RequestError>;
|
||||||
/// constructed using `dirinfo`.
|
/// constructed using `dirinfo`.
|
||||||
///
|
///
|
||||||
/// For more fine-grained control over the circuit and stream used,
|
/// 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
|
/// # TODO
|
||||||
///
|
///
|
||||||
|
@ -122,7 +122,7 @@ where
|
||||||
|
|
||||||
// TODO: Perhaps we want separate timeouts for each phase of this.
|
// TODO: Perhaps we want separate timeouts for each phase of this.
|
||||||
// For now, we just use higher-level timeouts in `dirmgr`.
|
// 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) {
|
if should_retire_circ(&r) {
|
||||||
retire_circ(&circ_mgr, &source, "Partial response");
|
retire_circ(&circ_mgr, &source, "Partial response");
|
||||||
|
@ -140,7 +140,7 @@ fn should_retire_circ(result: &Result<DirResponse>) -> 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
|
/// 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
|
/// object in `req` over `stream`, and then wait for a response. In
|
||||||
|
@ -158,7 +158,7 @@ fn should_retire_circ(result: &Result<DirResponse>) -> bool {
|
||||||
/// The only error variant returned is [`Error::RequestFailed`].
|
/// The only error variant returned is [`Error::RequestFailed`].
|
||||||
// TODO: should the error return type change to `RequestFailedError`?
|
// TODO: should the error return type change to `RequestFailedError`?
|
||||||
// If so, that would simplify some code in_dirmgr::bridgedesc.
|
// If so, that would simplify some code in_dirmgr::bridgedesc.
|
||||||
pub async fn download<R, S, SP>(
|
pub async fn send_request<R, S, SP>(
|
||||||
runtime: &SP,
|
runtime: &SP,
|
||||||
req: &R,
|
req: &R,
|
||||||
stream: &mut S,
|
stream: &mut S,
|
||||||
|
@ -660,7 +660,7 @@ mod test {
|
||||||
) = futures::join!(
|
) = futures::join!(
|
||||||
async {
|
async {
|
||||||
// Run the download function.
|
// 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| {
|
s1.close().await.map_err(|error| {
|
||||||
Error::RequestFailed(RequestFailedError {
|
Error::RequestFailed(RequestFailedError {
|
||||||
source: None,
|
source: None,
|
||||||
|
@ -703,7 +703,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_download() -> RequestResult<()> {
|
fn test_send_request() -> RequestResult<()> {
|
||||||
let req: request::MicrodescRequest = vec![[9; 32]].into_iter().collect();
|
let req: request::MicrodescRequest = vec![[9; 32]].into_iter().collect();
|
||||||
|
|
||||||
let (response, request) = run_download_test(
|
let (response, request) = run_download_test(
|
||||||
|
|
|
@ -16,6 +16,7 @@ pub(crate) fn encode_request(req: &http::Request<()>) -> String {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
// TODO HSS encode the body
|
||||||
s.push_str("\r\n");
|
s.push_str("\r\n");
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,11 +212,11 @@ impl<R: Runtime> mockable::MockableAPI<R> for () {
|
||||||
.await
|
.await
|
||||||
.map_err(Error::StreamFailed)?;
|
.map_err(Error::StreamFailed)?;
|
||||||
let request = tor_dirclient::request::RoutersOwnDescRequest::new();
|
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
|
.await
|
||||||
.map_err(|dce| match dce {
|
.map_err(|dce| match dce {
|
||||||
tor_dirclient::Error::RequestFailed(re) => Error::RequestFailed(re),
|
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()?;
|
let output = response.into_output_string()?;
|
||||||
Ok(Some(output))
|
Ok(Some(output))
|
||||||
|
|
|
@ -580,7 +580,7 @@ impl<'c, R: Runtime, M: MocksForConnect<R>> Context<'c, R, M> {
|
||||||
.await
|
.await
|
||||||
.map_err(DescriptorErrorDetail::Stream)?;
|
.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
|
.await
|
||||||
.map_err(|dir_error| match dir_error {
|
.map_err(|dir_error| match dir_error {
|
||||||
tor_dirclient::Error::RequestFailed(rfe) => DescriptorErrorDetail::from(rfe.error),
|
tor_dirclient::Error::RequestFailed(rfe) => DescriptorErrorDetail::from(rfe.error),
|
||||||
|
|
Loading…
Reference in New Issue