-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #576 from evoskuil/master
Style, refactor to simplify protocol.
- Loading branch information
Showing
12 changed files
with
347 additions
and
206 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
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,76 @@ | ||
/** | ||
* Copyright (c) 2011-2023 libbitcoin developers (see AUTHORS) | ||
* | ||
* This file is part of libbitcoin. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#ifndef LIBBITCOIN_NODE_PROTOCOL_PERFORMER_HPP | ||
#define LIBBITCOIN_NODE_PROTOCOL_PERFORMER_HPP | ||
|
||
#include <bitcoin/network.hpp> | ||
#include <bitcoin/node/define.hpp> | ||
#include <bitcoin/node/protocols/protocol.hpp> | ||
|
||
namespace libbitcoin { | ||
namespace node { | ||
|
||
/// Abstract base protocol for performance standard deviation measurement. | ||
class BCN_API protocol_performer | ||
: public node::protocol, | ||
protected network::tracker<protocol_performer> | ||
{ | ||
public: | ||
virtual void start_performance() NOEXCEPT; | ||
virtual void pause_performance() NOEXCEPT; | ||
virtual void stop_performance() NOEXCEPT; | ||
virtual void count(size_t bytes) NOEXCEPT; | ||
|
||
protected: | ||
template <typename Session> | ||
protocol_performer(Session& session, const channel_ptr& channel, | ||
bool enable) NOEXCEPT | ||
: node::protocol(session, channel), | ||
network::tracker<protocol_performer>(session.log), | ||
use_deviation_(session.config().node.allowed_deviation > 0.0), | ||
drop_stall_(enable && | ||
to_bool(session.config().node.sample_period_seconds)), | ||
performance_timer_(std::make_shared<network::deadline>(session.log, | ||
channel->strand(), session.config().node.sample_period())) | ||
{ | ||
} | ||
|
||
virtual bool is_idle() const NOEXCEPT = 0; | ||
|
||
private: | ||
void handle_performance_timer(const code& ec) NOEXCEPT; | ||
void handle_send_performance(const code& ec) NOEXCEPT; | ||
void do_handle_performance(const code& ec) NOEXCEPT; | ||
|
||
void send_performance(uint64_t rate) NOEXCEPT; | ||
|
||
// These are thread safe. | ||
const bool use_deviation_; | ||
const bool drop_stall_; | ||
|
||
// These are protected by strand. | ||
uint64_t bytes_{ zero }; | ||
network::steady_clock::time_point start_{}; | ||
network::deadline::ptr performance_timer_; | ||
}; | ||
|
||
} // namespace node | ||
} // namespace libbitcoin | ||
|
||
#endif |
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
Oops, something went wrong.