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
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ src_libbitcoin_network_la_SOURCES = \
src/messages/ping.cpp \
src/messages/pong.cpp \
src/messages/reject.cpp \
src/messages/send_address_v2.cpp \
src/messages/send_compact.cpp \
src/messages/send_headers.cpp \
src/messages/transaction.cpp \
Expand Down Expand Up @@ -182,6 +183,7 @@ test_libbitcoin_network_test_SOURCES = \
test/messages/ping.cpp \
test/messages/pong.cpp \
test/messages/reject.cpp \
test/messages/send_address_v2.cpp \
test/messages/send_compact.cpp \
test/messages/send_headers.cpp \
test/messages/transaction.cpp \
Expand Down Expand Up @@ -323,6 +325,7 @@ include_bitcoin_network_messages_HEADERS = \
include/bitcoin/network/messages/ping.hpp \
include/bitcoin/network/messages/pong.hpp \
include/bitcoin/network/messages/reject.hpp \
include/bitcoin/network/messages/send_address_v2.hpp \
include/bitcoin/network/messages/send_compact.hpp \
include/bitcoin/network/messages/send_headers.hpp \
include/bitcoin/network/messages/transaction.hpp \
Expand Down
2 changes: 2 additions & 0 deletions builds/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ add_library( ${CANONICAL_LIB_NAME}
"../../src/messages/ping.cpp"
"../../src/messages/pong.cpp"
"../../src/messages/reject.cpp"
"../../src/messages/send_address_v2.cpp"
"../../src/messages/send_compact.cpp"
"../../src/messages/send_headers.cpp"
"../../src/messages/transaction.cpp"
Expand Down Expand Up @@ -388,6 +389,7 @@ if (with-tests)
"../../test/messages/ping.cpp"
"../../test/messages/pong.cpp"
"../../test/messages/reject.cpp"
"../../test/messages/send_address_v2.cpp"
"../../test/messages/send_compact.cpp"
"../../test/messages/send_headers.cpp"
"../../test/messages/transaction.cpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
<ClCompile Include="..\..\..\..\test\messages\ping.cpp" />
<ClCompile Include="..\..\..\..\test\messages\pong.cpp" />
<ClCompile Include="..\..\..\..\test\messages\reject.cpp" />
<ClCompile Include="..\..\..\..\test\messages\send_address_v2.cpp" />
<ClCompile Include="..\..\..\..\test\messages\send_compact.cpp" />
<ClCompile Include="..\..\..\..\test\messages\send_headers.cpp" />
<ClCompile Include="..\..\..\..\test\messages\transaction.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@
<ClCompile Include="..\..\..\..\test\messages\reject.cpp">
<Filter>src\messages</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\messages\send_address_v2.cpp">
<Filter>src\messages</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\messages\send_compact.cpp">
<Filter>src\messages</Filter>
</ClCompile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
<ClCompile Include="..\..\..\..\src\messages\ping.cpp" />
<ClCompile Include="..\..\..\..\src\messages\pong.cpp" />
<ClCompile Include="..\..\..\..\src\messages\reject.cpp" />
<ClCompile Include="..\..\..\..\src\messages\send_address_v2.cpp" />
<ClCompile Include="..\..\..\..\src\messages\send_compact.cpp" />
<ClCompile Include="..\..\..\..\src\messages\send_headers.cpp" />
<ClCompile Include="..\..\..\..\src\messages\transaction.cpp" />
Expand Down Expand Up @@ -277,6 +278,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\network\messages\ping.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\messages\pong.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\messages\reject.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\messages\send_address_v2.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\messages\send_compact.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\messages\send_headers.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\messages\transaction.hpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@
<ClCompile Include="..\..\..\..\src\messages\reject.cpp">
<Filter>src\messages</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\messages\send_address_v2.cpp">
<Filter>src\messages</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\messages\send_compact.cpp">
<Filter>src\messages</Filter>
</ClCompile>
Expand Down Expand Up @@ -533,6 +536,9 @@
<ClInclude Include="..\..\..\..\include\bitcoin\network\messages\reject.hpp">
<Filter>include\bitcoin\network\messages</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\network\messages\send_address_v2.hpp">
<Filter>include\bitcoin\network\messages</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\network\messages\send_compact.hpp">
<Filter>include\bitcoin\network\messages</Filter>
</ClInclude>
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
#include <bitcoin/network/messages/ping.hpp>
#include <bitcoin/network/messages/pong.hpp>
#include <bitcoin/network/messages/reject.hpp>
#include <bitcoin/network/messages/send_address_v2.hpp>
#include <bitcoin/network/messages/send_compact.hpp>
#include <bitcoin/network/messages/send_headers.hpp>
#include <bitcoin/network/messages/transaction.hpp>
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/network/messages/enums/identifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ enum class identifier
ping,
pong,
reject,
send_address_v2,
send_compact,
send_headers,
transaction,
Expand Down
3 changes: 3 additions & 0 deletions include/bitcoin/network/messages/enums/level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ enum level: uint32_t
/// client filters protocol
bip157 = 70015,

/// send_address_v2
bip155 = 70016,

/// We require at least this of peers (for current address structure).
minimum_protocol = address_time,

Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/network/messages/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include <bitcoin/network/messages/ping.hpp>
#include <bitcoin/network/messages/pong.hpp>
#include <bitcoin/network/messages/reject.hpp>
#include <bitcoin/network/messages/send_address_v2.hpp>
#include <bitcoin/network/messages/send_compact.hpp>
#include <bitcoin/network/messages/send_headers.hpp>
#include <bitcoin/network/messages/transaction.hpp>
Expand Down
57 changes: 57 additions & 0 deletions include/bitcoin/network/messages/send_address_v2.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright (c) 2011-2025 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_NETWORK_MESSAGES_SEND_ADDRESS_V2_HPP
#define LIBBITCOIN_NETWORK_MESSAGES_SEND_ADDRESS_V2_HPP

#include <memory>
#include <bitcoin/system.hpp>
#include <bitcoin/network/define.hpp>
#include <bitcoin/network/messages/enums/identifier.hpp>

namespace libbitcoin {
namespace network {
namespace messages {

struct BCT_API send_address_v2
{
typedef std::shared_ptr<const send_address_v2> cptr;

static const identifier id;
static const std::string command;
static const uint32_t version_minimum;
static const uint32_t version_maximum;

static size_t size(uint32_t version) NOEXCEPT;

static cptr deserialize(uint32_t version,
const system::data_chunk& data) NOEXCEPT;
static send_address_v2 deserialize(uint32_t version,
system::reader& source) NOEXCEPT;

bool serialize(uint32_t version,
const system::data_slab& data) const NOEXCEPT;
void serialize(uint32_t version,
system::writer& sink) const NOEXCEPT;
};

} // namespace messages
} // namespace network
} // namespace libbitcoin

#endif
4 changes: 4 additions & 0 deletions include/bitcoin/network/net/broadcaster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class BCT_API broadcaster
DEFINE_SUBSCRIBER(ping);
DEFINE_SUBSCRIBER(pong);
DEFINE_SUBSCRIBER(reject);
DEFINE_SUBSCRIBER(send_address_v2);
DEFINE_SUBSCRIBER(send_compact);
DEFINE_SUBSCRIBER(send_headers);
DEFINE_SUBSCRIBER(transaction);
Expand Down Expand Up @@ -128,6 +129,7 @@ class BCT_API broadcaster
NOTIFY_OVERLOAD(ping);
NOTIFY_OVERLOAD(pong);
NOTIFY_OVERLOAD(reject);
NOTIFY_OVERLOAD(send_address_v2);
NOTIFY_OVERLOAD(send_compact);
NOTIFY_OVERLOAD(send_headers);
NOTIFY_OVERLOAD(transaction);
Expand Down Expand Up @@ -171,6 +173,7 @@ class BCT_API broadcaster
SUBSCRIBER_OVERLOAD(ping);
SUBSCRIBER_OVERLOAD(pong);
SUBSCRIBER_OVERLOAD(reject);
SUBSCRIBER_OVERLOAD(send_address_v2);
SUBSCRIBER_OVERLOAD(send_compact);
SUBSCRIBER_OVERLOAD(send_headers);
SUBSCRIBER_OVERLOAD(transaction);
Expand Down Expand Up @@ -206,6 +209,7 @@ class BCT_API broadcaster
DECLARE_SUBSCRIBER(ping);
DECLARE_SUBSCRIBER(pong);
DECLARE_SUBSCRIBER(reject);
DECLARE_SUBSCRIBER(send_address_v2);
DECLARE_SUBSCRIBER(send_compact);
DECLARE_SUBSCRIBER(send_headers);
DECLARE_SUBSCRIBER(transaction);
Expand Down
3 changes: 3 additions & 0 deletions include/bitcoin/network/net/distributor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class BCT_API distributor
DEFINE_SUBSCRIBER(ping);
DEFINE_SUBSCRIBER(pong);
DEFINE_SUBSCRIBER(reject);
DEFINE_SUBSCRIBER(send_address_v2);
DEFINE_SUBSCRIBER(send_compact);
DEFINE_SUBSCRIBER(send_headers);
DEFINE_SUBSCRIBER(transaction);
Expand Down Expand Up @@ -153,6 +154,7 @@ class BCT_API distributor
SUBSCRIBER_OVERLOAD(ping);
SUBSCRIBER_OVERLOAD(pong);
SUBSCRIBER_OVERLOAD(reject);
SUBSCRIBER_OVERLOAD(send_address_v2);
SUBSCRIBER_OVERLOAD(send_compact);
SUBSCRIBER_OVERLOAD(send_headers);
SUBSCRIBER_OVERLOAD(transaction);
Expand Down Expand Up @@ -188,6 +190,7 @@ class BCT_API distributor
DECLARE_SUBSCRIBER(ping);
DECLARE_SUBSCRIBER(pong);
DECLARE_SUBSCRIBER(reject);
DECLARE_SUBSCRIBER(send_address_v2);
DECLARE_SUBSCRIBER(send_compact);
DECLARE_SUBSCRIBER(send_headers);
DECLARE_SUBSCRIBER(transaction);
Expand Down
2 changes: 2 additions & 0 deletions src/messages/heading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <bitcoin/network/messages/ping.hpp>
#include <bitcoin/network/messages/pong.hpp>
#include <bitcoin/network/messages/reject.hpp>
#include <bitcoin/network/messages/send_address_v2.hpp>
#include <bitcoin/network/messages/send_compact.hpp>
#include <bitcoin/network/messages/send_headers.hpp>
#include <bitcoin/network/messages/transaction.hpp>
Expand Down Expand Up @@ -194,6 +195,7 @@ identifier heading::id() const NOEXCEPT
COMMAND_ID(ping),
COMMAND_ID(pong),
COMMAND_ID(reject),
COMMAND_ID(send_address_v2),
COMMAND_ID(send_compact),
COMMAND_ID(send_headers),
COMMAND_ID(transaction),
Expand Down
80 changes: 80 additions & 0 deletions src/messages/send_address_v2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Copyright (c) 2011-2025 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/>.
*/
#include <bitcoin/network/messages/send_address_v2.hpp>

#include <bitcoin/system.hpp>
#include <bitcoin/network/messages/enums/identifier.hpp>
#include <bitcoin/network/messages/enums/level.hpp>
#include <bitcoin/network/messages/message.hpp>

namespace libbitcoin {
namespace network {
namespace messages {

using namespace system;

const std::string send_address_v2::command = "sendaddrv2";
const identifier send_address_v2::id = identifier::send_address_v2;
const uint32_t send_address_v2::version_minimum = level::bip155;
const uint32_t send_address_v2::version_maximum = level::maximum_protocol;

// static
size_t send_address_v2::size(uint32_t) NOEXCEPT
{
return zero;
}

// static
typename send_address_v2::cptr send_address_v2::deserialize(uint32_t version,
const system::data_chunk& data) NOEXCEPT
{
system::istream source{ data };
system::byte_reader reader{ source };
const auto message = to_shared(deserialize(version, reader));
return reader ? message : nullptr;
}

bool send_address_v2::serialize(uint32_t version,
const system::data_slab& data) const NOEXCEPT
{
system::ostream sink{ data };
system::byte_writer writer{ sink };
serialize(version, writer);
return writer;
}

send_address_v2 send_address_v2::deserialize(uint32_t version, reader& source) NOEXCEPT
{
if (version < version_minimum || version > version_maximum)
source.invalidate();

return {};
}

void send_address_v2::serialize(uint32_t BC_DEBUG_ONLY(version),
writer& BC_DEBUG_ONLY(sink)) const NOEXCEPT
{
BC_DEBUG_ONLY(const auto bytes = size(version);)
BC_DEBUG_ONLY(const auto start = sink.get_write_position();)
BC_ASSERT(sink && sink.get_write_position() - start == bytes);
}

} // namespace messages
} // namespace network
} // namespace libbitcoin
3 changes: 3 additions & 0 deletions src/net/broadcaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ broadcaster::broadcaster(asio::strand& strand) NOEXCEPT
MAKE_SUBSCRIBER(ping),
MAKE_SUBSCRIBER(pong),
MAKE_SUBSCRIBER(reject),
MAKE_SUBSCRIBER(send_address_v2),
MAKE_SUBSCRIBER(send_compact),
MAKE_SUBSCRIBER(send_headers),
MAKE_SUBSCRIBER(transaction),
Expand Down Expand Up @@ -100,6 +101,7 @@ void broadcaster::unsubscribe(channel_id subscriber) NOEXCEPT
UNSUBSCRIBER(ping);
UNSUBSCRIBER(pong);
UNSUBSCRIBER(reject);
UNSUBSCRIBER(send_address_v2);
UNSUBSCRIBER(send_compact);
UNSUBSCRIBER(send_headers);
UNSUBSCRIBER(transaction);
Expand Down Expand Up @@ -137,6 +139,7 @@ void broadcaster::stop(const code& ec) NOEXCEPT
STOP_SUBSCRIBER(ping);
STOP_SUBSCRIBER(pong);
STOP_SUBSCRIBER(reject);
STOP_SUBSCRIBER(send_address_v2);
STOP_SUBSCRIBER(send_compact);
STOP_SUBSCRIBER(send_headers);
STOP_SUBSCRIBER(transaction);
Expand Down
3 changes: 3 additions & 0 deletions src/net/distributor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ distributor::distributor(memory& memory, asio::strand& strand) NOEXCEPT
MAKE_SUBSCRIBER(ping),
MAKE_SUBSCRIBER(pong),
MAKE_SUBSCRIBER(reject),
MAKE_SUBSCRIBER(send_address_v2),
MAKE_SUBSCRIBER(send_compact),
MAKE_SUBSCRIBER(send_headers),
MAKE_SUBSCRIBER(transaction),
Expand Down Expand Up @@ -111,6 +112,7 @@ code distributor::notify(messages::identifier id, uint32_t version,
CASE_NOTIFY(ping);
CASE_NOTIFY(pong);
CASE_NOTIFY(reject);
CASE_NOTIFY(send_address_v2);
CASE_NOTIFY(send_compact);
CASE_NOTIFY(send_headers);
CASE_NOTIFY(transaction);
Expand Down Expand Up @@ -153,6 +155,7 @@ void distributor::stop(const code& ec) NOEXCEPT
STOP_SUBSCRIBER(ping);
STOP_SUBSCRIBER(pong);
STOP_SUBSCRIBER(reject);
STOP_SUBSCRIBER(send_address_v2);
STOP_SUBSCRIBER(send_compact);
STOP_SUBSCRIBER(send_headers);
STOP_SUBSCRIBER(transaction);
Expand Down
6 changes: 6 additions & 0 deletions test/messages/heading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ BOOST_AUTO_TEST_CASE(heading__reject_id__always__expected)
BOOST_REQUIRE(instance.id() == reject::id);
}

BOOST_AUTO_TEST_CASE(heading__send_address_v2_id__always__expected)
{
const auto instance = heading{ 0u, send_address_v2::command, 0u, 0u };
BOOST_REQUIRE(instance.id() == send_address_v2::id);
}

BOOST_AUTO_TEST_CASE(heading__send_compact_id__always__expected)
{
const auto instance = heading{ 0u, send_compact::command, 0u, 0u };
Expand Down
Loading
Loading