Skip to content

Commit 83cbd61

Browse files
committed
Update system integration.
1 parent 76ffbbb commit 83cbd61

File tree

9 files changed

+126
-109
lines changed

9 files changed

+126
-109
lines changed

src/zmq/authenticator.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ namespace libbitcoin {
3333
namespace protocol {
3434
namespace zmq {
3535

36+
using namespace bc::system;
37+
3638
// ZAP endpoint, see: rfc.zeromq.org/spec:27/ZAP
37-
const system::config::endpoint authenticator::endpoint(
39+
const config::endpoint authenticator::endpoint(
3840
"inproc://zeromq.zap.01");
3941

4042
// There may be only one authenticator per process.
41-
authenticator::authenticator(system::thread_priority priority)
43+
authenticator::authenticator(thread_priority priority)
4244
: worker(priority),
4345
context_(false),
4446
require_allow_(false)
@@ -61,7 +63,7 @@ bool authenticator::start()
6163
// Context is thread safe, this critical section is for start atomicity.
6264
///////////////////////////////////////////////////////////////////////////
6365
// Critical Section
64-
system::unique_lock lock(stop_mutex_);
66+
unique_lock lock(stop_mutex_);
6567

6668
return context_.start() && worker::start();
6769
///////////////////////////////////////////////////////////////////////////
@@ -72,7 +74,7 @@ bool authenticator::stop()
7274
// Context is thread safe, this critical section is for stop atomicity.
7375
///////////////////////////////////////////////////////////////////////////
7476
// Critical Section
75-
system::unique_lock lock(stop_mutex_);
77+
unique_lock lock(stop_mutex_);
7678

7779
// Stop the context first in case a blocking proxy is in use.
7880
return context_.stop() && worker::stop();
@@ -85,7 +87,7 @@ void authenticator::work()
8587
{
8688
socket replier(context_, zmq::socket::role::replier);
8789

88-
if (!started(replier.bind(endpoint) == system::error::success))
90+
if (!started(replier.bind(endpoint) == error::success))
8991
return;
9092

9193
poller poller;
@@ -106,7 +108,7 @@ void authenticator::work()
106108
message request;
107109
auto ec = replier.receive(request);
108110

109-
if (ec != system::error::success || request.size() < 6)
111+
if (ec != error::success || request.size() < 6)
110112
{
111113
status_code = "500";
112114
status_text = "Internal error.";
@@ -171,7 +173,7 @@ void authenticator::work()
171173
}
172174
else
173175
{
174-
system::hash_digest public_key;
176+
hash_digest public_key;
175177

176178
if (!request.dequeue(public_key))
177179
{
@@ -265,11 +267,11 @@ bool authenticator::apply(socket& socket, const std::string& domain,
265267
}
266268

267269
void authenticator::set_private_key(
268-
const system::config::sodium& private_key)
270+
const config::sodium& private_key)
269271
{
270272
///////////////////////////////////////////////////////////////////////////
271273
// Critical Section
272-
system::unique_lock lock(property_mutex_);
274+
unique_lock lock(property_mutex_);
273275

274276
private_key_ = private_key;
275277
///////////////////////////////////////////////////////////////////////////
@@ -279,7 +281,7 @@ bool authenticator::allowed_address(const std::string& ip_address) const
279281
{
280282
///////////////////////////////////////////////////////////////////////////
281283
// Critical Section
282-
system::shared_lock lock(property_mutex_);
284+
shared_lock lock(property_mutex_);
283285

284286
const auto entry = adresses_.find(ip_address);
285287
const auto found = entry != adresses_.end();
@@ -288,11 +290,11 @@ bool authenticator::allowed_address(const std::string& ip_address) const
288290
///////////////////////////////////////////////////////////////////////////
289291
}
290292

291-
bool authenticator::allowed_key(const system::hash_digest& public_key) const
293+
bool authenticator::allowed_key(const hash_digest& public_key) const
292294
{
293295
///////////////////////////////////////////////////////////////////////////
294296
// Critical Section
295-
system::shared_lock lock(property_mutex_);
297+
shared_lock lock(property_mutex_);
296298

297299
return keys_.empty() || keys_.find(public_key) != keys_.end();
298300
///////////////////////////////////////////////////////////////////////////
@@ -302,27 +304,27 @@ bool authenticator::allowed_weak(const std::string& domain) const
302304
{
303305
///////////////////////////////////////////////////////////////////////////
304306
// Critical Section
305-
system::shared_lock lock(property_mutex_);
307+
shared_lock lock(property_mutex_);
306308

307309
return weak_domains_.find(domain) != weak_domains_.end();
308310
///////////////////////////////////////////////////////////////////////////
309311
}
310312

311-
void authenticator::allow(const system::hash_digest& public_key)
313+
void authenticator::allow(const hash_digest& public_key)
312314
{
313315
///////////////////////////////////////////////////////////////////////////
314316
// Critical Section
315-
system::unique_lock lock(property_mutex_);
317+
unique_lock lock(property_mutex_);
316318

317319
keys_.emplace(public_key);
318320
///////////////////////////////////////////////////////////////////////////
319321
}
320322

321-
void authenticator::allow(const system::config::authority& address)
323+
void authenticator::allow(const config::authority& address)
322324
{
323325
///////////////////////////////////////////////////////////////////////////
324326
// Critical Section
325-
system::unique_lock lock(property_mutex_);
327+
unique_lock lock(property_mutex_);
326328

327329
require_allow_ = true;
328330

@@ -331,11 +333,11 @@ void authenticator::allow(const system::config::authority& address)
331333
///////////////////////////////////////////////////////////////////////////
332334
}
333335

334-
void authenticator::deny(const system::config::authority& address)
336+
void authenticator::deny(const config::authority& address)
335337
{
336338
///////////////////////////////////////////////////////////////////////////
337339
// Critical Section
338-
system::unique_lock lock(property_mutex_);
340+
unique_lock lock(property_mutex_);
339341

340342
// Denial is effective independent of whitelisting.
341343
// Due to emplace behavior, first writer wins allow/deny conflict.

src/zmq/certificate.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace libbitcoin {
2626
namespace protocol {
2727
namespace zmq {
2828

29+
using namespace bc::system;
30+
2931
static constexpr int32_t zmq_fail = -1;
3032
static constexpr size_t zmq_encoded_key_size = 40;
3133

@@ -36,7 +38,7 @@ certificate::certificate()
3638
}
3739

3840
// Full key space.
39-
certificate::certificate(const system::config::sodium& private_key)
41+
certificate::certificate(const config::sodium& private_key)
4042
{
4143
if (!private_key)
4244
{
@@ -49,8 +51,8 @@ certificate::certificate(const system::config::sodium& private_key)
4951
private_ = private_key;
5052
}
5153

52-
bool certificate::derive(system::config::sodium& out_public,
53-
const system::config::sodium& private_key)
54+
bool certificate::derive(config::sodium& out_public,
55+
const config::sodium& private_key)
5456
{
5557
if (!private_key)
5658
return false;
@@ -61,7 +63,7 @@ bool certificate::derive(system::config::sodium& out_public,
6163
if (zmq_curve_public(public_key, key.data()) == zmq_fail)
6264
return false;
6365

64-
out_public = system::config::sodium(public_key);
66+
out_public = config::sodium(public_key);
6567
return out_public;
6668
}
6769

@@ -72,8 +74,8 @@ static inline bool ok_setting(const std::string& key)
7274
return key.find_first_of('#') == std::string::npos;
7375
}
7476

75-
bool certificate::create(system::config::sodium& out_public,
76-
system::config::sodium& out_private, bool setting)
77+
bool certificate::create(config::sodium& out_public,
78+
config::sodium& out_private, bool setting)
7779
{
7880
// Loop until neither key's base85 encoding includes the # character.
7981
// This ensures that the value can be used in libbitcoin settings files.
@@ -88,8 +90,8 @@ bool certificate::create(system::config::sodium& out_public,
8890

8991
if (!setting || (ok_setting(public_key) && ok_setting(private_key)))
9092
{
91-
out_public = system::config::sodium(public_key);
92-
out_private = system::config::sodium(private_key);
93+
out_public = config::sodium(public_key);
94+
out_private = config::sodium(private_key);
9395
return out_public;
9496
}
9597
}
@@ -102,12 +104,12 @@ certificate::operator bool() const
102104
return public_;
103105
}
104106

105-
const system::config::sodium& certificate::public_key() const
107+
const config::sodium& certificate::public_key() const
106108
{
107109
return public_;
108110
}
109111

110-
const system::config::sodium& certificate::private_key() const
112+
const config::sodium& certificate::private_key() const
111113
{
112114
return private_;
113115
}

src/zmq/context.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace libbitcoin {
2626
namespace protocol {
2727
namespace zmq {
2828

29+
using namespace bc::system;
30+
2931
static constexpr int32_t zmq_fail = -1;
3032

3133
context::context(bool started)
@@ -45,7 +47,7 @@ bool context::start()
4547
{
4648
///////////////////////////////////////////////////////////////////////////
4749
// Critical Section
48-
system::unique_lock lock(mutex_);
50+
unique_lock lock(mutex_);
4951

5052
if (self_ != nullptr)
5153
return false;
@@ -60,7 +62,7 @@ bool context::stop()
6062
{
6163
///////////////////////////////////////////////////////////////////////////
6264
// Critical Section
63-
system::unique_lock lock(mutex_);
65+
unique_lock lock(mutex_);
6466

6567
if (self_ == nullptr)
6668
return true;

src/zmq/frame.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ namespace libbitcoin {
3030
namespace protocol {
3131
namespace zmq {
3232

33+
using namespace bc::system;
34+
3335
// If ZMQ_DONTWAIT is set we fail on busy socket.
3436
// This would happen if a message is being read when we try to send.
3537
static auto constexpr wait_flag = 0;
@@ -42,7 +44,7 @@ frame::frame()
4244
}
4345

4446
// Use for sending.
45-
frame::frame(const system::data_chunk& data)
47+
frame::frame(const data_chunk& data)
4648
: more_(false), valid_(initialize(data))
4749
{
4850
}
@@ -53,7 +55,7 @@ frame::~frame()
5355
}
5456

5557
// private
56-
bool frame::initialize(const system::data_chunk& data)
58+
bool frame::initialize(const data_chunk& data)
5759
{
5860
const auto buffer = reinterpret_cast<zmq_msg_t*>(&message_);
5961

@@ -90,7 +92,7 @@ bool frame::set_more(socket& socket)
9092
return true;
9193
}
9294

93-
system::data_chunk frame::payload() const
95+
data_chunk frame::payload() const
9496
{
9597
const auto buffer = reinterpret_cast<zmq_msg_t*>(&message_);
9698

@@ -103,27 +105,27 @@ system::data_chunk frame::payload() const
103105
}
104106

105107
// Must be called on the socket thread.
106-
system::code frame::receive(socket& socket)
108+
code frame::receive(socket& socket)
107109
{
108110
if (!valid_)
109-
return system::error::operation_failed;
111+
return error::operation_failed;
110112

111113
const auto buffer = reinterpret_cast<zmq_msg_t*>(&message_);
112114
const auto result = zmq_msg_recv(buffer, socket.self(), wait_flag)
113115
!= zmq_fail && set_more(socket);
114-
return result ? system::error::success : get_last_error();
116+
return result ? error::success : get_last_error();
115117
}
116118

117119
// Must be called on the socket thread.
118-
system::code frame::send(socket& socket, bool last)
120+
code frame::send(socket& socket, bool last)
119121
{
120122
if (!valid_)
121-
return system::error::operation_failed;
123+
return error::operation_failed;
122124

123125
const int flags = (last ? 0 : ZMQ_SNDMORE) | wait_flag;
124126
const auto buffer = reinterpret_cast<zmq_msg_t*>(&message_);
125127
const auto result = zmq_msg_send(buffer, socket.self(), flags) != zmq_fail;
126-
return result ? system::error::success : get_last_error();
128+
return result ? error::success : get_last_error();
127129
}
128130

129131
// private

0 commit comments

Comments
 (0)