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 @@ -109,6 +109,7 @@ src_libbitcoin_network_la_SOURCES = \
src/protocols/protocol_version_31402.cpp \
src/protocols/protocol_version_70001.cpp \
src/protocols/protocol_version_70002.cpp \
src/protocols/protocol_version_70016.cpp \
src/sessions/session.cpp \
src/sessions/session_inbound.cpp \
src/sessions/session_manual.cpp \
Expand Down Expand Up @@ -209,6 +210,7 @@ test_libbitcoin_network_test_SOURCES = \
test/protocols/protocol_version_31402.cpp \
test/protocols/protocol_version_70001.cpp \
test/protocols/protocol_version_70002.cpp \
test/protocols/protocol_version_70016.cpp \
test/sessions/session.cpp \
test/sessions/session_inbound.cpp \
test/sessions/session_manual.cpp \
Expand Down Expand Up @@ -365,6 +367,7 @@ include_bitcoin_network_protocols_HEADERS = \
include/bitcoin/network/protocols/protocol_version_31402.hpp \
include/bitcoin/network/protocols/protocol_version_70001.hpp \
include/bitcoin/network/protocols/protocol_version_70002.hpp \
include/bitcoin/network/protocols/protocol_version_70016.hpp \
include/bitcoin/network/protocols/protocols.hpp

