make it no mut

This commit is contained in:
Yuwei B 2023-09-05 00:14:01 +10:00 committed by Dirkjan Ochtman
parent fe7bd363a7
commit 1df7537192
18 changed files with 39 additions and 38 deletions

View File

@ -29,7 +29,7 @@ impl<C: ClientHandle + Unpin> DnsHandle for MutMessageHandle<C> {
}
#[allow(unused_mut)]
fn send<R: Into<DnsRequest> + Unpin>(&mut self, request: R) -> Self::Response {
fn send<R: Into<DnsRequest> + Unpin>(&self, request: R) -> Self::Response {
let mut request = request.into();
#[cfg(feature = "dnssec")]

View File

@ -147,7 +147,7 @@ impl DnsHandle for AsyncClient {
type Response = DnsExchangeSend;
type Error = ProtoError;
fn send<R: Into<DnsRequest> + Unpin + Send + 'static>(&mut self, request: R) -> Self::Response {
fn send<R: Into<DnsRequest> + Unpin + Send + 'static>(&self, request: R) -> Self::Response {
self.exchange.send(request)
}

View File

@ -71,7 +71,7 @@ impl DnsHandle for AsyncDnssecClient {
type Response = Pin<Box<(dyn Stream<Item = Result<DnsResponse, ProtoError>> + Send + 'static)>>;
type Error = ProtoError;
fn send<R: Into<DnsRequest> + Unpin + Send + 'static>(&mut self, request: R) -> Self::Response {
fn send<R: Into<DnsRequest> + Unpin + Send + 'static>(&self, request: R) -> Self::Response {
self.client.send(request)
}
}

View File

@ -99,7 +99,7 @@ pub trait Client {
&self,
msg: R,
) -> Vec<ClientResult<DnsResponse>> {
let (mut client, runtime) = match self.spawn_client() {
let (client, runtime) = match self.spawn_client() {
Ok(c_r) => c_r,
Err(e) => return vec![Err(e)],
};

View File

@ -48,7 +48,7 @@ where
async fn inner_send(
request: DnsRequest,
active_queries: Arc<Mutex<HashMap<Query, RcStream<<H as DnsHandle>::Response>>>>,
mut client: H,
client: H,
) -> impl Stream<Item = Result<DnsResponse, ProtoError>> {
// TODO: what if we want to support multiple queries (non-standard)?
let query = request.queries().first().expect("no query!").clone();
@ -77,7 +77,7 @@ where
type Response = Pin<Box<dyn Stream<Item = Result<DnsResponse, ProtoError>> + Send>>;
type Error = ProtoError;
fn send<R: Into<DnsRequest>>(&mut self, request: R) -> Self::Response {
fn send<R: Into<DnsRequest>>(&self, request: R) -> Self::Response {
let request = request.into();
Box::pin(
@ -119,7 +119,7 @@ mod test {
type Response = Pin<Box<dyn Stream<Item = Result<DnsResponse, ProtoError>> + Send>>;
type Error = ProtoError;
fn send<R: Into<DnsRequest> + Send + 'static>(&mut self, request: R) -> Self::Response {
fn send<R: Into<DnsRequest> + Send + 'static>(&self, request: R) -> Self::Response {
let i = Arc::clone(&self.i);
let future = async {
let i = i;
@ -148,7 +148,7 @@ mod test {
fn test_memoized() {
use futures::executor::block_on;
let mut client = MemoizeClientHandle::new(TestClient {
let client = MemoizeClientHandle::new(TestClient {
i: Arc::new(Mutex::new(0)),
});

View File

@ -107,7 +107,7 @@ impl DnsHandle for DnsExchange {
type Response = DnsExchangeSend;
type Error = ProtoError;
fn send<R: Into<DnsRequest> + Unpin + Send + 'static>(&mut self, request: R) -> Self::Response {
fn send<R: Into<DnsRequest> + Unpin + Send + 'static>(&self, request: R) -> Self::Response {
DnsExchangeSend {
result: self.sender.send(request),
_sender: self.sender.clone(), // TODO: this shouldn't be necessary, currently the presence of Senders is what allows the background to track current users, it generally is dropped right after send, this makes sure that there is at least one active after send

View File

@ -53,7 +53,7 @@ pub trait DnsHandle: 'static + Clone + Send + Sync + Unpin {
/// * `request` - the fully constructed Message to send, note that most implementations of
/// will most likely be required to rewrite the QueryId, do no rely on that as
/// being stable.
fn send<R: Into<DnsRequest> + Unpin + Send + 'static>(&mut self, request: R) -> Self::Response;
fn send<R: Into<DnsRequest> + Unpin + Send + 'static>(&self, request: R) -> Self::Response;
/// A *classic* DNS query
///
@ -63,7 +63,7 @@ pub trait DnsHandle: 'static + Clone + Send + Sync + Unpin {
///
/// * `query` - the query to lookup
/// * `options` - options to use when constructing the message
fn lookup(&mut self, query: Query, options: DnsRequestOptions) -> Self::Response {
fn lookup(&self, query: Query, options: DnsRequestOptions) -> Self::Response {
debug!("querying: {} {:?}", query.name(), query.query_type());
self.send(DnsRequest::new(build_message(query, options), options))
}

View File

@ -115,7 +115,7 @@ where
true
}
fn send<R: Into<DnsRequest>>(&mut self, request: R) -> Self::Response {
fn send<R: Into<DnsRequest>>(&self, request: R) -> Self::Response {
let mut request = request.into();
// backstop
@ -467,7 +467,7 @@ where
/// as a success. Otherwise, a query is sent to get the DS record, and the DNSKEY is validated
/// against the DS record.
async fn verify_dnskey_rrset<H, E>(
mut handle: DnssecDnsHandle<H>,
handle: DnssecDnsHandle<H>,
rrset: Rrset,
options: DnsRequestOptions,
) -> Result<Rrset, E>
@ -715,7 +715,7 @@ where
.filter_map(|rrsig|rrsig.into_data())
.map(|sig| {
let rrset = Arc::clone(&rrset);
let mut handle = handle.clone_with_context();
let handle = handle.clone_with_context();
handle
.lookup(

View File

@ -166,7 +166,7 @@ impl DnsHandle for BufDnsRequestStreamHandle {
type Response = DnsResponseReceiver;
type Error = ProtoError;
fn send<R: Into<DnsRequest>>(&mut self, request: R) -> Self::Response {
fn send<R: Into<DnsRequest>>(&self, request: R) -> Self::Response {
let request: DnsRequest = request.into();
debug!(
"enqueueing message:{}:{:?}",
@ -175,7 +175,8 @@ impl DnsHandle for BufDnsRequestStreamHandle {
);
let (request, oneshot) = OneshotDnsRequest::oneshot(request);
try_oneshot!(self.sender.try_send(request).map_err(|_| {
let mut sender = self.sender.clone();
try_oneshot!(sender.try_send(request).map_err(|_| {
debug!("unable to enqueue message");
ProtoError::from(ProtoErrorKind::Busy)
}));

View File

@ -63,7 +63,7 @@ where
type Response = Pin<Box<dyn Stream<Item = Result<DnsResponse, Self::Error>> + Send + Unpin>>;
type Error = <H as DnsHandle>::Error;
fn send<R: Into<DnsRequest>>(&mut self, request: R) -> Self::Response {
fn send<R: Into<DnsRequest>>(&self, request: R) -> Self::Response {
let request = request.into();
// need to clone here so that the retry can resend if necessary...
@ -165,7 +165,7 @@ mod test {
type Response = Box<dyn Stream<Item = Result<DnsResponse, ProtoError>> + Send + Unpin>;
type Error = ProtoError;
fn send<R: Into<DnsRequest>>(&mut self, _: R) -> Self::Response {
fn send<R: Into<DnsRequest>>(&self, _: R) -> Self::Response {
let i = self.attempts.load(Ordering::SeqCst);
if (i > self.retries || self.retries - i == 0) && self.last_succeed {
@ -181,7 +181,7 @@ mod test {
#[test]
fn test_retry() {
let mut handle = RetryDnsHandle::new(
let handle = RetryDnsHandle::new(
TestClient {
last_succeed: true,
retries: 1,
@ -196,7 +196,7 @@ mod test {
#[test]
fn test_error() {
let mut client = RetryDnsHandle::new(
let client = RetryDnsHandle::new(
TestClient {
last_succeed: false,
retries: 1,

View File

@ -204,11 +204,11 @@ impl<P: ConnectionProvider> DnsHandle for LookupEither<P> {
}
}
fn send<R: Into<DnsRequest> + Unpin + Send + 'static>(&mut self, request: R) -> Self::Response {
fn send<R: Into<DnsRequest> + Unpin + Send + 'static>(&self, request: R) -> Self::Response {
match *self {
Self::Retry(ref mut c) => c.send(request),
Self::Retry(ref c) => c.send(request),
#[cfg(feature = "dnssec")]
Self::Secure(ref mut c) => c.send(request),
Self::Secure(ref c) => c.send(request),
}
}
}
@ -557,7 +557,7 @@ pub mod tests {
type Response = Pin<Box<dyn Stream<Item = Result<DnsResponse, ResolveError>> + Send>>;
type Error = ResolveError;
fn send<R: Into<DnsRequest>>(&mut self, _: R) -> Self::Response {
fn send<R: Into<DnsRequest>>(&self, _: R) -> Self::Response {
Box::pin(once(
future::ready(self.messages.lock().unwrap().pop().unwrap_or_else(empty)).boxed(),
))

View File

@ -474,7 +474,7 @@ pub mod tests {
Pin<Box<dyn Stream<Item = Result<DnsResponse, ResolveError>> + Send + Unpin>>;
type Error = ResolveError;
fn send<R: Into<DnsRequest>>(&mut self, _: R) -> Self::Response {
fn send<R: Into<DnsRequest>>(&self, _: R) -> Self::Response {
Box::pin(once(future::ready(
self.messages.lock().unwrap().pop().unwrap_or_else(empty),
)))

View File

@ -233,7 +233,7 @@ impl DnsHandle for GenericConnection {
type Response = ConnectionResponse;
type Error = ResolveError;
fn send<R: Into<DnsRequest> + Unpin + Send + 'static>(&mut self, request: R) -> Self::Response {
fn send<R: Into<DnsRequest> + Unpin + Send + 'static>(&self, request: R) -> Self::Response {
ConnectionResponse(self.0.send(request))
}
}

View File

@ -128,7 +128,7 @@ where
mut self,
request: R,
) -> Result<DnsResponse, ResolveError> {
let mut client = self.connected_mut_client().await?;
let client = self.connected_mut_client().await?;
let now = Instant::now();
let response = client.send(request).first_answer().await;
let rtt = now.elapsed();
@ -183,7 +183,7 @@ where
}
// TODO: there needs to be some way of customizing the connection based on EDNS options from the server side...
fn send<R: Into<DnsRequest> + Unpin + Send + 'static>(&mut self, request: R) -> Self::Response {
fn send<R: Into<DnsRequest> + Unpin + Send + 'static>(&self, request: R) -> Self::Response {
let this = self.clone();
// if state is failed, return future::err(), unless retry delay expired..
Box::pin(once(this.inner_send(request)))
@ -289,7 +289,7 @@ mod tests {
let name = Name::parse("www.example.com.", None).unwrap();
let response = io_loop
.block_on(name_server.then(|mut name_server| {
.block_on(name_server.then(|name_server| {
name_server
.lookup(
Query::query(name.clone(), RecordType::A),
@ -323,7 +323,7 @@ mod tests {
let name = Name::parse("www.example.com.", None).unwrap();
assert!(io_loop
.block_on(name_server.then(|mut name_server| {
.block_on(name_server.then(|name_server| {
name_server
.lookup(
Query::query(name.clone(), RecordType::A),

View File

@ -229,7 +229,7 @@ where
type Response = Pin<Box<dyn Stream<Item = Result<DnsResponse, ResolveError>> + Send>>;
type Error = ResolveError;
fn send<R: Into<DnsRequest>>(&mut self, request: R) -> Self::Response {
fn send<R: Into<DnsRequest>>(&self, request: R) -> Self::Response {
let opts = self.options;
let request = request.into();
let datagram_conns = Arc::clone(&self.datagram_conns);
@ -360,7 +360,7 @@ where
let mut requests = par_conns
.into_iter()
.map(move |mut conn| {
.map(move |conn| {
conn.send(request_cont.clone())
.first_answer()
.map(|result| result.map_err(|e| (conn, e)))
@ -516,7 +516,7 @@ mod tests {
resolver_config.add_name_server(config2);
let io_loop = Runtime::new().unwrap();
let mut pool = GenericNameServerPool::tokio_from_config(
let pool = GenericNameServerPool::tokio_from_config(
&resolver_config,
&ResolverOpts::default(),
TokioRuntimeProvider::new(),
@ -582,7 +582,7 @@ mod tests {
let name_servers: Arc<[_]> = Arc::from([name_server]);
#[cfg(not(feature = "mdns"))]
let mut pool = GenericNameServerPool::from_nameservers_test(
let pool = GenericNameServerPool::from_nameservers_test(
&opts,
Arc::from([]),
Arc::clone(&name_servers),

View File

@ -196,7 +196,7 @@ where
type Response = Pin<Box<dyn Stream<Item = Result<DnsResponse, E>> + Send>>;
type Error = E;
fn send<R: Into<DnsRequest>>(&mut self, _: R) -> Self::Response {
fn send<R: Into<DnsRequest>>(&self, _: R) -> Self::Response {
let mut messages = self.messages.lock().expect("failed to lock at messages");
println!("MockClientHandle::send message count: {}", messages.len());
@ -247,7 +247,7 @@ pub fn error<E>(error: E) -> Result<DnsResponse, E> {
pub trait OnSend: Clone + Send + Sync + 'static {
fn on_send<E>(
&mut self,
&self,
response: Result<DnsResponse, E>,
) -> Pin<Box<dyn Future<Output = Result<DnsResponse, E>> + Send>>
where

View File

@ -645,7 +645,7 @@ impl OnSendBarrier {
impl OnSend for OnSendBarrier {
fn on_send<E>(
&mut self,
&self,
response: Result<DnsResponse, E>,
) -> Pin<Box<dyn Future<Output = Result<DnsResponse, E>> + Send>>
where

View File

@ -23,7 +23,7 @@ impl DnsHandle for TestClient {
type Response = Box<dyn Stream<Item = Result<DnsResponse, Self::Error>> + Send + Unpin>;
type Error = ResolveError;
fn send<R: Into<DnsRequest>>(&mut self, _: R) -> Self::Response {
fn send<R: Into<DnsRequest>>(&self, _: R) -> Self::Response {
let i = self.attempts.load(Ordering::SeqCst);
if i > self.retries || self.retries - i == 0 {