Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ test_libbitcoin_protocol_test_LDADD = src/libbitcoin-protocol.la ${boost_unit_te
test_libbitcoin_protocol_test_SOURCES = \
test/converter.cpp \
test/main.cpp \
test/protocol.cpp \
test/zmq/ironhouse2.cpp \
test/examples/authenticator_example.cpp \
test/examples/poller_example.cpp \
test/zmq/authenticator.cpp \
test/zmq/certificate.cpp \
test/zmq/context.cpp \
test/zmq/frame.cpp \
test/zmq/message.cpp \
test/zmq/poller.cpp \
test/zmq/zmq.cpp
test/zmq/socket.cpp

endif WITH_TESTS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@
</ImportGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\test\converter.cpp" />
<ClCompile Include="..\..\..\..\test\examples\authenticator_example.cpp" />
<ClCompile Include="..\..\..\..\test\examples\poller_example.cpp" />
<ClCompile Include="..\..\..\..\test\main.cpp" />
<ClCompile Include="..\..\..\..\test\protocol.cpp" />
<ClCompile Include="..\..\..\..\test\zmq\ironhouse2.cpp" />
<ClCompile Include="..\..\..\..\test\zmq\authenticator.cpp" />
<ClCompile Include="..\..\..\..\test\zmq\certificate.cpp" />
<ClCompile Include="..\..\..\..\test\zmq\context.cpp" />
<ClCompile Include="..\..\..\..\test\zmq\frame.cpp" />
<ClCompile Include="..\..\..\..\test\zmq\message.cpp" />
<ClCompile Include="..\..\..\..\test\zmq\poller.cpp" />
<ClCompile Include="..\..\..\..\test\zmq\zmq.cpp" />
<ClCompile Include="..\..\..\..\test\zmq\socket.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,43 @@
<Filter Include="src\zmq">
<UniqueIdentifier>{be07d12d-9dae-4731-8b0d-acdec8ab7968}</UniqueIdentifier>
</Filter>
<Filter Include="src\examples">
<UniqueIdentifier>{cb493992-f913-4264-a0f1-33913ccc69e5}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\test\main.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\protocol.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\converter.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\zmq\zmq.cpp">
<ClCompile Include="..\..\..\..\test\zmq\context.cpp">
<Filter>src\zmq</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\zmq\ironhouse2.cpp">
<ClCompile Include="..\..\..\..\test\zmq\frame.cpp">
<Filter>src\zmq</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\zmq\message.cpp">
<Filter>src\zmq</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\zmq\poller.cpp">
<Filter>src\zmq</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\zmq\socket.cpp">
<Filter>src\zmq</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\zmq\authenticator.cpp">
<Filter>src\zmq</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\zmq\certificate.cpp">
<Filter>src\zmq</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\examples\authenticator_example.cpp">
<Filter>src\examples</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\examples\poller_example.cpp">
<Filter>src\examples</Filter>
</ClCompile>
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions include/bitcoin/protocol/zmq/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BCP_API context
context(const context&) = delete;
void operator=(const context&) = delete;

/// True if the context construction was successful.
/// True if the context is valid.
operator const bool() const;

/// The underlying zeromq context.
Expand All @@ -57,7 +57,6 @@ class BCP_API context
bool stop();

private:
int32_t threads_;
void* self_;
};

Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/protocol/zmq/socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class BCP_API socket
/// Free socket resources.
virtual ~socket();

/// True if there is an encapsultaed zeromq socket.
/// True if the socket is valid.
operator const bool() const;

/// The underlying zeromq socket.
Expand Down
2 changes: 1 addition & 1 deletion libbitcoin_protocol_test_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Define tests and options.
#==============================================================================
BOOST_UNIT_TEST_OPTIONS=\
"--run_test=* "\
"--run_test=authenticator_tests,certificate_tests,context_tests,frame_tests,message_tests,poller_tests,socket_tests "\
"--show_progress=no "\
"--detect_memory_leak=0 "\
"--report_level=no "\
Expand Down
4 changes: 4 additions & 0 deletions src/packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* 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/>.
*/
#ifdef LIBBITCOIN_VERSION4

#include <bitcoin/protocol/packet.hpp>

#include <bitcoin/bitcoin.hpp>
Expand Down Expand Up @@ -88,3 +90,5 @@ bool packet::send(zmq::socket& socket)

}
}