include_bitcoin_network_sessionsdir = ${includedir}/bitcoin/network/sessions
Expand Down
2 changes: 2 additions & 0 deletions builds/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ add_library( ${CANONICAL_LIB_NAME}
"../../src/protocols/protocol_version_31402.cpp"
"../../src/protocols/protocol_version_70001.cpp"
"../../src/protocols/protocol_version_70002.cpp"
"../../src/protocols/protocol_version_70016.cpp"
"../../src/sessions/session.cpp"
"../../src/sessions/session_inbound.cpp"
"../../src/sessions/session_manual.cpp"
Expand Down Expand Up @@ -415,6 +416,7 @@ if (with-tests)
"../../test/protocols/protocol_version_31402.cpp"
"../../test/protocols/protocol_version_70001.cpp"
"../../test/protocols/protocol_version_70002.cpp"
"../../test/protocols/protocol_version_70016.cpp"
"../../test/sessions/session.cpp"
"../../test/sessions/session_inbound.cpp"
"../../test/sessions/session_manual.cpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
<ClCompile Include="..\..\..\..\test\protocols\protocol_version_31402.cpp" />
<ClCompile Include="..\..\..\..\test\protocols\protocol_version_70001.cpp" />
<ClCompile Include="..\..\..\..\test\protocols\protocol_version_70002.cpp" />
<ClCompile Include="..\..\..\..\test\protocols\protocol_version_70016.cpp" />
<ClCompile Include="..\..\..\..\test\sessions\session.cpp" />
<ClCompile Include="..\..\..\..\test\sessions\session_inbound.cpp" />
<ClCompile Include="..\..\..\..\test\sessions\session_manual.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@
<ClCompile Include="..\..\..\..\test\protocols\protocol_version_70002.cpp">
<Filter>src\protocols</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\protocols\protocol_version_70016.cpp">
<Filter>src\protocols</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\sessions\session.cpp">
<Filter>src\sessions</Filter>
</ClCompile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
<ClCompile Include="..\..\..\..\src\protocols\protocol_version_31402.cpp" />
<ClCompile Include="..\..\..\..\src\protocols\protocol_version_70001.cpp" />
<ClCompile Include="..\..\..\..\src\protocols\protocol_version_70002.cpp" />
<ClCompile Include="..\..\..\..\src\protocols\protocol_version_70016.cpp" />
<ClCompile Include="..\..\..\..\src\sessions\session.cpp" />
<ClCompile Include="..\..\..\..\src\sessions\session_inbound.cpp" />
<ClCompile Include="..\..\..\..\src\sessions\session_manual.cpp" />
Expand Down Expand Up @@ -306,6 +307,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\network\protocols\protocol_version_31402.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\protocols\protocol_version_70001.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\protocols\protocol_version_70002.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\protocols\protocol_version_70016.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\protocols\protocols.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\sessions\session.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\sessions\session_inbound.hpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@
<ClCompile Include="..\..\..\..\src\protocols\protocol_version_70002.cpp">
<Filter>src\protocols</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\protocols\protocol_version_70016.cpp">
<Filter>src\protocols</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\sessions\session.cpp">
<Filter>src\sessions</Filter>
</ClCompile>
Expand Down Expand Up @@ -620,6 +623,9 @@
<ClInclude Include="..\..\..\..\include\bitcoin\network\protocols\protocol_version_70002.hpp">
<Filter>include\bitcoin\network\protocols</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\network\protocols\protocol_version_70016.hpp">
<Filter>include\bitcoin\network\protocols</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\network\protocols\protocols.hpp">
<Filter>include\bitcoin\network\protocols</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 @@ -116,6 +116,7 @@
#include <bitcoin/network/protocols/protocol_version_31402.hpp>
#include <bitcoin/network/protocols/protocol_version_70001.hpp>
#include <bitcoin/network/protocols/protocol_version_70002.hpp>
#include <bitcoin/network/protocols/protocol_version_70016.hpp>
#include <bitcoin/network/protocols/protocols.hpp>
#include <bitcoin/network/sessions/session.hpp>
#include <bitcoin/network/sessions/session_inbound.hpp>
Expand Down
71 changes: 71 additions & 0 deletions include/bitcoin/network/protocols/protocol_version_70016.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* 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_PROTOCOL_VERSION_70016_HPP
#define LIBBITCOIN_NETWORK_PROTOCOL_VERSION_70016_HPP

#include <memory>
#include <bitcoin/system.hpp>
#include <bitcoin/network/async/async.hpp>
#include <bitcoin/network/define.hpp>
#include <bitcoin/network/log/log.hpp>
#include <bitcoin/network/messages/messages.hpp>
#include <bitcoin/network/net/net.hpp>
#include <bitcoin/network/protocols/protocol_version_70002.hpp>
#include <bitcoin/network/sessions/sessions.hpp>

namespace libbitcoin {
namespace network {

class BCT_API protocol_version_70016
: public protocol_version_70002, protected tracker<protocol_version_70016>
{
public:
typedef std::shared_ptr<protocol_version_70016> ptr;

/// Construct a version protocol instance using configured values.
protocol_version_70016(const session::ptr& session,
const channel::ptr& channel) NOEXCEPT;

/// Construct a version protocol instance using parameterized services.
protocol_version_70016(const session::ptr& session,
const channel::ptr& channel, uint64_t minimum_services,
uint64_t maximum_services, bool relay, bool reject) NOEXCEPT;

/// Perform the handshake (strand required), handler invoked on completion.
void shake(result_handler&& handle_event) NOEXCEPT override;

protected:
void handle_send_version(const code& ec) NOEXCEPT override;
bool handle_receive_acknowledge(const code& ec,
const messages::version_acknowledge::cptr& message) NOEXCEPT override;
virtual bool handle_receive_send_address_v2(const code& ec,
const messages::send_address_v2::cptr& message) NOEXCEPT;

private:
// This is thread safe.
const bool reject_;

// This is protected by strand.
bool complete_{};
};

} // namespace network
} // namespace libbitcoin

#endif
1 change: 1 addition & 0 deletions include/bitcoin/network/protocols/protocols.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
#include <bitcoin/network/protocols/protocol_version_31402.hpp>
#include <bitcoin/network/protocols/protocol_version_70001.hpp>
#include <bitcoin/network/protocols/protocol_version_70002.hpp>
#include <bitcoin/network/protocols/protocol_version_70016.hpp>

#endif
5 changes: 3 additions & 2 deletions src/protocols/protocol_version_31402.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ protocol_version_31402::protocol_version_31402(const session::ptr& session,

// Used for seeding (should probably not override these).
protocol_version_31402::protocol_version_31402(const session::ptr& session,
const channel::ptr& channel, uint64_t minimum_services,
const channel::ptr& channel,
uint64_t minimum_services,
uint64_t maximum_services) NOEXCEPT
: protocol(session, channel),
inbound_(channel->inbound()),
Expand Down Expand Up @@ -335,7 +336,7 @@ bool protocol_version_31402::handle_receive_version(const code& ec,

if (is_disallowed_deviation(message->timestamp))
{
LOGP("Timestamp out of range (" << message->value << ") "
LOGR("Timestamp out of range (" << message->value << ") "
"for [" << authority() << "].");

rejection(error::peer_timestamp);
Expand Down
9 changes: 5 additions & 4 deletions src/protocols/protocol_version_70001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ protocol_version_70001::protocol_version_70001(const session::ptr& session,
}

protocol_version_70001::protocol_version_70001(const session::ptr& session,
const channel::ptr& channel, uint64_t minimum_services,
uint64_t maximum_services, bool relay) NOEXCEPT
: protocol_version_31402(session, channel, minimum_services,
maximum_services),
const channel::ptr& channel,
uint64_t minimum_services,
uint64_t maximum_services,
bool relay) NOEXCEPT
: protocol_version_31402(session, channel, minimum_services, maximum_services),
relay_(relay),
tracker<protocol_version_70001>(session->log)
{
Expand Down
17 changes: 7 additions & 10 deletions src/protocols/protocol_version_70002.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
#include <bitcoin/network/protocols/protocol_version_70001.hpp>
#include <bitcoin/network/sessions/sessions.hpp>

// TODO: incorporate "sendaddrv2" into a new protocol_version_70016.
// TODO: sendaddrv2 is a a broken protocol in that it is a formally unversioned
// TODO: message, though Satoshi doesn't send until receiving version >= 70016.
// TODO: must be sent/received before verack (and sent after version receipt).

namespace libbitcoin {
namespace network {

Expand All @@ -51,10 +46,11 @@ protocol_version_70002::protocol_version_70002(const session::ptr& session,
}

protocol_version_70002::protocol_version_70002(const session::ptr& session,
const channel::ptr& channel, uint64_t minimum_services,
uint64_t maximum_services, bool relay) NOEXCEPT
: protocol_version_70001(session, channel, minimum_services,
maximum_services, relay),
const channel::ptr& channel,
uint64_t minimum_services,
uint64_t maximum_services,
bool relay) NOEXCEPT
: protocol_version_70001(session, channel, minimum_services, maximum_services, relay),
tracker<protocol_version_70002>(session->log)
{
}
Expand All @@ -76,6 +72,7 @@ void protocol_version_70002::shake(result_handler&& handle_event) NOEXCEPT

// Outgoing [(in)sufficient_peer => send_reject].
// ----------------------------------------------------------------------------
// Reject is the only difference at protocol level 70002.

void protocol_version_70002::rejection(const code& ec) NOEXCEPT
{
Expand Down Expand Up @@ -104,7 +101,7 @@ void protocol_version_70002::rejection(const code& ec) NOEXCEPT
"timestamp" }), handle_send, _1);
}

return protocol_version_70001::rejection(ec);
protocol_version_70001::rejection(ec);
}

// Incoming [receive_reject => log].
Expand Down
129 changes: 129 additions & 0 deletions src/protocols/protocol_version_70016.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* 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/protocols/protocol_version_70016.hpp>

#include <utility>
#include <bitcoin/system.hpp>
#include <bitcoin/network/define.hpp>
#include <bitcoin/network/log/log.hpp>
#include <bitcoin/network/messages/messages.hpp>
#include <bitcoin/network/net/net.hpp>
#include <bitcoin/network/protocols/protocol_version_70002.hpp>
#include <bitcoin/network/sessions/sessions.hpp>

// sendaddrv2 is a a broken protocol in that it is a formally unversioned
// message, though Satoshi doesn't send until receiving version >= 70016.
// It must be sent/received before verack (and sent after version receipt).

namespace libbitcoin {
namespace network {

#define CLASS protocol_version_70016

using namespace system;
using namespace bc::network::messages;
using namespace std::placeholders;

protocol_version_70016::protocol_version_70016(const session::ptr& session,
const channel::ptr& channel) NOEXCEPT
: protocol_version_70016(session, channel,
session->settings().services_minimum,
session->settings().services_maximum,
session->settings().enable_transaction,
session->settings().enable_reject)
{
}

protocol_version_70016::protocol_version_70016(const session::ptr& session,
const channel::ptr& channel,
uint64_t minimum_services,
uint64_t maximum_services,
bool relay,
bool reject) NOEXCEPT
: protocol_version_70002(session, channel, minimum_services, maximum_services, relay),
reject_(reject),
tracker<protocol_version_70016>(session->log)
{
}

// Start.
// ----------------------------------------------------------------------------

void protocol_version_70016::shake(result_handler&& handle_event) NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "protocol_version_70016");

if (started())
return;

// Protocol versions are cumulative, but reject is deprecated.
if (reject_)
{
protocol_version_70002::shake(std::move(handle_event));
return;
}

protocol_version_70001::shake(std::move(handle_event));
}


// Incoming [send_address_v2 => negotiated state change].
// ----------------------------------------------------------------------------
// send_address_v2 receipt is the only difference at protocol level 70016.

void protocol_version_70016::handle_send_version(const code& ec) NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "protocol_version_70016");

SUBSCRIBE_CHANNEL(send_address_v2, handle_receive_send_address_v2, _1, _2);
protocol_version_70002::handle_send_version(ec);
}

bool protocol_version_70016::handle_receive_acknowledge(const code& ec,
const messages::version_acknowledge::cptr& message) NOEXCEPT
{
complete_ = true;

// Channel will pause after this and then be restarted as connected.
return protocol_version_70002::handle_receive_acknowledge(ec, message);
}

bool protocol_version_70016::handle_receive_send_address_v2(const code& ec,
const send_address_v2::cptr&) NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "protocol_version_70016");

if (stopped(ec))
return false;

// Late or already received send_address_v2.
if (complete_)
{
rejection(error::protocol_violation);
return false;
}

// TODO: set channel addressv2 property and use to attach protocols.
// TODO: implement updated protocol_address_in|out_70016.
complete_ = true;
return true;
}

} // namespace network
} // namespace libbitcoin
Loading
Loading