Skip to content

Commit c79e2e7

Browse files
committed
rust-toolchain: Upgrade to 1.85.0, update rust edition to 2024
Signed-off-by: Eval EXEC <execvy@gmail.com>
1 parent f685607 commit c79e2e7

File tree

32 files changed

+145
-134
lines changed

32 files changed

+145
-134
lines changed

bench/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "bench"
33
version = "0.1.0"
44
authors = ["piaoliu <441594700@qq.com>"]
5-
edition = "2021"
5+
edition = "2024"
66

77
[lib]
88
name = "bench"

bench/src/main.rs

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ use p2p::{
1313
traits::{ServiceHandle, ServiceProtocol},
1414
ProtocolId,
1515
};
16-
use std::{sync::Once, thread};
16+
use std::{
17+
sync::{Once, OnceLock},
18+
thread,
19+
};
1720
use tokio_util::codec::length_delimited::Builder;
1821

1922
static START_SECIO: Once = Once::new();
2023
static START_NO_SECIO: Once = Once::new();
2124

22-
static mut SECIO_CONTROL: Option<ServiceControl> = None;
23-
static mut NO_SECIO_CONTROL: Option<ServiceControl> = None;
25+
static SECIO_CONTROL: OnceLock<ServiceControl> = OnceLock::new();
26+
static NO_SECIO_CONTROL: OnceLock<ServiceControl> = OnceLock::new();
2427

25-
static mut SECIO_RECV: Option<crossbeam_channel::Receiver<Notify>> = None;
26-
static mut NO_SECIO_RECV: Option<crossbeam_channel::Receiver<Notify>> = None;
28+
static SECIO_RECV: OnceLock<crossbeam_channel::Receiver<Notify>> = OnceLock::new();
29+
static NO_SECIO_RECV: OnceLock<crossbeam_channel::Receiver<Notify>> = OnceLock::new();
2730

2831
#[derive(Debug, PartialEq)]
2932
enum Notify {
@@ -134,10 +137,8 @@ pub fn init() {
134137
});
135138

136139
assert_eq!(client_receiver.recv(), Ok(Notify::Connected));
137-
unsafe {
138-
SECIO_CONTROL = Some(control.into());
139-
SECIO_RECV = Some(client_receiver);
140-
}
140+
assert!(SECIO_CONTROL.set(control.into()).is_ok());
141+
assert!(SECIO_RECV.set(client_receiver).is_ok());
141142
});
142143

143144
// init no secio two peers
@@ -174,43 +175,37 @@ pub fn init() {
174175
});
175176

176177
assert_eq!(client_receiver.recv(), Ok(Notify::Connected));
177-
unsafe {
178-
NO_SECIO_CONTROL = Some(control.into());
179-
NO_SECIO_RECV = Some(client_receiver);
180-
}
178+
assert!(NO_SECIO_CONTROL.set(control.into()).is_ok());
179+
assert!(NO_SECIO_RECV.set(client_receiver).is_ok());
181180
});
182181
}
183182

