Skip to content

Commit

Permalink
chore: migrate to Rust 2024 edition
Browse files Browse the repository at this point in the history
This is thankfully a smooth transition for us. All the changes are
just style updates, mostly due to sorting switching from ASCIIbetical
to Unicode-aware (non-lowercase comes before lowercase now).

Signed-off-by: Renato Westphal <[email protected]>
  • Loading branch information
rwestphal committed Jan 10, 2025
1 parent e99eda9 commit 2efc855
Show file tree
Hide file tree
Showing 155 changed files with 388 additions and 409 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ resolver = "2"
version = "0.5.0"
authors = ["Renato Westphal <[email protected]>"]
license = "MIT"
edition = "2021"
edition = "2024"
repository = "https://github.com/holo-routing/holo"

[workspace.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions holo-bfd/src/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ impl ProtocolInstance for Master {
}
}

fn protocol_input_channels(
) -> (ProtocolInputChannelsTx, ProtocolInputChannelsRx) {
fn protocol_input_channels()
-> (ProtocolInputChannelsTx, ProtocolInputChannelsRx) {
let (udp_packet_rxp, udp_packet_rxc) = mpsc::channel(4);
let (detect_timerp, detect_timerc) = mpsc::channel(4);

Expand Down
6 changes: 3 additions & 3 deletions holo-bfd/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use std::net::{
};
use std::ops::Deref;
use std::os::fd::AsRawFd;
use std::sync::atomic::{self, AtomicU64};
use std::sync::Arc;
use std::sync::atomic::{self, AtomicU64};

use holo_utils::bfd::PathType;
use holo_utils::ip::{AddressFamily, IpAddrExt};
use holo_utils::socket::{SocketExt, UdpSocket, UdpSocketExt, TTL_MAX};
use holo_utils::{capabilities, Sender};
use holo_utils::socket::{SocketExt, TTL_MAX, UdpSocket, UdpSocketExt};
use holo_utils::{Sender, capabilities};
use nix::sys::socket::{self, ControlMessageOwned};
use serde::{Deserialize, Serialize};
use tokio::sync::mpsc::error::SendError;
Expand Down
2 changes: 1 addition & 1 deletion holo-bfd/src/northbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub mod yang;
use holo_northbound::ProviderBase;
use holo_utils::protocol::Protocol;
use holo_yang::ToYang;
use tracing::{debug_span, Span};
use tracing::{Span, debug_span};

use crate::master::Master;

Expand Down
2 changes: 1 addition & 1 deletion holo-bfd/src/northbound/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::borrow::Cow;
use std::net::IpAddr;

use holo_northbound::{notification, yang, NbProviderSender};
use holo_northbound::{NbProviderSender, notification, yang};
use holo_utils::bfd::SessionKey;
use holo_yang::ToYang;

Expand Down
2 changes: 1 addition & 1 deletion holo-bfd/src/northbound/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//

use std::borrow::Cow;
use std::sync::{atomic, LazyLock as Lazy};
use std::sync::{LazyLock as Lazy, atomic};

use enum_as_inner::EnumAsInner;
use holo_northbound::state::{
Expand Down
8 changes: 4 additions & 4 deletions holo-bfd/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
// SPDX-License-Identifier: MIT
//

use std::collections::{hash_map, BTreeMap, HashMap, HashSet};
use std::collections::{BTreeMap, HashMap, HashSet, hash_map};
use std::net::{IpAddr, SocketAddr};
use std::sync::atomic::{AtomicBool, AtomicU64};
use std::sync::{atomic, Arc};
use std::sync::{Arc, atomic};

use chrono::{DateTime, Utc};
use derive_new::new;
use generational_arena::{Arena, Index};
use holo_northbound::yang::control_plane_protocol::bfd;
use holo_protocol::InstanceChannelsTx;
use holo_utils::Sender;
use holo_utils::bfd::{ClientCfg, ClientId, SessionKey, State};
use holo_utils::ibus::IbusMsg;
use holo_utils::ip::{IpAddrExt, IpAddrKind};
use holo_utils::socket::{UdpSocket, TTL_MAX};
use holo_utils::socket::{TTL_MAX, UdpSocket};
use holo_utils::task::{IntervalTask, TimeoutTask};
use holo_utils::Sender;
use rand::RngCore;

use crate::debug::Debug;
Expand Down
4 changes: 2 additions & 2 deletions holo-bfd/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
//

use std::net::SocketAddr;
use std::sync::{atomic, Arc};
use std::sync::{Arc, atomic};
use std::time::Duration;

use holo_utils::Sender;
use holo_utils::bfd::PathType;
use holo_utils::socket::UdpSocket;
use holo_utils::task::{IntervalTask, Task, TimeoutTask};
use holo_utils::Sender;
use tracing::Instrument;

use crate::network;
Expand Down
2 changes: 1 addition & 1 deletion holo-bgp/benches/msg_decoding.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::hint::black_box;

use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{Criterion, criterion_group, criterion_main};
use holo_bgp::neighbor::PeerType;
use holo_bgp::packet::message::{DecodeCxt, Message, NegotiatedCapability};

Expand Down
4 changes: 2 additions & 2 deletions holo-bgp/benches/msg_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::net::Ipv4Addr;
use std::str::FromStr;
use std::sync::LazyLock as Lazy;

use criterion::{criterion_group, criterion_main, Criterion};
use holo_bgp::packet::consts::{Afi, Safi, BGP_VERSION};
use criterion::{Criterion, criterion_group, criterion_main};
use holo_bgp::packet::consts::{Afi, BGP_VERSION, Safi};
use holo_bgp::packet::message::{
Capability, EncodeCxt, Message, NegotiatedCapability, OpenMsg,
};
Expand Down
2 changes: 1 addition & 1 deletion holo-bgp/src/af.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use itertools::Itertools;
use crate::neighbor::{
Neighbor, NeighborUpdateQueue, NeighborUpdateQueues, PeerType,
};
use crate::packet::attribute::{self, BaseAttrs, ATTR_MIN_LEN_EXT};
use crate::packet::attribute::{self, ATTR_MIN_LEN_EXT, BaseAttrs};
use crate::packet::consts::{Afi, Safi};
use crate::packet::message::{
Message, MpReachNlri, MpUnreachNlri, ReachNlri, UnreachNlri, UpdateMsg,
Expand Down
5 changes: 4 additions & 1 deletion holo-bgp/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ impl std::fmt::Display for IoError {
write!(f, "failed to set TCP authentication option")
}
IoError::TcpInfoError(..) => {
write!(f, "failed to fetch address and port information from the socket")
write!(
f,
"failed to fetch address and port information from the socket"
)
}
IoError::TcpRecvError(..) => {
write!(f, "failed to read TCP data")
Expand Down
2 changes: 1 addition & 1 deletion holo-bgp/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::af::{AddressFamily, Ipv4Unicast, Ipv6Unicast};
use crate::debug::Debug;
use crate::error::{Error, IoError, NbrRxError};
use crate::instance::{InstanceUpView, PolicyApplyTasks};
use crate::neighbor::{fsm, Neighbor, Neighbors, PeerType};
use crate::neighbor::{Neighbor, Neighbors, PeerType, fsm};
use crate::packet::attribute::Attrs;
use crate::packet::consts::{Afi, Safi};
use crate::packet::message::{
Expand Down
6 changes: 3 additions & 3 deletions holo-bgp/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use tokio::sync::mpsc;
use crate::af::{Ipv4Unicast, Ipv6Unicast};
use crate::debug::{Debug, InstanceInactiveReason};
use crate::error::{Error, IoError};
use crate::neighbor::{fsm, Neighbors};
use crate::neighbor::{Neighbors, fsm};
use crate::northbound::configuration::InstanceCfg;
use crate::packet::consts::{CeaseSubcode, ErrorCode};
use crate::packet::message::NotificationMsg;
Expand Down Expand Up @@ -283,8 +283,8 @@ impl ProtocolInstance for Instance {
}
}

fn protocol_input_channels(
) -> (ProtocolInputChannelsTx, ProtocolInputChannelsRx) {
fn protocol_input_channels()
-> (ProtocolInputChannelsTx, ProtocolInputChannelsRx) {
let (tcp_acceptp, tcp_acceptc) = mpsc::channel(4);
let (tcp_connectp, tcp_connectc) = mpsc::channel(4);
let (nbr_msg_rxp, nbr_msg_rxc) = mpsc::channel(4);
Expand Down
20 changes: 9 additions & 11 deletions holo-bgp/src/neighbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

use std::collections::{BTreeMap, BTreeSet};
use std::net::{IpAddr, Ipv4Addr};
use std::sync::atomic::{self, AtomicU32};
use std::sync::Arc;
use std::sync::atomic::{self, AtomicU32};
use std::time::Duration;

use chrono::{DateTime, Utc};
use holo_protocol::InstanceChannelsTx;
use holo_utils::bgp::{AfiSafi, RouteType, WellKnownCommunities};
use holo_utils::ibus::IbusSender;
use holo_utils::socket::{TcpConnInfo, TcpStream, TTL_MAX};
use holo_utils::socket::{TTL_MAX, TcpConnInfo, TcpStream};
use holo_utils::task::{IntervalTask, Task, TimeoutTask};
use holo_utils::{Sender, UnboundedSender};
use num_traits::{FromPrimitive, ToPrimitive};
Expand All @@ -29,17 +29,17 @@ use crate::northbound::notification;
use crate::northbound::rpc::ClearType;
use crate::packet::attribute::Attrs;
use crate::packet::consts::{
Afi, CeaseSubcode, ErrorCode, FsmErrorSubcode, Safi, AS_TRANS, BGP_VERSION,
AS_TRANS, Afi, BGP_VERSION, CeaseSubcode, ErrorCode, FsmErrorSubcode, Safi,
};
use crate::packet::message::{
Capability, DecodeCxt, EncodeCxt, KeepaliveMsg, Message,
NegotiatedCapability, NotificationMsg, OpenMsg, RouteRefreshMsg,
};
use crate::rib::{Rib, Route, RouteOrigin};
use crate::tasks::messages::input::{NbrRxMsg, NbrTimerMsg, TcpConnectMsg};
use crate::tasks::messages::output::NbrTxMsg;
#[cfg(feature = "testing")]
use crate::tasks::messages::ProtocolOutputMsg;
use crate::tasks::messages::input::{NbrRxMsg, NbrTimerMsg, TcpConnectMsg};
use crate::tasks::messages::output::NbrTxMsg;
use crate::{events, rib, tasks};

// Large hold-time used during session initialization.
Expand Down Expand Up @@ -661,13 +661,11 @@ impl Neighbor {
// Sends a BGP OPEN message based on the local configuration.
fn open_send(&mut self, instance_cfg: &InstanceCfg, identifier: Ipv4Addr) {
// Base capabilities.
let mut capabilities: BTreeSet<_> = [
Capability::RouteRefresh,
Capability::FourOctetAsNumber {
let mut capabilities: BTreeSet<_> =
[Capability::RouteRefresh, Capability::FourOctetAsNumber {
asn: instance_cfg.asn,
},
]
.into();
}]
.into();

// Multiprotocol capabilities.
if let Some(afi_safi) = self.config.afi_safi.get(&AfiSafi::Ipv4Unicast)
Expand Down
6 changes: 3 additions & 3 deletions holo-bgp/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use std::sync::Arc;

use holo_utils::ip::{AddressFamily, IpAddrExt, IpAddrKind};
use holo_utils::socket::{
OwnedReadHalf, OwnedWriteHalf, SocketExt, TcpConnInfo, TcpListener,
TcpSocket, TcpSocketExt, TcpStream, TcpStreamExt, TTL_MAX,
OwnedReadHalf, OwnedWriteHalf, SocketExt, TTL_MAX, TcpConnInfo,
TcpListener, TcpSocket, TcpSocketExt, TcpStream, TcpStreamExt,
};
use holo_utils::{capabilities, Sender, UnboundedReceiver};
use holo_utils::{Sender, UnboundedReceiver, capabilities};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::sync::mpsc::error::SendError;

Expand Down
2 changes: 1 addition & 1 deletion holo-bgp/src/northbound/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use holo_yang::TryFromYang;

use crate::af::{Ipv4Unicast, Ipv6Unicast};
use crate::instance::{Instance, InstanceUpView};
use crate::neighbor::{fsm, Neighbor, PeerType};
use crate::neighbor::{Neighbor, PeerType, fsm};
use crate::network;
use crate::packet::consts::{CeaseSubcode, ErrorCode};
use crate::packet::message::NotificationMsg;
Expand Down
2 changes: 1 addition & 1 deletion holo-bgp/src/northbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub mod yang;
use holo_northbound::ProviderBase;
use holo_utils::protocol::Protocol;
use holo_yang::ToYang;
use tracing::{debug_span, Span};
use tracing::{Span, debug_span};

use crate::instance::Instance;

Expand Down
4 changes: 2 additions & 2 deletions holo-bgp/src/northbound/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//

use std::borrow::Cow;
use std::sync::{atomic, Arc, LazyLock as Lazy};
use std::sync::{Arc, LazyLock as Lazy, atomic};

use enum_as_inner::EnumAsInner;
use holo_northbound::state::{
Expand All @@ -18,7 +18,7 @@ use holo_yang::ToYang;
use ipnetwork::{Ipv4Network, Ipv6Network};

use crate::instance::Instance;
use crate::neighbor::{fsm, Neighbor};
use crate::neighbor::{Neighbor, fsm};
use crate::packet::attribute::{
AsPathSegment, BaseAttrs, Comms, ExtComms, Extv6Comms, LargeComms,
UnknownAttr,
Expand Down
2 changes: 1 addition & 1 deletion holo-bgp/src/northbound/yang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::borrow::Cow;
use holo_yang::{ToYang, TryFromYang};
use num_traits::FromPrimitive;

use crate::neighbor::{fsm, PeerType};
use crate::neighbor::{PeerType, fsm};
use crate::northbound::configuration::PrivateAsRemove;
use crate::packet::consts::{
AddPathMode, AsPathSegmentType, CapabilityCode, CeaseSubcode, ErrorCode,
Expand Down
8 changes: 4 additions & 4 deletions holo-bgp/src/packet/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use crate::packet::consts::{
};
use crate::packet::error::{AttrError, UpdateMessageError};
use crate::packet::message::{
decode_ipv4_prefix, decode_ipv6_prefix, encode_ipv4_prefix,
encode_ipv6_prefix, DecodeCxt, EncodeCxt, MpReachNlri, MpUnreachNlri,
NegotiatedCapability, ReachNlri,
DecodeCxt, EncodeCxt, MpReachNlri, MpUnreachNlri, NegotiatedCapability,
ReachNlri, decode_ipv4_prefix, decode_ipv6_prefix, encode_ipv4_prefix,
encode_ipv6_prefix,
};

pub const ATTR_MIN_LEN: u16 = 3;
Expand Down Expand Up @@ -439,7 +439,7 @@ impl Attrs {
AttrError::Reset => {
return Err(
UpdateMessageError::OptionalAttributeError,
)
);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions holo-bgp/src/packet/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use serde_with::skip_serializing_none;
use crate::neighbor::PeerType;
use crate::packet::attribute::Attrs;
use crate::packet::consts::{
AddPathMode, Afi, CapabilityCode, ErrorCode, MessageHeaderErrorSubcode,
MessageType, OpenMessageErrorSubcode, OpenParamType, Safi,
UpdateMessageErrorSubcode, BGP_VERSION,
AddPathMode, Afi, BGP_VERSION, CapabilityCode, ErrorCode,
MessageHeaderErrorSubcode, MessageType, OpenMessageErrorSubcode,
OpenParamType, Safi, UpdateMessageErrorSubcode,
};
use crate::packet::error::{
DecodeError, DecodeResult, MessageHeaderError, OpenMessageError,
Expand Down
2 changes: 1 addition & 1 deletion holo-bgp/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::net::IpAddr;
use std::sync::Arc;

use derive_new::new;
use holo_utils::UnboundedSender;
use holo_utils::bgp::{AfiSafi, RouteType};
use holo_utils::ip::IpNetworkKind;
use holo_utils::policy::{
Expand All @@ -18,7 +19,6 @@ use holo_utils::policy::{
PolicyType,
};
use holo_utils::southbound::RouteOpaqueAttrs;
use holo_utils::UnboundedSender;
use ipnetwork::IpNetwork;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
Expand Down
2 changes: 1 addition & 1 deletion holo-bgp/src/rib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//

use std::cmp::Ordering;
use std::collections::{btree_map, hash_map, BTreeMap, BTreeSet, HashMap};
use std::collections::{BTreeMap, BTreeSet, HashMap, btree_map, hash_map};
use std::net::{IpAddr, Ipv4Addr};
use std::sync::Arc;
use std::time::Instant;
Expand Down
6 changes: 3 additions & 3 deletions holo-bgp/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
// SPDX-License-Identifier: MIT
//

use std::sync::{atomic, Arc};
use std::sync::{Arc, atomic};
use std::time::Duration;

use holo_utils::socket::{OwnedReadHalf, OwnedWriteHalf, TcpListener};
use holo_utils::task::{IntervalTask, Task, TimeoutTask};
use holo_utils::{Sender, UnboundedReceiver, UnboundedSender};
use tokio::time::sleep;
use tracing::{debug_span, Instrument};
use tracing::{Instrument, debug_span};

use crate::debug::Debug;
use crate::neighbor::{fsm, Neighbor};
use crate::neighbor::{Neighbor, fsm};
use crate::packet::message::{DecodeCxt, EncodeCxt, KeepaliveMsg, Message};
use crate::{network, policy};

Expand Down
2 changes: 1 addition & 1 deletion holo-bgp/tests/packet/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::net::Ipv4Addr;
use std::str::FromStr;
use std::sync::LazyLock as Lazy;

use holo_bgp::packet::consts::{Afi, Safi, BGP_VERSION};
use holo_bgp::packet::consts::{Afi, BGP_VERSION, Safi};
use holo_bgp::packet::message::{Capability, Message, OpenMsg};

use super::{test_decode_msg, test_encode_msg};
Expand Down
2 changes: 1 addition & 1 deletion holo-daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use pickledb::{PickleDb, PickleDbDumpPolicy, SerializationMethod};
use tracing::level_filters::LevelFilter;
use tracing::{error, info};
use tracing_appender::rolling;
use tracing_subscriber::prelude::*;
use tracing_subscriber::Layer;
use tracing_subscriber::prelude::*;

fn init_tracing(config: &config::Logging) {
// Enable logging to journald.
Expand Down
Loading

0 comments on commit 2efc855

Please sign in to comment.