-
Notifications
You must be signed in to change notification settings - Fork 785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Peer cache #4574
Merged
Merged
Peer cache #4574
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d54bcb4
Headers for forward declarations
pwojcikdev 4a4f61c
Conversions for endpoint_key
pwojcikdev 379099e
Time helpers
pwojcikdev 4f5c859
Store timestamps in peer store
pwojcikdev 926bd38
Introduce `peer_cache`
pwojcikdev 2093bbb
Tests for peer cache
pwojcikdev 3f9551a
Reach out to cached peers
pwojcikdev efe4369
Test reconnecting to cached peers
pwojcikdev 1c11cbd
Fixes
pwojcikdev a107c04
Rename to `peer_history`
pwojcikdev fe01ecb
Merge branch 'develop' into cached-peers-2
pwojcikdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <nano/node/peer_cache.hpp> | ||
#include <nano/test_common/system.hpp> | ||
#include <nano/test_common/testutil.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
TEST (peer_cache, store_live) | ||
{ | ||
nano::test::system system; | ||
|
||
auto & node1 = *system.add_node (); | ||
auto & node2 = *system.add_node (); | ||
auto & node3 = *system.add_node (); | ||
|
||
ASSERT_TIMELY (5s, node1.peer_cache.exists (node2.network.endpoint ())); | ||
ASSERT_TIMELY (5s, node1.peer_cache.exists (node3.network.endpoint ())); | ||
|
||
ASSERT_TIMELY (5s, node2.peer_cache.exists (node1.network.endpoint ())); | ||
ASSERT_TIMELY (5s, node2.peer_cache.exists (node3.network.endpoint ())); | ||
|
||
ASSERT_TIMELY (5s, node3.peer_cache.exists (node1.network.endpoint ())); | ||
ASSERT_TIMELY (5s, node3.peer_cache.exists (node2.network.endpoint ())); | ||
} | ||
|
||
TEST (peer_cache, erase_old) | ||
{ | ||
nano::test::system system; | ||
|
||
auto & node1 = *system.add_node (); | ||
auto & node2 = *system.add_node (); | ||
|
||
ASSERT_TIMELY (5s, node1.peer_cache.exists (node2.network.endpoint ())); | ||
ASSERT_TIMELY (5s, node2.peer_cache.exists (node1.network.endpoint ())); | ||
|
||
// Endpoint won't be available after node is stopped | ||
auto node2_endpoint = node2.network.endpoint (); | ||
|
||
system.stop_node (node2); | ||
|
||
auto cached1 = node1.peer_cache.cached_peers (); | ||
ASSERT_EQ (cached1.size (), 1); | ||
ASSERT_EQ (cached1[0], node2_endpoint); | ||
|
||
ASSERT_TIMELY (5s, !node1.peer_cache.exists (node2_endpoint)); | ||
|
||
auto cached2 = node1.peer_cache.cached_peers (); | ||
ASSERT_EQ (cached2.size (), 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
#include <nano/boost/asio/ip/tcp.hpp> | ||
#include <nano/boost/asio/ip/udp.hpp> | ||
|
||
namespace nano | ||
{ | ||
using endpoint = boost::asio::ip::udp::endpoint; | ||
using tcp_endpoint = boost::asio::ip::tcp::endpoint; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include <nano/store/fwd.hpp> | ||
|
||
namespace nano | ||
{ | ||
class logger; | ||
class node; | ||
class network; | ||
class stats; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this counter be loop_reachout_cached?