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
30 changes: 30 additions & 0 deletions .github/workflows/ci-expanded.yml
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,16 @@ jobs:
if: ${{ startsWith(matrix.image, 'windows') }}
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0

- name: Prefer Visual Studio LLVM [windows]
if: ${{ startsWith(matrix.image, 'windows') }}
shell: pwsh
run: |
$arch = if ($env:RUNNER_ARCH -eq 'ARM64') { 'ARM64' } else { 'x64' }
$llvm = Join-Path $env:VCINSTALLDIR Tools Llvm $arch bin
if (-not (Test-Path (Join-Path $llvm 'clang-cl.exe'))) { throw "clang-cl not found in $llvm." }
Add-Content -Path $env:GITHUB_PATH -Value $llvm
& (Join-Path $llvm 'clang-cl.exe') --version

- name: Environmental Computation
shell: bash
run: |
Expand Down Expand Up @@ -1157,6 +1167,16 @@ jobs:
if: ${{ startsWith(matrix.image, 'windows') }}
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0

- name: Prefer Visual Studio LLVM [windows]
if: ${{ startsWith(matrix.image, 'windows') }}
shell: pwsh
run: |
$arch = if ($env:RUNNER_ARCH -eq 'ARM64') { 'ARM64' } else { 'x64' }
$llvm = Join-Path $env:VCINSTALLDIR Tools Llvm $arch bin
if (-not (Test-Path (Join-Path $llvm 'clang-cl.exe'))) { throw "clang-cl not found in $llvm." }
Add-Content -Path $env:GITHUB_PATH -Value $llvm
& (Join-Path $llvm 'clang-cl.exe') --version

- name: Environmental Computation
shell: bash
run: |
Expand Down Expand Up @@ -1571,6 +1591,16 @@ jobs:
if: ${{ startsWith(matrix.image, 'windows') }}
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0

- name: Prefer Visual Studio LLVM [windows]
if: ${{ startsWith(matrix.image, 'windows') }}
shell: pwsh
run: |
$arch = if ($env:RUNNER_ARCH -eq 'ARM64') { 'ARM64' } else { 'x64' }
$llvm = Join-Path $env:VCINSTALLDIR Tools Llvm $arch bin
if (-not (Test-Path (Join-Path $llvm 'clang-cl.exe'))) { throw "clang-cl not found in $llvm." }
Add-Content -Path $env:GITHUB_PATH -Value $llvm
& (Join-Path $llvm 'clang-cl.exe') --version

- name: Environmental Computation
shell: bash
run: |
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ jobs:
if: ${{ startsWith(matrix.image, 'windows') }}
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0

- name: Prefer Visual Studio LLVM [windows]
if: ${{ startsWith(matrix.image, 'windows') }}
shell: pwsh
run: |
$arch = if ($env:RUNNER_ARCH -eq 'ARM64') { 'ARM64' } else { 'x64' }
$llvm = Join-Path $env:VCINSTALLDIR Tools Llvm $arch bin
if (-not (Test-Path (Join-Path $llvm 'clang-cl.exe'))) { throw "clang-cl not found in $llvm." }
Add-Content -Path $env:GITHUB_PATH -Value $llvm
& (Join-Path $llvm 'clang-cl.exe') --version

- name: Environmental Computation
shell: bash
run: |
Expand Down Expand Up @@ -450,6 +460,16 @@ jobs:
if: ${{ startsWith(matrix.image, 'windows') }}
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0

- name: Prefer Visual Studio LLVM [windows]
if: ${{ startsWith(matrix.image, 'windows') }}
shell: pwsh
run: |
$arch = if ($env:RUNNER_ARCH -eq 'ARM64') { 'ARM64' } else { 'x64' }
$llvm = Join-Path $env:VCINSTALLDIR Tools Llvm $arch bin
if (-not (Test-Path (Join-Path $llvm 'clang-cl.exe'))) { throw "clang-cl not found in $llvm." }
Add-Content -Path $env:GITHUB_PATH -Value $llvm
& (Join-Path $llvm 'clang-cl.exe') --version

- name: Environmental Computation
shell: bash
run: |
Expand Down Expand Up @@ -636,6 +656,16 @@ jobs:
if: ${{ startsWith(matrix.image, 'windows') }}
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0

