Zebra/zebra-network/src
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
..
address_book Security: Avoid reconnecting to peers that are likely unreachable (#3030) 2021-11-10 23:51:22 +00:00
config Use the default port for configured listen addresses with no port (#2043) 2021-04-21 23:14:29 +00:00
meta_addr Security: Avoid reconnecting to peers that are likely unreachable (#3030) 2021-11-10 23:51:22 +00:00
peer Refactor addr v1 serialization using a separate AddrV1 type (#3021) 2021-11-10 06:47:50 +10:00
peer_set Avoid listener address conflicts in network tests (#3031) 2021-11-08 11:20:13 -03:00
protocol Simplify preallocate tests (#3032) 2021-11-11 07:53:21 +10:00
address_book.rs Refactor addr v1 serialization using a separate AddrV1 type (#3021) 2021-11-10 06:47:50 +10:00
address_book_updater.rs Add unused seed peers to the AddressBook (#2974) 2021-11-04 08:34:00 -03:00
config.rs Refactor addr v1 serialization using a separate AddrV1 type (#3021) 2021-11-10 06:47:50 +10:00
constants.rs Security: Avoid reconnecting to peers that are likely unreachable (#3030) 2021-11-10 23:51:22 +00:00
isolated.rs Refactor addr v1 serialization using a separate AddrV1 type (#3021) 2021-11-10 06:47:50 +10:00
lib.rs Add unused seed peers to the AddressBook (#2974) 2021-11-04 08:34:00 -03:00
meta_addr.rs Security: Avoid reconnecting to peers that are likely unreachable (#3030) 2021-11-10 23:51:22 +00:00
peer.rs Limit the number of outbound peer connections (#2944) 2021-10-27 21:28:51 +00:00
peer_set.rs Track the number of active inbound and outbound peer connections (#2912) 2021-10-21 21:36:42 +00:00
policies.rs Fix sync algorithm. (#887) 2020-08-12 16:48:01 -07:00
protocol.rs Refactor protocol into internal, external modules. 2019-11-27 05:06:01 -05:00