ckb_network/peer_store/
mod.rs1pub mod addr_manager;
11pub mod ban_list;
12#[cfg(target_family = "wasm")]
13pub(crate) mod browser;
14mod peer_store_db;
15mod peer_store_impl;
16pub mod types;
17
18pub(crate) use crate::Behaviour;
19pub use crate::SessionType;
20use p2p::multiaddr::{Multiaddr, Protocol};
21pub use peer_store_impl::PeerStore;
22pub(crate) use peer_store_impl::required_flags_filter;
23
24pub(crate) const ADDR_COUNT_LIMIT: usize = 16384;
26const ADDR_TIMEOUT_MS: u64 = 7 * 24 * 3600 * 1000;
28pub(crate) const ADDR_TRY_TIMEOUT_MS: u64 = 3 * 24 * 3600 * 1000;
30pub(crate) const DIAL_INTERVAL: u64 = 15 * 1000;
33const ADDR_MAX_RETRIES: u32 = 3;
34const ADDR_MAX_FAILURES: u32 = 10;
35
36pub type Score = i32;
38
39#[derive(Copy, Clone, Debug)]
41pub struct PeerScoreConfig {
42 pub default_score: Score,
44 pub ban_score: Score,
46 pub ban_timeout_ms: u64,
48}
49
50impl Default for PeerScoreConfig {
51 fn default() -> Self {
52 PeerScoreConfig {
53 default_score: 100,
54 ban_score: 40,
55 ban_timeout_ms: 24 * 3600 * 1000, }
57 }
58}
59
60#[derive(Debug, Copy, Clone, Eq, PartialEq)]
62pub enum Status {
63 Connected,
65 Disconnected,
67}
68
69#[derive(Debug, Copy, Clone, Eq, PartialEq)]
71pub enum ReportResult {
72 Ok,
74 Banned,
76}
77
78impl ReportResult {
79 pub fn is_banned(self) -> bool {
81 self == ReportResult::Banned
82 }
83
84 pub fn is_ok(self) -> bool {
86 self == ReportResult::Ok
87 }
88}
89
90pub(crate) fn base_addr(addr: &Multiaddr) -> Multiaddr {
92 addr.iter()
93 .filter_map(|p| {
94 if matches!(
95 p,
96 Protocol::Ws
97 | Protocol::Wss
98 | Protocol::Memory(_)
99 | Protocol::Tls(_)
100 | Protocol::Onion3(_)
101 ) {
102 None
103 } else {
104 Some(p)
105 }
106 })
107 .collect()
108}