Skip to content

Commit d6cf5db

Browse files
committed
try fix build
Signed-off-by: turuslan <[email protected]>
1 parent a303b8a commit d6cf5db

File tree

8 files changed

+55
-85
lines changed

8 files changed

+55
-85
lines changed

.github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ jobs:
4747
CXX: ${{ matrix.compiler.cxx }}
4848
run: cmake . -Bbuild
4949
- name: build
50+
env:
51+
CURL_SSL_BACKEND: SecureTransport
5052
run: cmake --build build -- -j4
5153
- name: test
5254
env:

.github/workflows/clang-tidy.yml

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
sudo python3 -m pip install scikit-build
2626
sudo python3 -m pip install cmake requests gitpython gcovr pyyaml
2727
- name: run checks
28+
env:
29+
CURL_SSL_BACKEND: SecureTransport
2830
run: |
2931
#!/bin/bash
3032
LLVM_DIR=/usr/local/Cellar/llvm

cmake/Hunter/init.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ set(
3131
include(${CMAKE_CURRENT_LIST_DIR}/HunterGate.cmake)
3232

3333
HunterGate(
34-
URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.23.257-qdrvm10.tar.gz
35-
SHA1 72b446a4424ba28ea90f9a68a9134b0f8e44b5b2
34+
URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.25.3-qdrvm5.zip
35+
SHA1 ae75fdf1850bd21dead239b8580012b6091be855
3636
LOCAL
3737
)

cmake/toolchain/clang-15_cxx17.cmake

-3
This file was deleted.

include/libp2p/muxer/yamux/yamux_stream.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#pragma once
88

9+
#include <optional>
10+
911
#include <libp2p/basic/read_buffer.hpp>
1012
#include <libp2p/basic/write_queue.hpp>
1113
#include <libp2p/common/metrics/instance_count.hpp>

include/libp2p/outcome/outcome.hpp

-75
Original file line numberDiff line numberDiff line change
@@ -95,78 +95,3 @@ struct fmt::formatter<boost::system::error_code> {
9595
return std::copy(std::begin(message), std::end(message), ctx.out());
9696
}
9797
};
98-
99-
// Remove after it will be added to libp2p (will be happened compilation error)
100-
template <typename T>
101-
struct fmt::formatter<outcome::success_type<T>> {
102-
// Parses format specifications. Must be empty
103-
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) {
104-
// Parse the presentation format and store it in the formatter:
105-
auto it = ctx.begin(), end = ctx.end();
106-
107-
// Check if reached the end of the range:
108-
if (it != end && *it != '}') {
109-
throw format_error("invalid format");
110-
}
111-
112-
// Return an iterator past the end of the parsed range:
113-
return it;
114-
}
115-
116-
// Formats the success<non_void_type>
117-
template <typename OutputIt>
118-
typename std::enable_if_t<not std::is_void_v<T>, OutputIt> format_impl(
119-
OutputIt out, const outcome::success_type<T> &success) const {
120-
return fmt::format_to(out, "{}", success.value());
121-
}
122-
123-
// Formats the success<void>
124-
template <typename OutputIt>
125-
typename std::enable_if_t<std::is_void_v<T>, OutputIt> format_impl(
126-
OutputIt out, const outcome::success_type<void> &) const {
127-
static constexpr string_view message("<success>");
128-
return std::copy(std::begin(message), std::end(message), out);
129-
}
130-
131-
// Formats the success<T>
132-
template <typename FormatContext>
133-
auto format(const outcome::success_type<T> &success, FormatContext &ctx) const
134-
-> decltype(ctx.out()) {
135-
return format_impl(ctx.out(), success);
136-
}
137-
};
138-
139-
template <typename Result, typename Failure>
140-
struct fmt::formatter<outcome::result<Result, Failure>> {
141-
// Parses format specifications. Must be empty
142-
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) {
143-
// Parse the presentation format and store it in the formatter:
144-
auto it = ctx.begin(), end = ctx.end();
145-
146-
// Check if reached the end of the range:
147-
if (it != end && *it != '}') {
148-
throw format_error("invalid format");
149-
}
150-
151-
// Return an iterator past the end of the parsed range:
152-
return it;
153-
}
154-
155-
// Formats the outcome result
156-
template <typename FormatContext>
157-
auto format(const outcome::result<Result, Failure> &res,
158-
FormatContext &ctx) const -> decltype(ctx.out()) {
159-
// ctx.out() is an output iterator to write to.
160-
161-
if (res.has_value()) {
162-
if constexpr (not std::is_void_v<Result>) {
163-
return fmt::format_to(ctx.out(), "{}", res.value());
164-
} else {
165-
static constexpr string_view message("<success>");
166-
return std::copy(std::begin(message), std::end(message), ctx.out());
167-
}
168-
} else {
169-
return fmt::format_to(ctx.out(), "{}", res.error());
170-
}
171-
}
172-
};