184183
fn secio_and_send_data(data: &[u8]) {
185-
unsafe {
186-
SECIO_CONTROL.as_mut().map(|control| {
187-
control.filter_broadcast(
188-
TargetSession::All,
189-
ProtocolId::new(1),
190-
Bytes::from(data.to_owned()),
191-
)
192-
});
193-
if let Some(rev) = SECIO_RECV.as_ref() {
194-
assert_eq!(
195-
rev.recv(),
196-
Ok(Notify::Message(bytes::Bytes::from(data.to_owned())))
197-
)
198-
}
184+
SECIO_CONTROL.get().map(|control| {
185+
control.filter_broadcast(
186+
TargetSession::All,
187+
ProtocolId::new(1),
188+
Bytes::from(data.to_owned()),
189+
)
190+
});
191+
if let Some(rev) = SECIO_RECV.get() {
192+
assert_eq!(
193+
rev.recv(),
194+
Ok(Notify::Message(bytes::Bytes::from(data.to_owned())))
195+
)
199196
}
200197
}
201198

202199
fn no_secio_and_send_data(data: &[u8]) {
203-
unsafe {
204-
NO_SECIO_CONTROL.as_mut().map(|control| {
205-
control.filter_broadcast(TargetSession::All, 1.into(), Bytes::from(data.to_owned()))
206-
});
200+
NO_SECIO_CONTROL.get().map(|control| {
201+
control.filter_broadcast(TargetSession::All, 1.into(), Bytes::from(data.to_owned()))
202+
});
207203

208-
if let Some(rev) = NO_SECIO_RECV.as_ref() {
209-
assert_eq!(
210-
rev.recv(),
211-
Ok(Notify::Message(bytes::Bytes::from(data.to_owned())))
212-
)
213-
}
204+
if let Some(rev) = NO_SECIO_RECV.get() {
205+
assert_eq!(
206+
rev.recv(),
207+
Ok(Notify::Message(bytes::Bytes::from(data.to_owned())))
208+
)
214209
}
215210
}
216211

fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "tentacle-fuzz"
33
version = "0.0.1"
44
license = "MIT"
55
authors = ["Nervos Core Dev <dev@nervos.org>"]
6-
edition = "2021"
6+
edition = "2024"
77

88
[package.metadata]
99
cargo-fuzz = true

multiaddr/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
name = "tentacle-multiaddr"
33
version = "0.3.5"
44
authors = ["driftluo <driftluo@foxmail.com>"]
5-
edition = "2021"
6-
rust-version = "1.61.0"
5+
edition = "2024"
6+
rust-version = "1.85.0"
77
repository = "https://github.com/nervosnetwork/tentacle"
88
license = "MIT"
99
description = "Mini Implementation of multiaddr"

multiaddr/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
///! Mini Implementation of [multiaddr](https://github.com/jbenet/multiaddr) in Rust.
1+
//! Mini Implementation of [multiaddr](https://github.com/jbenet/multiaddr) in Rust.
22
mod error;
33
mod onion_addr;
44
mod protocol;

multiaddr/src/onion_addr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{borrow::Cow, fmt};
44
#[derive(Clone)]
55
pub struct Onion3Addr<'a>(Cow<'a, [u8; 35]>, u16);
66

7-
impl<'a> Onion3Addr<'a> {
7+
impl Onion3Addr<'_> {
88
/// Return the hash of the public key as bytes
99
pub fn hash(&self) -> &[u8; 35] {
1010
self.0.as_ref()

multiaddr/src/protocol.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl<'a> Protocol<'a> {
258258
}
259259
}
260260

261-
impl<'a> fmt::Display for Protocol<'a> {
261+
impl fmt::Display for Protocol<'_> {
262262
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
263263
use self::Protocol::*;
264264
match self {
@@ -280,7 +280,7 @@ impl<'a> fmt::Display for Protocol<'a> {
280280
}
281281
}
282282

283-
impl<'a> From<IpAddr> for Protocol<'a> {
283+
impl From<IpAddr> for Protocol<'_> {
284284
#[inline]
285285
fn from(addr: IpAddr) -> Self {
286286
match addr {
@@ -290,14 +290,14 @@ impl<'a> From<IpAddr> for Protocol<'a> {
290290
}
291291
}
292292

293-
impl<'a> From<Ipv4Addr> for Protocol<'a> {
293+
impl From<Ipv4Addr> for Protocol<'_> {
294294
#[inline]
295295
fn from(addr: Ipv4Addr) -> Self {
296296
Protocol::Ip4(addr)
297297
}
298298
}
299299

300-
impl<'a> From<Ipv6Addr> for Protocol<'a> {
300+
impl From<Ipv6Addr> for Protocol<'_> {
301301
#[inline]
302302
fn from(addr: Ipv6Addr) -> Self {
303303
Protocol::Ip6(addr)

protocols/discovery/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description = "p2p discovery protocol main reference bitcoin"
77
keywords = ["network", "peer-to-peer", "p2p", "discovery"]
88
repository = "https://github.com/nervosnetwork/tentacle"
99
categories = ["network-programming", "asynchronous"]
10-
edition = "2018"
10+
edition = "2024"
1111

1212
[package.metadata.docs.rs]
1313
features = []

protocols/identify/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description = "p2p identify protocol"
77
keywords = ["network", "peer-to-peer", "p2p", "identify"]
88
repository = "https://github.com/nervosnetwork/tentacle"
99
categories = ["network-programming", "asynchronous"]
10-
edition = "2018"
10+
edition = "2024"
1111

1212
[package.metadata.docs.rs]
1313
features = []

protocols/ping/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ keywords = ["network", "peer-to-peer", "p2p", "ping"]
77
categories = ["network-programming", "asynchronous"]
88
repository = "https://github.com/nervosnetwork/tentacle"
99
description = "ping protocol implementation for tentacle"
10-
edition = "2018"
10+
edition = "2024"
1111

1212
[package.metadata.docs.rs]
1313
features = []

0 commit comments

Comments
 (0)