Skip to content

Commit 8ea82ec

Browse files
committed
Change MultiAddr to Multiaddr
Signed-off-by: Eval EXEC <[email protected]>
1 parent e2cd407 commit 8ea82ec

File tree

20 files changed

+80
-83
lines changed

20 files changed

+80
-83
lines changed

network/fuzz/fuzz_targets/fuzz_peer_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
use libfuzzer_sys::fuzz_target;
44

55
use ckb_network::{
6-
multiaddr::MultiAddr, peer_store::types::BannedAddr, peer_store::PeerStore, Flags, PeerId,
6+
multiaddr::Multiaddr, peer_store::types::BannedAddr, peer_store::PeerStore, Flags, PeerId,
77
};
88
use ckb_network_fuzz::BufManager;
99

10-
fn new_multi_addr(data: &mut BufManager) -> (MultiAddr, Flags) {
10+
fn new_multi_addr(data: &mut BufManager) -> (Multiaddr, Flags) {
1111
let flags = data.get();
1212
let addr_flag = data.get::<u8>();
1313

network/src/address.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
use p2p::multiaddr::{MultiAddr, Protocol};
1+
use p2p::multiaddr::{Multiaddr, Protocol};
22

33
#[derive(Default, Clone, Debug)]
44
pub struct NetworkAddresses {
5-
pub regular_addresses: Vec<MultiAddr>,
5+
pub regular_addresses: Vec<Multiaddr>,
66

77
// onion addresses can't be solved by multiaddr_to_socketaddr or socketaddr_to_multiaddr
8-
pub onion_addresses: Vec<MultiAddr>,
8+
pub onion_addresses: Vec<Multiaddr>,
99
}
1010

1111
impl NetworkAddresses {
12-
pub fn push(&mut self, address: MultiAddr) {
12+
pub fn push(&mut self, address: Multiaddr) {
1313
if address
1414
.iter()
1515
.any(|proto| matches!(proto, Protocol::Onion3(_)))
@@ -21,7 +21,7 @@ impl NetworkAddresses {
2121
}
2222

2323
// contains
24-
pub fn contains(&self, address: &MultiAddr) -> bool {
24+
pub fn contains(&self, address: &Multiaddr) -> bool {
2525
self.regular_addresses.contains(address) || self.onion_addresses.contains(address)
2626
}
2727

@@ -38,9 +38,9 @@ impl NetworkAddresses {
3838

3939
// implement iter() for NetworkAddresses, don't take ownership
4040
impl<'a> IntoIterator for &'a NetworkAddresses {
41-
type Item = &'a MultiAddr;
41+
type Item = &'a Multiaddr;
4242
type IntoIter =
43-
std::iter::Chain<std::slice::Iter<'a, MultiAddr>, std::slice::Iter<'a, MultiAddr>>;
43+
std::iter::Chain<std::slice::Iter<'a, Multiaddr>, std::slice::Iter<'a, Multiaddr>>;
4444

4545
fn into_iter(self) -> Self::IntoIter {
4646
self.regular_addresses
@@ -49,9 +49,9 @@ impl<'a> IntoIterator for &'a NetworkAddresses {
4949
}
5050
}
5151

52-
// convert Vec<MultiAddr> to NetworkAddresses
53-
impl From<Vec<MultiAddr>> for NetworkAddresses {
54-
fn from(addresses: Vec<MultiAddr>) -> Self {
52+
// convert Vec<Multiaddr> to NetworkAddresses
53+
impl From<Vec<Multiaddr>> for NetworkAddresses {
54+
fn from(addresses: Vec<Multiaddr>) -> Self {
5555
let mut regular_addresses = Vec::new();
5656
let mut onion_addresses = Vec::new();
5757
for address in addresses {
@@ -71,8 +71,8 @@ impl From<Vec<MultiAddr>> for NetworkAddresses {
7171
}
7272
}
7373

74-
// convert NetworkAddresses to Vec<MultiAddr>
75-
impl From<NetworkAddresses> for Vec<MultiAddr> {
74+
// convert NetworkAddresses to Vec<Multiaddr>
75+
impl From<NetworkAddresses> for Vec<Multiaddr> {
7676
fn from(addresses: NetworkAddresses) -> Self {
7777
let mut result = addresses.regular_addresses;
7878
result.extend(addresses.onion_addresses);

network/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub type ProtocolVersion = String;
5656

5757
/// Observe listen port occupancy
5858
pub async fn observe_listen_port_occupancy(
59-
_addrs: &[multiaddr::MultiAddr],
59+
_addrs: &[multiaddr::Multiaddr],
6060
) -> Result<(), std::io::Error> {
6161
#[cfg(target_os = "linux")]
6262
{

network/src/network.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,12 +1059,11 @@ impl NetworkService {
10591059
p2p::service::SocketState::Dial => {
10601060
let domain = socket2::Domain::for_address(addr);
10611061
if socket_ref.domain()? == domain {
1062-
let should_bind_socket = !(proxy_config_enable
1063-
&& matches!(ctxt.state, p2p::service::SocketState::Dial));
1064-
if should_bind_socket {
1065-
socket_ref.bind(&addr.into())?;
1066-
} else {
1062+
if proxy_config_enable {
10671063
// skip bind if proxy enabled
1064+
debug!("skip bind since proxy is enabled");
1065+
} else {
1066+
socket_ref.bind(&addr.into())?;
10681067
}
10691068
}
10701069
Ok(socket)

network/src/peer_store/addr_manager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Address manager
22
use crate::peer_store::{base_addr, types::AddrInfo};
3+
use ckb_logger::debug;
34
use p2p::{
45
multiaddr::{Multiaddr, Protocol},
56
utils::multiaddr_to_socketaddr,
@@ -81,7 +82,7 @@ impl AddrManager {
8182
addr_infos.push(addr_info);
8283
} else {
8384
debug!(
84-
"addr {:?} is not connectable or not onion address",
85+
"addr {:?} is not connectable and not an onion address",
8586
addr_info.addr
8687
);
8788
}

network/src/peer_store/peer_store_db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
},
1010
};
1111
use ckb_logger::{debug, error};
12-
use p2p::multiaddr::MultiAddr;
12+
use p2p::multiaddr::Multiaddr;
1313
use std::path::Path;
1414
use std::{
1515
fs::{File, OpenOptions, copy, create_dir_all, remove_file, rename},
@@ -82,7 +82,7 @@ impl BanList {
8282
impl Anchors {
8383
/// Load address list from disk
8484
pub fn load<R: Read>(r: R) -> Result<Self, Error> {
85-
let addrs: Vec<MultiAddr> = serde_json::from_reader(r).map_err(PeerStoreError::Serde)?;
85+
let addrs: Vec<Multiaddr> = serde_json::from_reader(r).map_err(PeerStoreError::Serde)?;
8686
let mut anchors = Anchors::default();
8787
addrs.into_iter().for_each(|addr| anchors.add(addr));
8888
Ok(anchors)

network/src/protocols/identify/protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'a> IdentifyMessage<'a> {
7474
Ok(multi_addr) => {
7575
listen_addrs.push(multi_addr);
7676
}
77-
Err(err) => warn!("failed to decode listen_addr to MultiAddr: {}", err),
77+
Err(err) => warn!("failed to decode listen_addr to Multiaddr: {}", err),
7878
}
7979
}
8080

network/src/proxy.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ pub(crate) fn check_proxy_url(proxy_url: &str) -> Result<(), String> {
99
if scheme.ne("socks5") {
1010
return Err(format!("CKB doesn't support proxy scheme: {}", scheme));
1111
}
12+
if parsed_url.port().is_none() {
13+
return Err(format!("missing port in proxy url: {}", proxy_url));
14+
}
1215
Ok(())
1316
}
1417

network/src/services/outbound_peer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use ckb_systemtime::unix_time_as_millis;
88
use futures::{Future, StreamExt};
99
use p2p::runtime::{Interval, MissedTickBehavior};
1010
use p2p::{
11-
multiaddr::{MultiAddr, Protocol},
11+
multiaddr::{Multiaddr, Protocol},
1212
service::ServiceControl,
1313
};
1414
use rand::prelude::IteratorRandom;
@@ -131,7 +131,7 @@ impl OutboundPeerService {
131131
paddrs
132132
};
133133

134-
let peers: Box<dyn Iterator<Item = MultiAddr>> = if self.try_identify_count > 3 {
134+
let peers: Box<dyn Iterator<Item = Multiaddr>> = if self.try_identify_count > 3 {
135135
self.try_identify_count = 0;
136136
let len = self.network_state.bootnodes.len();
137137
if len < count {

resource/ckb.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ support_protocols = ["Ping", "Discovery", "Identify", "Feeler", "DisconnectMessa
135135
# [network.onion]
136136
### Enable or disable listening on the Onion network.
137137
### When set to true, CKB will accept incoming connections over Tor.
138-
### You can get the onion listening address in log, or by get_node_info RPC
138+
### You can get the onion listening address in log, or by local_node_info RPC
139139
# listen_on_onion = true
140140

141141
### The onion service will proxy incoming traffic to `p2p_listen_address`.

0 commit comments

Comments
 (0)