Skip to content

Commit 880bddb

Browse files
authored
Merge pull request libbitcoin#1098 from evoskuil/master
Expose start time and channel counts to protocols.
2 parents a9a8a35 + 879a6fa commit 880bddb

7 files changed

Lines changed: 61 additions & 2 deletions

File tree

include/bitcoin/node/full_node.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ class BCN_API full_node
145145
/// The confirmed chain is confirmed to maximum height or is current.
146146
virtual bool is_recent() const NOEXCEPT;
147147

148+
/// Zulu time at which the node started.
149+
virtual time_t start_time() const NOEXCEPT;
150+
148151
/// Methods.
149152
/// -----------------------------------------------------------------------
150153

@@ -180,6 +183,7 @@ class BCN_API full_node
180183

181184
// These are thread safe.
182185
const configuration& config_;
186+
const time_t start_time_;
183187
query& query_;
184188

185189
// These are protected by strand.

include/bitcoin/node/protocols/protocol.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ class BCN_API protocol
6868
/// The candidate|confirmed chain is current.
6969
virtual bool is_current_chain(bool confirmed) const NOEXCEPT;
7070

71+
/// Zulu time at which the node started.
72+
virtual time_t start_time() const NOEXCEPT;
73+
74+
/// The number of peer channels (counted, not quiet).
75+
virtual size_t channel_count() const NOEXCEPT;
76+
77+
/// The number of inbound peer channels (counted, not quiet).
78+
virtual size_t inbound_channel_count() const NOEXCEPT;
79+
7180
/// Methods.
7281
/// -----------------------------------------------------------------------
7382

include/bitcoin/node/sessions/session.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ class BCN_API session
109109
/// The confirmed chain is confirmed to maximum height or is current.
110110
virtual bool is_recent() const NOEXCEPT;
111111

112+
/// Zulu time at which the node started.
113+
virtual time_t start_time() const NOEXCEPT;
114+
115+
/// The number of peer channels (counted, not quiet).
116+
virtual size_t channel_count() const NOEXCEPT;
117+
118+
/// The number of inbound peer channels (counted, not quiet).
119+
virtual size_t inbound_channel_count() const NOEXCEPT;
120+
112121
protected:
113122

114123
/// Constructors.

src/chasers/chaser_estimate.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ bool chaser_estimate::handle_chase(const code&, chase event_,
150150
{
151151
BC_ASSERT(std::holds_alternative<header_t>(value));
152152
POST(do_reorganized, std::get<header_t>(value));
153-
break;
154153
}
154+
155+
break;
155156
}
156157
case chase::stop:
157158
{

src/full_node.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ full_node::full_node(query& query, const configuration& configuration,
3939
const logger& log) NOEXCEPT
4040
: net(configuration.network, log),
4141
config_(configuration),
42+
start_time_(zulu_time()),
4243
query_(query),
4344
chaser_block_(*this),
4445
chaser_header_(*this),
@@ -431,13 +432,18 @@ bool full_node::is_current_header(const header_link& link) const NOEXCEPT
431432

432433
bool full_node::is_recent() const NOEXCEPT
433434
{
434-
if (is_nonzero(config_.node.maximum_height) &&
435+
if (is_nonzero(config_.node.maximum_height) &&
435436
(query_.get_top_confirmed() >= config_.node.maximum_height))
436437
return true;
437438

438439
return is_current_chain(true);
439440
}
440441

442+
time_t full_node::start_time() const NOEXCEPT
443+
{
444+
return start_time_;
445+
}
446+
441447
// Methods.
442448
// ----------------------------------------------------------------------------
443449

src/protocols/protocol.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ bool protocol::is_current_chain(bool confirmed) const NOEXCEPT
6666
return session_->is_current_chain(confirmed);
6767
}
6868

69+
time_t protocol::start_time() const NOEXCEPT
70+
{
71+
return session_->start_time();
72+
}
73+
74+
size_t protocol::channel_count() const NOEXCEPT
75+
{
76+
return session_->channel_count();
77+
}
78+
79+
size_t protocol::inbound_channel_count() const NOEXCEPT
80+
{
81+
return session_->inbound_channel_count();
82+
}
83+
6984
// Methods.
7085
// ----------------------------------------------------------------------------
7186

src/sessions/session.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ bool session::is_recent() const NOEXCEPT
160160
return node_.is_recent();
161161
}
162162

163+
time_t session::start_time() const NOEXCEPT
164+
{
165+
return node_.start_time();
166+
}
167+
168+
size_t session::channel_count() const NOEXCEPT
169+
{
170+
return node_.channel_count();
171+
}
172+
173+
size_t session::inbound_channel_count() const NOEXCEPT
174+
{
175+
return node_.inbound_channel_count();
176+
}
177+
163178
BC_POP_WARNING()
164179

165180
} // namespace node

0 commit comments

Comments
 (0)