#endif
2 changes: 1 addition & 1 deletion src/zmq/certificate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bool certificate::create(std::string& out_public, std::string& out_private,
if (zmq_curve_keypair(public_key, private_key) == zmq_fail)
return false;

if (!setting || (ok_setting(public_key) && ok_setting(private_key)))
if (!setting || ((ok_setting(public_key) && ok_setting(private_key))))
{
out_public = public_key;
out_private = private_key;
Expand Down
10 changes: 6 additions & 4 deletions src/zmq/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ namespace protocol {
namespace zmq {

static constexpr int32_t zmq_fail = -1;
static constexpr int32_t zmq_io_threads = 1;

context::context()
: threads_(zmq_io_threads),
self_(zmq_init(threads_))
: self_(zmq_ctx_new())
{
}

Expand All @@ -41,6 +39,8 @@ context::~context()
stop();
}

// This could be made non-blocking by using zmq_ctx_shutdown here and
// zmq_ctx_term in a close method (invoked from the destructor).
bool context::stop()
{
if (self() == nullptr)
Expand All @@ -49,7 +49,9 @@ bool context::stop()
// This aborts blocking operations but blocks here until either each socket
// in the context is explicitly closed.
// It is possible for this to fail due to signal interrupt.
return zmq_term(self_) != zmq_fail;
const auto result = zmq_ctx_term(self_) != zmq_fail;
self_ = nullptr;
return result;
}

context::operator const bool() const
Expand Down
10 changes: 5 additions & 5 deletions src/zmq/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ bool socket::stop()
return closed;
}

socket::operator const bool() const
{
return socket_ != nullptr;
}

void socket::assign(socket&& other)
{
// Free any existing socket resources.
Expand Down Expand Up @@ -174,11 +179,6 @@ socket::identifier socket::id() const
return reinterpret_cast<socket::identifier>(socket_);
}

socket::operator const bool() const
{
return socket_ != nullptr;
}

} // namespace zmq
} // namespace protocol
} // namespace libbitcoin
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ void client_task(const std::string& client_private_key,
puts("Ironhouse test OK");
}

int ironhouse2_example()
// TODO: move to test case.
int authenticator_example()
{
static const auto localhost = config::authority("127.0.0.1");

Expand Down
75 changes: 75 additions & 0 deletions test/examples/poller_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Copyright (c) 2011-2015 libbitcoin developers (see AUTHORS)
*
* This file is part of libbitcoin-protocol.
*
* libbitcoin-protocol is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License with
* additional permissions to the one published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version. For more information see LICENSE.
*
* 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/>.
*/
#include <string>
#include <bitcoin/protocol.hpp>

using namespace bc;
using namespace bc::protocol;

// TODO: move to test case.
int poller_example()
{
zmq::context context;
assert(context);

// Create a few sockets
zmq::socket vent(context, zmq::socket::role::pusher);
auto result = vent.bind("tcp://*:9000");
assert(result);

zmq::socket sink(context, zmq::socket::role::puller);
result = sink.connect("tcp://localhost:9000");
assert(result);

zmq::socket bowl(context, zmq::socket::role::puller);
zmq::socket dish(context, zmq::socket::role::puller);

// Set-up poller.
zmq::poller poller;
poller.add(bowl);
poller.add(sink);
poller.add(dish);

const std::string hello = "Hello, World";

// Build and send the message.
zmq::message message;
message.enqueue(hello);
result = message.send(vent);
assert(result);

// We expect a message only on the sink.
const auto id = poller.wait(-1);
assert(id == sink.id());
assert(!poller.expired());
assert(!poller.terminated());

// Receive the message.
result = message.receive(sink);
assert(result);

// Check the size.
assert(message.size() == 1);

// Check the value.
const auto payload = message.dequeue_text();
assert(payload == hello);
return 0;
}
30 changes: 30 additions & 0 deletions test/zmq/authenticator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2016 libbitcoin developers (see AUTHORS)
*
* This file is part of libbitcoin-protocol.
*
* libbitcoin-protocol is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License with
* additional permissions to the one published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version. For more information see LICENSE.
*
* 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/>.
*/
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test_suite.hpp>
#include <bitcoin/protocol.hpp>

BOOST_AUTO_TEST_SUITE(authenticator_tests)

BOOST_AUTO_TEST_CASE(authenticator_test)
{
}

BOOST_AUTO_TEST_SUITE_END()
Loading