- name: Prefer Visual Studio LLVM [windows]
if: ${{ startsWith(matrix.image, 'windows') }}
shell: pwsh
run: |
$arch = if ($env:RUNNER_ARCH -eq 'ARM64') { 'ARM64' } else { 'x64' }
$llvm = Join-Path $env:VCINSTALLDIR Tools Llvm $arch bin
if (-not (Test-Path (Join-Path $llvm 'clang-cl.exe'))) { throw "clang-cl not found in $llvm." }
Add-Content -Path $env:GITHUB_PATH -Value $llvm
& (Join-Path $llvm 'clang-cl.exe') --version

- name: Environmental Computation
shell: bash
run: |
Expand Down
27 changes: 16 additions & 11 deletions builds/cmake/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"name": "nix-base",
"description": "Factored base settings for non-windows *nix based platforms.",
"hidden": true,
"inherits": [ "base-pathing" ],
"condition": {
"type": "inList",
"string": "${hostSystemName}",
Expand All @@ -39,6 +40,7 @@
"name": "win-base",
"description": "Factored base settings for windows platforms (msvc developer environment).",
"hidden": true,
"inherits": [ "base-pathing" ],
"generator": "Ninja",
"condition": {
"type": "equals",
Expand Down Expand Up @@ -66,6 +68,7 @@
"name": "gnu-debug",
"description": "Factored gnu specific debug settings.",
"hidden": true,
"inherits": [ "config-debug" ],
"cacheVariables": {
"CMAKE_C_FLAGS": "$env{CMAKE_C_FLAGS} -Og -g1 --coverage -fprofile-update=atomic",
"CMAKE_CXX_FLAGS": "$env{CMAKE_CXX_FLAGS} -Og -g1 --coverage -fprofile-update=atomic"
Expand All @@ -75,6 +78,7 @@
"name": "gnu-release",
"description": "Factored gnu specific release settings.",
"hidden": true,
"inherits": [ "config-release" ],
"cacheVariables": {
"CMAKE_C_FLAGS": "$env{CMAKE_C_FLAGS} -O3",
"CMAKE_CXX_FLAGS": "$env{CMAKE_CXX_FLAGS} -O3"
Expand Down Expand Up @@ -124,9 +128,10 @@
"name": "optimization-host-native",
"description": "Factored settings for march/mtune using for local execution.",
"hidden": true,
"cacheVariables": {
"CMAKE_C_FLAGS": "$env{CMAKE_C_FLAGS} -march=native -mtune=native",
"CMAKE_CXX_FLAGS": "$env{CMAKE_CXX_FLAGS} -march=native -mtune=native"
"inherits": [ "nix-base" ],
"environment": {
"CMAKE_C_FLAGS": "$penv{CMAKE_C_FLAGS} -march=native -mtune=native",
"CMAKE_CXX_FLAGS": "$penv{CMAKE_CXX_FLAGS} -march=native -mtune=native"
}
},
{
Expand Down Expand Up @@ -175,7 +180,7 @@
},
{
"name": "nix-gnu-debug-static-native",
"displayName": "*nix/GNU/Debug/Static",
"displayName": "*nix/GNU/Debug/Static/Native",
"description": "Debug build with static linking for native architecture.",
"hidden": false,
"inherits": [
Expand All @@ -187,7 +192,7 @@
},
{
"name": "nix-gnu-debug-shared-native",
"displayName": "*nix/GNU/Debug/Shared",
"displayName": "*nix/GNU/Debug/Shared/Native",
"description": "Debug build with shared linking for native architecture.",
"hidden": false,
"inherits": [
Expand All @@ -199,7 +204,7 @@
},
{
"name": "nix-gnu-release-static-native",
"displayName": "*nix/GNU/Release/Static",
"displayName": "*nix/GNU/Release/Static/Native",
"description": "Release build with static linking and standard optimizations for native architecture.",
"hidden": false,
"inherits": [
Expand All @@ -211,7 +216,7 @@
},
{
"name": "nix-gnu-release-shared-native",
"displayName": "*nix/GNU/Release/Shared",
"displayName": "*nix/GNU/Release/Shared/Native",
"description": "Release build with shared linking and standard optimizations for native architecture.",
"hidden": false,
"inherits": [
Expand Down Expand Up @@ -353,25 +358,25 @@
},
{
"name": "nix-gnu-debug-static-native",
"displayName": "*nix/GNU/Debug/Static",
"displayName": "*nix/GNU/Debug/Static/Native",
"inherits": [ "nix-target-list" ],
"configurePreset": "nix-gnu-debug-static-native"
},
{
"name": "nix-gnu-debug-shared-native",
"displayName": "*nix/GNU/Debug/Shared",
"displayName": "*nix/GNU/Debug/Shared/Native",
"inherits": [ "nix-target-list" ],
"configurePreset": "nix-gnu-debug-shared-native"
},
{
"name": "nix-gnu-release-static-native",
"displayName": "*nix/GNU/Release/Static",
"displayName": "*nix/GNU/Release/Static/Native",
"inherits": [ "nix-target-list" ],
"configurePreset": "nix-gnu-release-static-native"
},
{
"name": "nix-gnu-release-shared-native",
"displayName": "*nix/GNU/Release/Shared",
"displayName": "*nix/GNU/Release/Shared/Native",
"inherits": [ "nix-target-list" ],
"configurePreset": "nix-gnu-release-shared-native"
},
Expand Down
22 changes: 9 additions & 13 deletions include/bitcoin/network/impl/messages/json_body.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,8 @@ void CLASS::writer::init(code& ec) NOEXCEPT
return;
}

// Serialization is chunked by the estimate, within that bound less any
// terminator. An unestimated message is chunked by the bound.
const auto reserve = is_zero(terminator_) ? zero : one;
const auto maximum = floored_subtract(value_.buffer->max_size(), reserve);
chunk_ = is_zero(value_.size_hint) ? maximum :
std::min(value_.size_hint, maximum);

value_.buffer->consume(value_.buffer->size());
// Serialization is chunked by the estimate, within that bound.
chunk_ = is_zero(value_.size_hint) ? max_size_t : value_.size_hint;
ec.clear();
serializer_.reset(&value_.model);
}
Expand All @@ -194,7 +188,13 @@ CLASS::writer::get(code& ec) NOEXCEPT
return {};
}

const auto size = chunk_;
// The chunk and any terminator, which follows the final serialized byte,
// are bound by the room that follows the buffer's readable bytes.
const auto reserve = is_zero(terminator_) ? zero : one;
const auto size = std::min(chunk_, system::floored_subtract(
value_.buffer->max_size(), system::ceilinged_add(
value_.buffer->size(), reserve)));

if (is_zero(size))
{
ec = to_http_code(http_error_t::buffer_overflow);
Expand All @@ -203,9 +203,6 @@ CLASS::writer::get(code& ec) NOEXCEPT

try
{
// Prepares the chunk, which the estimate sized within the bound, and
// any terminator, which follows the final serialized byte.
const auto reserve = is_zero(terminator_) ? zero : one;
const auto scratch = value_.buffer->prepare(size + reserve);
const auto data = system::pointer_cast<char>(scratch.data());
const auto view = serializer_.read(data, size);
Expand All @@ -218,7 +215,6 @@ CLASS::writer::get(code& ec) NOEXCEPT
}

ec.clear();
value_.buffer->consume(scratch.size());
const auto more = !serializer_.done();
if (more || is_zero(terminator_))
return out_buffer{ std::make_pair(io::buffer(view), more) };
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/network/messages/http/bodies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,9 @@ struct stream_body
uint8_t* data{};
const auto size = value_.size;
if (!is_null(value_.buffer) &&
size <= value_.buffer->max_size())
size <= floored_subtract(value_.buffer->max_size(),
value_.buffer->size()))
{
value_.buffer->clear();
data = pointer_cast<uint8_t>(
value_.buffer->prepare(size).data());
}
Expand Down
5 changes: 5 additions & 0 deletions include/bitcoin/network/messages/http/flat_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class BCT_API flat_buffer
/// Move size writable bytes (prepared) to the readable bytes.
void commit(size_t size) NOEXCEPT;

/// Append the buffers to the readable bytes, of which at most one may be
/// within the writable bytes, throws std::length_error if the readable
/// size would then exceed the limit.
void append(const std::span<const const_buffers_type>& buffers) THROWS;

/// Remove size bytes from the front of the readable bytes.
void consume(size_t size) NOEXCEPT;

Expand Down
6 changes: 4 additions & 2 deletions include/bitcoin/network/net/proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ namespace network {
/// Caller must retain ownership of read/write buffers until handler invoked.
/// All writes are queued to prevent interleaving.
/// Completion handler is invoked once write is complete, at which point the
/// next queued write is invoked. When a channel stops with pending writes the
/// write queue is purged without invoke of the purged handlers.
/// next queued write is invoked. A write with another queued behind it may be
/// held by the socket, completing before it is written with a later write.
/// When a channel stops with pending writes the write queue is purged without
/// invoke of the purged handlers.
/// Each send is allocated (bytes/rate_limit) of time, and its completion is
/// deferred by whatever portion of that allocation the write did not consume.
/// Since nothing is produced until the completion handler is invoked, this
Expand Down
32 changes: 27 additions & 5 deletions include/bitcoin/network/net/socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,15 @@ class BCT_API socket
virtual void body_notify(http::request&& notification,
count_handler&& handler) NOEXCEPT;

/// Assign the retained json serialization buffer to the message body.
void assign_buffer(http::body::value_type& body) NOEXCEPT;
/// Hold writes that fit the minimum buffer for the next write (strand).
/// A held write completes when held, before it is written.
void hold(bool enable) NOEXCEPT;

/// Reduce the retained json serialization buffer to the minimum.
void reclaim_buffer() NOEXCEPT;
/// Writes are held (strand).
bool holding() const NOEXCEPT;

/// End the hold and write the held writes (strand).
void release(count_handler&& handler) NOEXCEPT;

/// HTTP/WS (generic/rpc).
/// -----------------------------------------------------------------------
Expand Down Expand Up @@ -347,6 +351,10 @@ class BCT_API socket
const count_handler& handler) NOEXCEPT;
void async_write(const io::const_buffer& buffer, bool binary,
bool finish, const count_handler& handler) NOEXCEPT;
void transmit(const std::span<const io::const_buffer>& buffers,
bool hold, const count_handler& handler) NOEXCEPT;
void interject(const std::span<const io::const_buffer>& buffers,
const count_handler& handler) NOEXCEPT;
void async_read_http(http::flat_buffer& buffer, http::request& request,
const count_handler& handler) NOEXCEPT;
void async_write_http(http::response&& response,
Expand Down Expand Up @@ -452,6 +460,8 @@ class BCT_API socket
io::const_buffer data{};
count_handler handler{};
std::array<io::const_buffer, 2> buffers{};
bool control{};
bool finish{};
};

enum class parse_mode
Expand Down Expand Up @@ -673,6 +683,14 @@ class BCT_API socket
void handle_chunk_last(const code& ec, size_t size, size_t total,
const count_handler& handler) NOEXCEPT;

// buffer
void assign_buffer(http::body::value_type& body) NOEXCEPT;
void reclaim_buffer() NOEXCEPT;

// transport
void handle_transmit(const code& ec, size_t size, size_t held,
const count_handler& handler) NOEXCEPT;

// utility
// ------------------------------------------------------------------------

Expand Down Expand Up @@ -711,8 +729,12 @@ class BCT_API socket
// Retains the detection prefix for a v1 peer (see handle_detection).
http::flat_buffer detection_{ p2ps::stream::detection_size };

// Retains the json serialization buffer (allocated on first write).
// Retains the serialization buffer (allocated on first write), the
// readable bytes of which are the held writes.
http::flat_buffer response_;
std::function<void()> deferred_{};
bool hold_{};
bool sending_{};

// Websocket framing (once upgraded).
std::optional<ws::reader> ws_reader_{};
Expand Down
4 changes: 4 additions & 0 deletions include/bitcoin/network/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ struct BCT_API settings
uint32_t inactivity_minutes{ 10 };
uint32_t expiration_minutes{ 60 };
uint32_t minimum_buffer{ 4 * kilobyte };
uint32_t minimum_response{ 4 * kilobyte };
uint32_t maximum_buffer{ 64 * kilobyte };
uint32_t maximum_request{ max_payload };
uint32_t maximum_backlog{ megabyte };
Expand All @@ -133,6 +134,9 @@ struct BCT_API settings

/// Set the default port of bindings that do not specify a port.
virtual void default_ports() NOEXCEPT;

/// Set the minimum response buffer to the minimum (request) buffer.
virtual void default_buffers() NOEXCEPT;
};

struct BCT_API secure_server
Expand Down
Loading
Loading