forked from nanocurrency/nano-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03da746
commit ec45d30
Showing
6 changed files
with
70 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include <nano/node/vote_broadcaster.hpp> | ||
|
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,61 @@ | ||
#pragma once | ||
|
||
#include <nano/lib/locks.hpp> | ||
#include <nano/lib/numbers.hpp> | ||
#include <nano/node/rep_tiers.hpp> | ||
#include <nano/secure/common.hpp> | ||
|
||
#include <atomic> | ||
#include <chrono> | ||
#include <condition_variable> | ||
#include <thread> | ||
|
||
namespace nano | ||
{ | ||
class node; | ||
class stats; | ||
} | ||
|
||
namespace nano | ||
{ | ||
class vote_broadcaster_config final | ||
{ | ||
public: | ||
size_t max_recently_broadcasted{ 1024 * 32 }; | ||
}; | ||
|
||
class vote_broadcaster final | ||
{ | ||
public: | ||
explicit vote_broadcaster (nano::node &); | ||
~vote_broadcaster (); | ||
|
||
void start (); | ||
void stop (); | ||
|
||
bool rebroadcast (std::shared_ptr<nano::vote> const & vote, nano::rep_tier tier); | ||
bool local (std::shared_ptr<nano::vote> const & vote); | ||
|
||
private: // Dependencies | ||
nano::vote_broadcaster_config const & config; | ||
nano::node & node; | ||
nano::stats & stats; | ||
|
||
private: | ||
void run (); | ||
|
||
private: | ||
class recently_broadcasted_entry | ||
{ | ||
std::map<nano::account, uint64_t> representatives; // <representative account, vote timestamp> | ||
}; | ||
|
||
std::unordered_map<nano::block_hash, recently_broadcasted_entry> recently_broadcasted; | ||
|
||
private: | ||
std::atomic<bool> stopped{ false }; | ||
nano::condition_variable condition; | ||
mutable nano::mutex mutex; | ||
std::thread thread; | ||
}; | ||
} |