Struct bitcoin_addrman::AddrManImpl
source · pub struct AddrManImpl {
pub cs: Mutex<AddrManInner>,
pub n_key: u256,
pub tried_collisions: HashSet<i32>,
pub consistency_check_ratio: i32,
pub asmap: Vec<bool>,
}
Fields§
§cs: Mutex<AddrManInner>
| A mutex to protect the inner data structures. |
n_key: u256
| secret key to randomize bucket select | with |
tried_collisions: HashSet<i32>
| Holds addrs inserted into tried table that | collide with existing | entries. Test-before-evict discipline used | to resolve these collisions.
consistency_check_ratio: i32
| Perform consistency checks every | m_consistency_check_ratio operations (if | non-zero). |
asmap: Vec<bool>
| Compressed IP->ASN mapping, loaded from | a file when a node starts. | | Should be always empty if no file was | provided. | | This mapping is then used for bucketing | nodes in Addrman. | | If asmap is provided, nodes will be | bucketed by AS they belong to, in order to | make impossible for a node to connect to | several nodes hosted in a single AS. | | This is done in response to Erebus attack, | but also to generally diversify the | connections every node creates, especially | useful when a large fraction of nodes | operate under a couple of cloud providers. | | If a new asmap was provided, the existing | records would be re-bucketed accordingly.
Implementations§
source§impl AddrManImpl
impl AddrManImpl
pub fn new( asmap: Vec<bool>, deterministic: bool, consistency_check_ratio: i32 ) -> Self
pub fn len(&self) -> usize
pub fn add( &mut self, addrs: &Vec<Address>, source: &NetAddr, n_time_penalty: i64 ) -> bool
pub fn good(&mut self, addr: &Service, n_time: i64)
pub fn attempt(&mut self, addr: &Service, count_failure: bool, n_time: i64)
pub fn resolve_collisions(&mut self)
pub fn select_tried_collision(&mut self) -> (Address, i64)
pub fn select(&self, new_only: bool) -> (Address, i64)
pub fn get_addr( &self, max_addresses: usize, max_pct: usize, network: Option<Network> ) -> Vec<Address>
pub fn connected(&mut self, addr: &Service, n_time: i64)
pub fn set_services(&mut self, addr: &Service, n_services: ServiceFlags)
pub fn get_asmap(&self) -> &Vec<bool>
source§impl AddrManImpl
impl AddrManImpl
sourcepub fn serialize<Stream: GetVersion + GetType>(&self, stream: &mut Stream)
pub fn serialize<Stream: GetVersion + GetType>(&self, stream: &mut Stream)
| Serialized format.
|
| - format version byte (@see Format
)
|
| - lowest compatible format version
| byte. This is used to help old software
| decide whether to parse the file. For
| example:
| - Bitcoin Core version N knows how to
| parse up to format=3. If a new format=4
| is introduced in version N+1 that is
| compatible with format=3 and it is
| known that version N will be able to
| parse it, then version N+1 will write
| (format=4, lowest_compatible=3) in the
| first two bytes of the file, and so
| version N will still try to parse it.
| - Bitcoin Core version N+2 introduces
| a new incompatible format=5. It will
| write (format=5, lowest_compatible=5)
| and so any versions that do not know
| how to parse format=5 will not try to
| read the file.
|
| - nKey
| - n_new
| - nTried
| - number of “new” buckets XOR 230
| - all new addresses (total count: n_new)
| - all tried addresses (total count: nTried)
| - for each new bucket:
| - number of elements
| - for each element: index in the
| serialized “all new addresses”
|
| - asmap checksum
|
| 230 is xorred with the number of buckets
| to make addrman deserializer v0 detect it
| as incompatible. This is necessary because
| it did not check the version number on
| deserialization.
|
| vvNew, vvTried, mapInfo, mapAddr and
| vRandom are never encoded explicitly; they
| are instead reconstructed from the other
| information.
|
| This format is more complex, but
| significantly smaller (at most 1.5 MiB),
| and supports changes to the ADDRMAN_
| parameters without breaking the on-disk
| structure.
|
| We don’t use SERIALIZE_METHODS since the
| serialization and deserialization code has
| very little in common.