ckb_network/peer_store/
mod.rs1pub mod addr_manager;
11mod anchors;
12pub mod ban_list;
13#[cfg(target_family = "wasm")]
14pub(crate) mod browser;
15mod peer_store_db;
16mod peer_store_impl;
17pub mod types;
18
19pub(crate) use crate::Behaviour;
20pub use crate::SessionType;
21use p2p::multiaddr::{Multiaddr, Protocol};
22pub use peer_store_impl::PeerStore;
23pub(crate) use peer_store_impl::required_flags_filter;
24
25pub(crate) const ADDR_COUNT_LIMIT: usize = 16384;
27const ADDR_TIMEOUT_MS: u64 = 7 * 24 * 3600 * 1000;
29pub(crate) const ADDR_TRY_TIMEOUT_MS: u64 = 3 * 24 * 3600 * 1000;
31pub(crate) const DIAL_INTERVAL: u64 = 15 * 1000;
34const ADDR_MAX_RETRIES: u32 = 3;
35const ADDR_MAX_FAILURES: u32 = 10;
36
37pub type Score = i32;
39
40#[derive(Copy, Clone, Debug)]
42pub struct PeerScoreConfig {
43 pub default_score: Score,
45 pub ban_score: Score,
47 pub ban_timeout_ms: u64,
49}
50
51impl Default for PeerScoreConfig {
52 fn default() -> Self {
53 PeerScoreConfig {
54 default_score: 100,
55 ban_score: 40,
56 ban_timeout_ms: 24 * 3600 * 1000, }
58 }
59}
60
61#[derive(Debug, Copy, Clone, Eq, PartialEq)]
63pub enum Status {
64 Connected,
66 Disconnected,
68}
69
70#[derive(Debug, Copy, Clone, Eq, PartialEq)]
72pub enum ReportResult {
73 Ok,
75 Banned,
77}
78
79impl ReportResult {
80 pub fn is_banned(self) -> bool {
82 self == ReportResult::Banned
83 }
84
85 pub fn is_ok(self) -> bool {
87 self == ReportResult::Ok
88 }
89}
90
91pub(crate) fn base_addr(addr: &Multiaddr) -> Multiaddr {
93 addr.iter()
94 .filter_map(|p| {
95 if matches!(
96 p,
97 Protocol::Ws | Protocol::Wss | Protocol::Memory(_) | Protocol::Tls(_)
98 ) {
99 None
100 } else {
101 Some(p)
102 }
103 })
104 .collect()
105}