Zebra/zebra-chain/src/serialization
Janito Vaqueiro Ferreira Filho 11b5a33651
Security: Avoid reconnecting to peers that are likely unreachable (#3030)
* Add a `Duration32::from_days` constructor

Make it simpler to construct a `Duration32` representing a certain
number of days.

* Add `MetaAddr::was_not_recently_seen` method

A helper method to check if a peer was never seen before or if it was
last seen a long time ago. This will be one of the conditions to
consider a peer as unreachable.

* Add `MetaAddr::is_probably_unreachable` method

A helper method to check if a peer should be considered unreachable. It
is considered unreachable if recent connection attempts have failed and
it was not recently seen.

If a peer is considered unreachable, Zebra shouldn't attempt to connect
to it again.

* Do not keep trying to connect to unreachable peer

A peer is probably unreachable if it was last seen a long time ago and
if it's last connection attempt failed.

* Test `was_not_recently_seen`

Redo the calculation on arbitrary `MetaAddr`s.

* Test `is_probably_unreachable`

Redo the calculation on arbitrary `MetaAddr`s.

* Test if probably unreachable peers are ignored

Given an `AddressBook` with a list of arbitrary `MetaAddr`s, check that
none of the peers listed for a reconnection is probably unreachable.

* Rename unit test to improve clarity

Remove the double negative from the name.

Co-authored-by: teor <teor@riseup.net>

* Rename constant to `MAX_RECENT_PEER_AGE`

Make the purpose of the constant clearer.

Co-authored-by: teor <teor@riseup.net>

* Rename method to `last_seen_is_recent`

Remove the double negative from the name.

* Rename method to `is_probably_reachable`

Avoid having to negate the result of the method in security critical
filter.

* Move check into `is_ready_for_connection_attempt`

Make sure the check is used in any place that requires a peer that's
ready for a connection attempt.

* Improve test documention

Describe the goal of the test better.

Co-authored-by: teor <teor@riseup.net>

* Improve `is_probably_reachable` documentation

List the conditions as bullet points.

Co-authored-by: teor <teor@riseup.net>

* Document what happens when peers have no last seen time

Co-authored-by: teor <teor@riseup.net>
2021-11-10 23:51:22 +00:00
..
tests Simplify preallocate tests (#3032) 2021-11-11 07:53:21 +10:00
arbitrary.rs Simplify preallocate tests (#3032) 2021-11-11 07:53:21 +10:00
compact_size.rs Create CompactSize64 for non-message-length fields (#3008) 2021-11-04 15:57:30 +00:00
constraint.rs Reject conflicting mempool transactions (#2765) 2021-09-28 01:03:08 +00:00
date_time.rs Security: Avoid reconnecting to peers that are likely unreachable (#3030) 2021-11-10 23:51:22 +00:00
error.rs Create CompactSize64 for non-message-length fields (#3008) 2021-11-04 15:57:30 +00:00
read_zcash.rs Refactor addr v1 serialization using a separate AddrV1 type (#3021) 2021-11-10 06:47:50 +10:00
serde_helpers.rs Rebase tidies 2021-04-30 00:48:23 -04:00
sha256d.rs Call `zebra_test::init` where needed. (#1227) 2020-11-10 10:29:25 +10:00
tests.rs Simplify preallocate tests (#3032) 2021-11-11 07:53:21 +10:00
write_zcash.rs Refactor addr v1 serialization using a separate AddrV1 type (#3021) 2021-11-10 06:47:50 +10:00
zcash_deserialize.rs Simplify preallocate tests (#3032) 2021-11-11 07:53:21 +10:00
zcash_serialize.rs Refactor addr v1 serialization using a separate AddrV1 type (#3021) 2021-11-10 06:47:50 +10:00