include/libp2p/protocol/echo/client_echo_session.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#pragma once
88

9+
#include <optional>
910
#include <vector>
1011

1112
#include <libp2p/connection/stream.hpp>

src/multi/converters/converter_utils.cpp

+46-5
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,56 @@
2222
#include <libp2p/multi/multibase_codec/codecs/base58.hpp>
2323
#include <libp2p/multi/uvarint.hpp>
2424

25-
// TODO(turuslan): qtils
25+
// TODO(turuslan): qtils, https://github.com/qdrvm/kagome/issues/1813
2626
namespace qtils {
2727
inline std::string_view byte2str(const libp2p::BytesIn &s) {
2828
// NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
2929
return {reinterpret_cast<const char *>(s.data()), s.size()};
3030
}
3131
} // namespace qtils
3232

33+
// https://github.com/multiformats/rust-multiaddr/blob/3c7e813c3b1fdd4187a9ca9ff67e10af0e79231d/src/protocol.rs#L613-L622
34+
inline void percentEncode(std::string &out, std::string_view str) {
35+
constexpr uint32_t mask[4]{0xffffffff, 0xd000802d, 0x00000000, 0xa8000001};
36+
for (auto &c : str) {
37+
if ((mask[c / 32] & (1 << (c % 32))) != 0) {
38+
fmt::format_to(std::back_inserter(out), "%{:02X}", c);
39+
} else {
40+
out += c;
41+
}
42+
}
43+
}
44+
45+
// https://github.com/multiformats/rust-multiaddr/blob/3c7e813c3b1fdd4187a9ca9ff67e10af0e79231d/src/protocol.rs#L203-L212
46+
inline std::string percentDecode(std::string_view str) {
47+
auto f = [&](char c) -> std::optional<uint8_t> {
48+
if (c >= '0' && c <= '9') {
49+
return c - '0';
50+
}
51+
if (c >= 'A' && c <= 'F') {
52+
return c - 'A' + 10;
53+
}
54+
if (c >= 'a' && c <= 'f') {
55+
return c - 'a' + 10;
56+
}
57+
return std::nullopt;
58+
};
59+
std::string out;
60+
while (not str.empty()) {
61+
if (str[0] == '%' and str.size() >= 3) {
62+
auto x1 = f(str[1]), x2 = f(str[2]);
63+
if (x1 and x2) {
64+
out += (*x1 << 4) | *x2;
65+
str.remove_prefix(3);
66+
continue;
67+
}
68+
}
69+
out += str[0];
70+
str.remove_prefix(1);
71+
}
72+
return out;
73+
}
74+
3375
namespace libp2p::multi::converters {
3476

3577
outcome::result<Bytes> multiaddrToBytes(std::string_view str) {
@@ -115,9 +157,10 @@ namespace libp2p::multi::converters {
115157
case Protocol::Code::DNS6:
116158
case Protocol::Code::DNS_ADDR:
117159
case Protocol::Code::UNIX:
160+
return DnsConverter::addressToBytes(addr);
118161
case Protocol::Code::X_PARITY_WS:
119162
case Protocol::Code::X_PARITY_WSS:
120-
return DnsConverter::addressToBytes(addr);
163+
return DnsConverter::addressToBytes(percentDecode(addr));
121164

122165
case Protocol::Code::IP6_ZONE:
123166
case Protocol::Code::ONION3:
@@ -198,9 +241,7 @@ namespace libp2p::multi::converters {
198241
case Protocol::Code::X_PARITY_WSS: {
199242
OUTCOME_TRY(data, read_uvar());
200243
results += "/";
201-
// TODO(turuslan): percent encoding
202-
// https://github.com/multiformats/rust-multiaddr/blob/3c7e813c3b1fdd4187a9ca9ff67e10af0e79231d/src/protocol.rs#L613-L622
203-
results += qtils::byte2str(data);
244+
percentEncode(results, qtils::byte2str(data));
204245
break;
205246
}
206247

0 commit comments

Comments
 (0)