Skip to content

Commit

Permalink
Update to Rust 1.77.0 (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky authored Mar 22, 2024
1 parent 8d535ad commit 0311d30
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 41 deletions.
2 changes: 1 addition & 1 deletion benches/cluster_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ mod serde {
resources.push(
resource_type
.encode_to_any(&Cluster {
locality: cluster.key().clone().map(|l| l.try_into().unwrap()),
locality: cluster.key().clone().map(From::from),
endpoints: cluster
.endpoints
.iter()
Expand Down
4 changes: 2 additions & 2 deletions benches/shared.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![allow(dead_code)]

pub use std::{
net::{Ipv4Addr, SocketAddr, SocketAddrV4, UdpSocket},
sync::{atomic, mpsc, Arc},
net::{Ipv4Addr, SocketAddr, UdpSocket},
sync::{mpsc, Arc},
};

pub const READ_QUILKIN_PORT: u16 = 9001;
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
# limitations under the License.

[toolchain]
channel = "1.74.0"
channel = "1.77.0"
components = ["rustfmt", "clippy"]
1 change: 1 addition & 0 deletions src/components/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ mod tests {
assert_eq!(response.status(), hyper::StatusCode::OK);
}

#[cfg(target_os = "linux")]
#[tokio::test]
async fn collect_pprof() {
// Custom time to make the test fast.
Expand Down
2 changes: 2 additions & 0 deletions src/components/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ impl Agent {
result = task => {
let client = result?;

// The inner fields are unused.
#[allow(dead_code)]
enum XdsTask {
Delta(crate::net::xds::client::DeltaSubscription),
Aggregated(crate::net::xds::client::MdsStream),
Expand Down
2 changes: 2 additions & 0 deletions src/components/manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ impl Manage {
)
.await?;

// The inner fields are unused.
#[allow(dead_code)]
enum XdsTask {
Delta(crate::net::xds::client::DeltaSubscription),
Aggregated(crate::net::xds::client::MdsStream),
Expand Down
2 changes: 1 addition & 1 deletion src/components/proxy/packet_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl DownstreamReceiveWorkerConfig {
let (result, contents) = socket.recv_from(buffer).await;
match result {
Ok((_size, mut source)) => {
crate::net::to_canonical(&mut source);
source.set_ip(source.ip().to_canonical());
let packet = DownstreamPacket {
received_at: crate::unix_timestamp(),
asn_info: crate::net::maxmind_db::MaxmindDb::lookup(source.ip()),
Expand Down
2 changes: 1 addition & 1 deletion src/components/proxy/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl SessionPool {
last_received_at: &mut Option<i64>,
) {
let received_at = crate::unix_timestamp();
crate::net::to_canonical(&mut recv_addr);
recv_addr.set_ip(recv_addr.ip().to_canonical());
let (downstream_addr, asn_info): (SocketAddr, Option<IpNetEntry>) = {
let storage = self.storage.read().await;
let Some(downstream_addr) = storage.destination_to_sources.get(&(recv_addr, port))
Expand Down
13 changes: 5 additions & 8 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,20 @@ impl Config {
if names.is_empty() {
for cluster in self.clusters.read().iter() {
resources.push(resource_type.encode_to_any(
&crate::net::cluster::proto::Cluster::try_from((
&crate::net::cluster::proto::Cluster::from((
cluster.key(),
&cluster.value().endpoints,
))?,
)),
)?);
}
} else {
for locality in names.iter().filter_map(|name| name.parse().ok()) {
if let Some(cluster) = self.clusters.read().get(&Some(locality)) {
resources.push(resource_type.encode_to_any(
&crate::net::cluster::proto::Cluster::try_from((
&crate::net::cluster::proto::Cluster::from((
cluster.key(),
&cluster.value().endpoints,
))?,
)),
)?);
}
}
Expand Down Expand Up @@ -305,10 +305,7 @@ impl Config {
name: key.as_ref().map(|k| k.to_string()).unwrap_or_default(),
version: current_version.to_string(),
resource: Some(resource_type.encode_to_any(
&crate::net::cluster::proto::Cluster::try_from((
key,
&value.endpoints,
))?,
&crate::net::cluster::proto::Cluster::from((key, &value.endpoints)),
)?),
..Default::default()
});
Expand Down
2 changes: 1 addition & 1 deletion src/config/providers/k8s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn update_filters_from_configmap(

let configmap = match event {
Event::Applied(configmap) => configmap,
Event::Restarted(configmaps) => match configmaps.get(0) {
Event::Restarted(configmaps) => match configmaps.first() {
Some(configmap) => configmap.clone(),
None => {
yield Ok(());
Expand Down
5 changes: 1 addition & 4 deletions src/config/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ impl<T: Clone + Default> Slot<T> {
/// slot. Any changes made will update the value in the slot.
pub fn modify(&self, mut modify: impl FnMut(&mut T)) {
self.inner.rcu(|value| {
let mut current = value
.as_deref()
.map(|value| T::clone(value))
.unwrap_or_default();
let mut current = value.as_deref().cloned().unwrap_or_default();
(modify)(&mut current);
Some(Arc::new(current))
});
Expand Down
18 changes: 0 additions & 18 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,21 +429,3 @@ mod tests {
);
}
}

/// Converts a a socket address to its canonical version.
/// This is just a copy of the method available in std but that is currently
/// nightly only.
pub fn to_canonical(addr: &mut SocketAddr) {
let ip = match addr.ip() {
std::net::IpAddr::V6(ip) => {
if let Some(mapped) = ip.to_ipv4_mapped() {
std::net::IpAddr::V4(mapped)
} else {
std::net::IpAddr::V6(ip)
}
}
addr => addr,
};

addr.set_ip(ip);
}
5 changes: 2 additions & 3 deletions src/net/xds/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ impl Resource {
/// In the relay service, it receives datacenter resources from the agents
/// without a host, because hosts don't know their own public IP, but the
/// relay does, so we add it to the `Resource`.
pub fn add_host_to_datacenter(&mut self, mut addr: std::net::SocketAddr) {
pub fn add_host_to_datacenter(&mut self, addr: std::net::SocketAddr) {
if let Self::Datacenter(dc) = self {
crate::net::to_canonical(&mut addr);
dc.host = addr.ip().to_string();
dc.host = addr.ip().to_canonical().to_string();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/net/xds/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ impl AggregatedControlPlaneDiscoveryService for ControlPlane {
let mut remote_addr = responses
.remote_addr()
.ok_or_else(|| tonic::Status::invalid_argument("no remote address available"))?;
crate::net::to_canonical(&mut remote_addr);
remote_addr.set_ip(remote_addr.ip().to_canonical());
let mut responses = responses.into_inner();
let Some(identifier) = responses
.next()
Expand Down

0 comments on commit 0311d30

Please sign in to comment.