1use std::net::{IpAddr, SocketAddr};
7
8use alloy_rpc_types_admin::EthProtocolInfo;
9use enr::{secp256k1::SecretKey, Enr};
10use reth_eth_wire_types::{DisconnectReason, ProtocolVersion};
11use reth_network_peers::NodeRecord;
12use reth_network_types::{PeerKind, Reputation, ReputationChangeKind};
13
14use crate::{NetworkError, NetworkInfo, NetworkStatus, PeerId, PeerInfo, Peers, PeersInfo};
15
16#[derive(Debug, Clone, Default)]
20#[non_exhaustive]
21pub struct NoopNetwork;
22
23impl NetworkInfo for NoopNetwork {
24 fn local_addr(&self) -> SocketAddr {
25 (IpAddr::from(std::net::Ipv4Addr::UNSPECIFIED), 30303).into()
26 }
27
28 async fn network_status(&self) -> Result<NetworkStatus, NetworkError> {
29 Ok(NetworkStatus {
30 client_version: "reth-test".to_string(),
31 protocol_version: ProtocolVersion::V5 as u64,
32 eth_protocol_info: EthProtocolInfo {
33 difficulty: Default::default(),
34 network: 1,
35 genesis: Default::default(),
36 config: Default::default(),
37 head: Default::default(),
38 },
39 })
40 }
41
42 fn chain_id(&self) -> u64 {
43 1
45 }
46
47 fn is_syncing(&self) -> bool {
48 false
49 }
50
51 fn is_initially_syncing(&self) -> bool {
52 false
53 }
54}
55
56impl PeersInfo for NoopNetwork {
57 fn num_connected_peers(&self) -> usize {
58 0
59 }
60
61 fn local_node_record(&self) -> NodeRecord {
62 NodeRecord::new(self.local_addr(), PeerId::random())
63 }
64
65 fn local_enr(&self) -> Enr<SecretKey> {
66 let sk = SecretKey::from_slice(&[0xcd; 32]).unwrap();
67 Enr::builder().build(&sk).unwrap()
68 }
69}
70
71impl Peers for NoopNetwork {
72 fn add_trusted_peer_id(&self, _peer: PeerId) {}
73
74 fn add_peer_kind(
75 &self,
76 _peer: PeerId,
77 _kind: PeerKind,
78 _tcp_addr: SocketAddr,
79 _udp_addr: Option<SocketAddr>,
80 ) {
81 }
82
83 async fn get_peers_by_kind(&self, _kind: PeerKind) -> Result<Vec<PeerInfo>, NetworkError> {
84 Ok(vec![])
85 }
86
87 async fn get_all_peers(&self) -> Result<Vec<PeerInfo>, NetworkError> {
88 Ok(vec![])
89 }
90
91 async fn get_peer_by_id(&self, _peer_id: PeerId) -> Result<Option<PeerInfo>, NetworkError> {
92 Ok(None)
93 }
94
95 async fn get_peers_by_id(&self, _peer_id: Vec<PeerId>) -> Result<Vec<PeerInfo>, NetworkError> {
96 Ok(vec![])
97 }
98
99 fn remove_peer(&self, _peer: PeerId, _kind: PeerKind) {}
100
101 fn disconnect_peer(&self, _peer: PeerId) {}
102
103 fn disconnect_peer_with_reason(&self, _peer: PeerId, _reason: DisconnectReason) {}
104
105 fn connect_peer_kind(
106 &self,
107 _peer: PeerId,
108 _kind: PeerKind,
109 _tcp_addr: SocketAddr,
110 _udp_addr: Option<SocketAddr>,
111 ) {
112 }
113
114 fn reputation_change(&self, _peer_id: PeerId, _kind: ReputationChangeKind) {}
115
116 async fn reputation_by_id(&self, _peer_id: PeerId) -> Result<Option<Reputation>, NetworkError> {
117 Ok(None)
118 }
119}